2) The exception will only occur when there are two or more data streams used by the indicator, and only if an attempt is made to set the background color when BarsInProgress is greater than zero.
3) The same exact problem is also present in NT7 (of course, the code has to be different because of the differences between NT7 and NT8).
4) Here is the stack traceback for the exception:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
at NinjaTrader.NinjaScript.BrushSeries.Set(Int32 index, Brush value)
at NinjaTrader.NinjaScript.NinjaScriptBase.set_BackBr ush(Brush value)
at NinjaTrader.NinjaScript.Indicators.N1IndicatorBase .postUpdatePlots()
at NinjaTrader.NinjaScript.Indicators.N1IndicatorBase .OnBarUpdate()
5) Here's the slightly simplified code I use to set the background color:
public enum BackgroundColorScope { IndicatorPanel, AllOtherPanels, AllPanels } public enum BackgroundColorMode { DoNotColor, Static, Dynamic } protected virtual void setBackgroundBrush() { Brush brush; switch (backgroundColorMode) { default: case BackgroundColorMode.DoNotColor: return; case BackgroundColorMode.Static: brush = staticBackgroundBrush; break; case BackgroundColorMode.Dynamic: brush = computeBackgroundBrush(); break; } switch (backgroundColorScope) { case BackgroundColorScope.IndicatorPanel: BackBrush = brush; break; case BakgroundColorScope.AllOtherPanels: BackBrushAll = brush; BackBrush = staticBackgroundBrush; break; case BackgroundColorScope.AllPanels: BackBrush = brush; BackBrushAll = brush; break; } } protected override void OnBarUpdate() { ....... other code..... setBackgroundBrush(); ........other code...... }
Comment