"Error on calling 'OnBarUpdate' method on bar 796: You are accessing an index with a value that is invalid since it is out-of-range."
Bar 796 seems to be connected to the "Strenght" set by my application, which is 797, both in the "ChartReader" for use in the chart and in the strategy or the indicator "Tradesignal" as well, which both run "Swing" with exactly the same parameters. (I followed this lead, results are described later.)
I tried this solutions without success:
- MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
- Saving the whole Swing-Indicator as a new file (other indicator-name, all public variables renamed in the new Swing-indicator and all calling procedures)
- Setting all variables in this new Swing-indicator to "private", except "Strength" and, of course, the functions "SwingHighBar" and "SwingLowBar" - they are renamed but still public.
- In the functions "SwingLowBar" and "SwingHighBar"the following lines
throw new Exception(string.Format(NinjaTrader.Custom.Resourc e.SwingSwingLowBarInstanceGreaterEqual, GetType().Name, instance));
if (barsAgo < 0)
throw new Exception(string.Format(NinjaTrader.Custom.Resourc e.SwingSwingLowBarBarsAgoGreaterEqual, GetType().Name, barsAgo));
if (barsAgo >= Count)
throw new Exception(string.Format(NinjaTrader.Custom.Resourc e.SwingSwingLowBarBarsAgoOutOfRange, GetType().Name, (Count - 1), barsAgo));
return -1;
if (barsAgo < 0)
return -1;
if (barsAgo >= Count)
return -1;
None of this changed neither the correct behaviour of the "Swing"-indicator in the Chart nor the error-message, when called through a strategy or another indicator like "Tradesignal".
This changes had effects:
- Adding in the functions "SwingLowBar" and "SwingHighBar" these lines in the beginning:
return -1;
- Adding this in the beginning of OnBarUpdate()
if (CurrentBar < 796)
return;
I understand that the Swing indicator is not supposed to be used for generating trading-signals, but I do need its output in a lookback-procedure that is far enough from "Bar 0", so the results seem to be useful - if it works.
By the way: The functions "SwingLowBar" and "SwingHighBar" do always return "-1" when called by "Tradsignal" or a strategy (through "Chartreader" which is used in their procedures), but a correct bar-number when called from "Chartreader" directely (always with same parameters, checked by prints in the output-window done by "Chartreader" itself).
But this may another outcome of he same problem.
Does anyone know the source of that behaviour of "Swing" and a possible solution?
Thanks for reading this!
Comment