Need a little help with a problem in TOS

Discussion in 'App Development' started by Hiperfly, Mar 25, 2014.

  1. Hiperfly

    Hiperfly

    Hello all,

    I am trying to backtest an strategy in TOS, with an exit based on the cross of the price with the Parabolic SAR. The problem is that the exit is made far below the SAR in long exits (see pic below) and far above SAR in short exits, which highly affects the PL reports.

    I would want this to be like a Trailing Stop, that's why in the code I stablished low (in this case, for longs; high for shorts) price as the order price.

    I don't know if I explained well myself. If you didn't understand please just ask and I will try.

    What am I missing? Should I use 'close' price instead of 'low'/'high' price?

    The image: The stop should be effective in the '+' draw, that the arrow aims. There is exactly when the price touches the SAR. Instead of this, the program activates this 'stop' right in the circle, far below the SAR.

    [​IMG]

    Other example (this is the exit of a short):

    [​IMG]

    And like this the 99% of the orders.

    Thank you very much
     
  2. Hiperfly

    Hiperfly

    Some more explained info about my issue:

    Let's call the candle that crosses the ParabolicSAR 0, and the next candle 1.

    The problem is that the Stop order should be executed by the program in the same momment that the candle 0 touches the SAR, but instead of that, the order is executed at the OPEN of candle 1.

    I would be really glad if someone could help me or at least tell me where else could I ask.

    Thank you very much.
     
  3. Hiperfly

    Hiperfly

    Sorry for replying again, I can't edit my previous message (wouldn't mind if an admin merge these two replies):

    I have been trying lots of things and I'm sure that the key is in the AddOrder function (last line in the code) in the ExitPrice variable. I have tried with
    but still doesn't work.

    Any ideas? Thanks again.
     
  4. Hiperfly

    Hiperfly

    Solved!

    If anyone was curious, the only thing I did was setting

    as the exitprice.

    Thanks everyone for the PMs.