Is SAR crossover using Open price cheating?

Buy = Cross(Open,  SAR(acc,accm));
Sell = Cross(SAR(acc,accm), Open);
BuyPrice = SellPrice = Open;

Can someone please tell me if this code is forward looking ( ie not possible to trade)?

Yes, it is future leak. SAR uses High, Low, Close (also of current bar) for calculation. And as you know Open occurs before HLC of same bar.

See explanations here about what is future leak and what is not and how to apply bar delay.

So in your case you may do this for backtest (not a future leak)

SetTradeDelays(0, 0, 0, 0);

acc = 0.02;
accm = 0.2;

mysar = SAR(acc,accm);
prev_sar = Ref(mysar, -1);

Buy = Cross(Open, prev_sar);
Sell = Cross(prev_sar, Open);

BuyPrice = SellPrice = Open;

Or instead do this one (which is different than upper one but not being future leak too)

SetTradeDelays(1, 1, 1, 1);

acc = 0.02;
accm = 0.2;

mysar = SAR(acc,accm);

Buy = Cross(Close, mysar);
Sell = Cross(mysar, Close);

BuyPrice = SellPrice = Open;

etc.

6 Likes

Thank you. I was afraid of that.

Yeah, we've all been there. It's better to find out in code than "in trade"! :sunglasses:

3 Likes