Conditions necessary for triggering the exception
(1) All indicators are programmatically set to "IsSuspendedWhileInactive = true."
(2) All indicators load a secondary bar series of minute or tick data via AddDataSeries() in State.Configure.
(3) All indicators have a custom OnRender() method.
Reproducing the problem
The easiest way to reproduce the problem is
-> first to disconnect from the data feed
-> then open a chart with a complex multi-timeframe indicator for which "IsSuspendedWhileInactive" is programmatically set to "true".
-> then duplicate the chart 4 times by right clicking the tab in the lower left corner of the chart
-> then change the instruments in the 4 duplicated tabs
-> then reconnect to the data feed
When reconnecting to the data feed one of the 5 charts is active, while the other 4 charts are inactive. For the active chart the plot works as expected. However, when I toggle to one of the inactive charts, I am getting the error message.
"Error on calling 'OnRender' method on bar 324961: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."
The bar count 324961 refers to the bar count of the secondary bar series. The secondary bar series is nowhere called in the custom OnRender() method. After massive problems I have even replaced "BarsArray[0]" with "ChartBars" in all the custom OnRender() methods of my indicators.
Interpreting the findings
It seems that in the case of an inactive chart - which has not yet been active after connecting to a data feed - a false bar count is passed to OnRender(), which in turn tries to access a chart bar with an index that does not exist. The error message above was created on a 15-min chart (about 4382 bars) with a secondary bar series of 50-tick bars (324961 bars) added.
I have also inserted a Print instruction in the beginning of the OnRender() method for BarsArray[0].Count, which showed a false barcount for the primary bars. This points to a problem of OnRender() running before OnBarUpdate() was completed.
Workaround
The only workaround here is to set all multi-timeframe indicators to
IsSuspendedWhileInactive = false;
With the workaround available fixing this problem becomes less urgent. However, it should be noted that the current solution for "IsSuspendedWhileInactive" is incompatible with multi-timeframe indicators.
Comment