NinjaTrader Multi-Timeframe glitch in RealTime vs Historical

I wanted to mention two words about Multi-Timeframe dataseries in NinjaScripts. I.E. if you have your primary chart set to i.e. 1 hour and in your script you also have granular data, like

else if (State == State.Configure)
{
     AddDataSeries(Instrument.FullName, BarsPeriodType.Minute, 1, MarketDataType.Last);
}

If in OnBarUpdate you will insert:

Print(BarsInProgress + " | " + Time[0] + " | BN:" + CurrentBars[0] + " | " + " | Close:"+ Close[0]);

you will get something like this on Each Bar (for example, at bar #67):


1 | 13:58:00   |BN: 66  | Close:  157.06
1 | 13:59:00   |BN: 66  | Close:  156.75
0 | 14:00:00   |BN: 67  | Close:  157.10     <—– See this
1 | 14:00:00   |BN: 67  | Close:  157.10     <—– See this
1 | 14:00:01   |BN: 67  | Close:  157.32    <—— NewBar starts here
1 | 14:00:02   |BN: 67  | Close:  157.19
…etc… 

So, you might think that everything is ok, but NOT. The problem here is that, on charts , bar timestamp means the END-TIME of the bar.  So, actually, 14:00:00 bar you are watching on chart,  that bar reflects the data which has been forming during 13:00:00-14:00:00 (thus, expressed with 14:00:00)
So, on that 1-hour BAR, if you have smaller timeframe bars data printed, note that the 1-hour BAR  on 14:00:00 shows the data of previous hour, and the 1-minute data of BAR on 14:00:00 will show the 13:59:00-14:00:00 data (On realtime, that is a bit different, will add two words about that later.   So, remember that). So, NewBar variable for 2nd-timeframe data, should start not on the red highlighted line in above example, but on the next 2nd-timeframe bar (marked with orange color).

I highly recommend to read NinjaTrader Docs page about Multi-Timeframe series.

 

Example of accumulation in MTF

 ( For sequence of BIP execution, you can see this interesting  example1 and example2 )

Leave a Reply

Your email address will not be published. Required fields are marked *