Look-Ahead Bias Question

I have this simple program and I am trying to get my head around "look-ahead" bias.

The program generates a Buy signal given the rules below, so I have figured out that when the Buy signal is generated, the system buys at the next Open - So, as I understand it, there is no look-ahead bias here.

Where I am confused is at the Sell signal. Here, since TradeDelays( 0, 0, 0, 0 ) is set, the sell signal ( Cross( MA( Close, 20 ), Close ) ) uses the "Close", which in a real-live trading system would not be known. So, does this Sell signal cause "look-ahead" bias?

Thanks for any insights into this question...

SetTradeDelays( 0, 0, 0, 0 );

BuySignal =  
			Cross( Close, MA( Close, 20, 2 ) )
			AND Close - Ref( Close, -Lag ) > 0;

Buy = Ref( BuySignal, -1 ); 
BuyPrice = Open * 1.0000; 
 
Sell =  
         Cross( MA( Close, 20 ), Close  );

No, it is not look ahead bias since it is same price as signal occurs -> Close of bar.
But it is just unrealistic/unlikely that you would get trade entry/exit at close of bar in realtime.

A future leak would be this example:

SetTradeDelays( 0, 0, 0, 0 );

//Buy = ....

SellPrice = Open;
Sell = Cross( MA( Close, 20 ), Close );
2 Likes

Thanks for your insights - I am struggling with this - but does the SellPrice have to Open?, i.e.,

SellPrice = Open;

or can it be

SellPrice = Close;

Is using SellPrice = Close look-ahead bias in this example?

Please re-read my post. It is not look ahead bias since it is at same time (-> at bar close). Events at same time are not future leak. But it's just unrealistic in real-time. So a more realistic approach for backtesting is using next bar's prices as trade price.

2 Likes