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.
Other example (this is the exit of a short):
And like this the 99% of the orders.
Thank you very much
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.
def SARR = reference parabolicSAR(0.02, 0.2);
def price = close;
#plot SAR0 = SimpleMovingAvg(SARR,1);
plot SARR0 = SARR;
SARR0.SetPaintingStrategy(PaintingStrategy.POINTS);
SARR0.SetDefaultColor(GetColor(5));
def exit = if crosses(low,SARR,CrossingDirection.BELOW) then 1 else 0;
def exitPrice = low;
AddOrder(OrderType.SELL_TO_CLOSE, exit, exitPrice, tickColor = Color.WHITE, arrowColor = Color.WHITE);
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.
Other example (this is the exit of a short):
And like this the 99% of the orders.
Thank you very much