NT 8.0.8.0.
OnBarUpdate processes historical bars, but the "State" is already set to "State.Realtime" when they are processed.
Reproducing the bug
To reproduce the error please proceed as follows:
(1) Open a single chart and add a test indicator that prints the "State" for each loop of OnBarUpdate().
(2) Minimize the chart (upper right corner of the chart window).
(3) Connect to a datafeed.
(4) Wait. You will now see that for the indicator on the minimized chart "State. Configure", "State.DataLoaded" and "State.Historical" are being processed. Actually each of these states is being processed twice for no specific reason, but this does not do any harm.
(5) Now open the minimized chart.
When the minimized chart is displayed, OnBarUpdate will now process all historical bars on the chart but treat them as realtime ticks with the "State" shown as "State.Realtime". This is the bug and causes further havoc.
(6) Now refresh the chart via F5.
This time "State.Configure", "State.DataLoaded". and "State.Historical" will be called only once. OnBarUpdate will now process the same historical bars of the chart again and show them with "State.Historical".
Implications
When coding multi-timeframe indicators for NinjaTrader it is important to differentiate between historical bars and real-time bars, as they do not follow the same logic. For historical bars any event becomes final with the current bar, while for real-time bars it only becomes final with the first tick of the next bar (event driven logic).
When NinjaTrader confuses historical with real-time bars, this will cause many multi-timeframe indicators to crash. Therefore it is important that the state is correctly set when a minimized chart is opened.
Further problems
There are other problems that I have discovered with minimized charts, such as
-> BarsArray[0] not being populated when the minimized chart is opened.
-> PlotSeries holding no values when being accessed.
-> 'Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error = 'Object reference not set to an instance of an object.'
-> 'A direct X error has occurred while rendering the chart: HRESULT: [0x88990001], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_WRONG_STATE/WrongState]'
Those errors do often occur, when a minimized chart is reopened when connected to a data feed. But I cannot reproduce the behavior or attribute it to specific bugs. I will come back on these when there is further evidence.
However, the false realtime state is 100% reproducible and easy to test.
Comment