Announcement

Collapse
No announcement yet.

Problems with strategies

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with strategies

    I've run into a few issues with strategies.

    They run differently in back testing than in realtime. It appears in back testing that the strategy gets called at the end of each bar while in realtime it get's called more often. Backtesting and realtime need to act the same.

    If I place a stop order to enter into a trade, I also want to enter a stoploss after the orignal order hits. If I get called on everytick, I can monitor the price action and decide that the stop took and place a protective stop. In backtesting mode, I cannot because I am being called at the end of the bar.

    I have'nt found a way to tell what price a market order when in for (So I can set a protective stop).

    I have noticed that upon loading a strategy to a chart, all the back bars react properly when orders are issued using market orders and then testing with strategy.isLong() for example. But moving forward, it no longer detects issued orders (strategy.isLong()). Again, realtime and backtesting needs to be the same.

    If anyone has ideas around these problems please reply

    Thanks

  • #2
    back-testing vs. RT...

    I have a bunch of experience with both.

    There are some minor tricks to accomplishing what you want. Like code structure....

    You should probably go to my fileshare group (Matheny Enterprises) and download the chat session (the only one there) that discusses Strategy functions and uses. Also, in my fileshare section is a "guide to building Strategy code". Both of these would be a big help to you.

    Here are some simple answers to your questions..

    Using Strategy.MARKET, the esignal system assumes you enter on the OPEN of the next bar (or open(1). So, when you enter a LONG trade using this option, you can record the open price of the next bar as your entry price..

    Strategy.doLong("Long Entry", Strategy.MARKET, Stragegy.THISBAR, Strategy.DEFAULT);
    nEntryPrice = open(1);

    This will then allow you to place your stop orders based on the entry price.

    Now, if you are using a LIMIT or STOP order to place your entry trades, then you have to pass it a price value. So, if you know the price value you are entering at, then you should be able to place stop loss orders also.

    I like to check (within my code) to see if the order could be executed at the proper price. This way I know when/where the market entered the order and can place additional orders as necessary.

    Another way to do this is to check Strategy.isLong() and Strategy.isShort(). When these become true, you are in a trade and thus can place your stop loss and profit target levels.

    If you need more help, please let me know.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      sorry...

      Developing RT code is much different. You have to work out the logic issues for you code to operate properly. There are a few tricks to this as well.

      1. Use Time-Stamps for certain actions. Record the time of the bar that an action took place, then you can prevent a similar action from acting on the same bar..

      nEntryTime = 0;


      // Allow a test for new entry signals
      if ( (time to buy) && (nEntryTime != getValue("rawtime",0)) ){
      // Record the bar time for our entry
      nEntryTime = getValue("rawtime",0);
      GO Long!

      }

      if ( (time to sell) && (nEntryTime != getValue("rawtime",0)) ){
      // Record the bar time for our entry
      nEntryTime = getValue("rawtime",0);
      GO Short!

      }

      Using this type of time stamping will prevent your system from "flipping" back and forth on the same bar.

      There are many others, but this is one of the most important processes in developing RT code.

      Brad
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Thanks for the replies.

        The problem that I am having is not with the realtime (I have plenty of control over that), but with the backtesting. Because backtesting works different, I can't really backtest any strategies with any validity because it doesn't work like the realtime. For example, I may want to issue an order in the middle of a bar (which works fine with something like dynaorder) but when back testing, because the strategy only gets called at the end of the bar, I am unable to issue orders during the bar as I can with the real time.

        Comment


        • #5
          Possible Resolution

          In situations like this, the only thing you can do is ESTIMATE the entry price.

          For example, if your system entered on a 5 minute bar with a high of 950.00 and a low of 947.00, then we might estimate the entry with the following code...

          Depending on your entry strategy (lets say a price breakout) would be easy. You would be entering on the BREACH PRICE +/- a VALUE

          Lets say your entry is based on multiple technical indicator conditions (Like Stos, RSI and other).

          I would suggest determining the range of these indicators and calculating the percentage ABOVE or BELOW the LIMIT you set for your entry condition. Then averaging the PERCENTAGE values, then subtracting that percentage value from the price range (950-947 = 3. 3*xx% = n. n+947 = your estimated entry price).

          You can use any other method you like, but I have tried this in the past (and always assumed at least a .25 pt slippage in and out of the trade). It seems to work OK.

          Of course, there is nothing like matching up the price in RT, but that is not possible. So, we have to work around such things.

          If I can be of any further help, let me know.

          Brad
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment

          Working...
          X