The data inside the bar, including the Close[0], is all out-of-date by at least 1 tick. Because the open of the "next" bar has already occurred.
Imagine that there are three ticks and that minute bars are being created.
TickNumber, Time
1, 14:00:00
2, 14:00:59
3, 15:00:00
In this case, when the third tick arrives, NT calls OnBarUpdate() and inside it Close[0].Time is 14:00:59. This is an out-of-date datapoint. The most up-to-date datapoint, which is most definitely NOT in the future, is tick number 3. There is no "look-ahead bias" in using this value.
Orders placed in OnBarUpdate() are actually filled at the price of the open of the next bar and not at Close[0]. This is correct because it is the most up-to-date data point.
The most up-to-date price is available in OnBarUpdate() through:
Bars.GetOpen(CurrentBar+1)
A "Zero Slippage, No Delay" simulation can therefore be achieved by doing something like this. Pseudo code:
var samplePrice = Bars.GetOpen(CurrentBar+1); var position= GetPositionFromAlgorithm(samplePrice); if(position > 0) EnterLong(); if(position) < 0) EnterShort();
Now, there is an old thread which discusses this point:
The thread heats up and is never finished. Let's ignore the emotion in that thread and let's discuss this "Bars.GetOpen(CurrentBar+1)" thing.
I would like to know from NT staff/developers what will happen in the event that the strategy code uses Bars.GetOpen(CurrentBar+1) in live-trading.
Is it the same?
I.e. OnBarUpdate() is called when the tick which opens the "next" bar has arrived and Bars.GetOpen(CurrentBar+1) will give you that most up-to-date tick?
This is the tick which should be used to generate signals. Not Close[0]. Or am I missing something?
Comment