I'm new to the NinjaTrader community and could use some assistance. I'm working on building an automated strategy with the strategy builder, but having some challenges. After building it in the strategy builder, enabling it, it seems to work just fine without errors. However, when I move to the strategy analyzer and try to either backtest and/or optimize I receive two OnBarUpdate Errors and it disables the analysis.
Error 1: Indicator ":Error on calling 'OnBarUpdate' method on bar ): Object reference not set to an instance of an object
Error 2: Strategy Error on call'OnBarUpdate' method on bar 2544: You are accessing an index with a value that is invalid since it is out-of-range.
That said, I have attempted to edit the script multiple ways to eliminate the error.
The original script from the builder: ( I received the above errors)
if (BarsInProgress ! = 0)
return;
if (CurrentBars[0] < 1)
return;
Variation of the script 1: ( I received the above-forementioned errors)
if (CurrentBar < 1)
return;
if (Close[0] > Close[1])
The script as it stands now: ( I received the above-forementioned errors)
if (Close[0] > Close[Math.Min(CurrentBar, 1)])
Here's where I thought it got interesting, but still receiving an error; I added a line to test the range if you will, and the error code changed to state that the OnBarUpdate method on bar 10856.
if (CurrentBar < 1)
return;
if (CurrentBars [0] < 10000)
return;
if (Close[0] > Close[1])
To continue with that logic, I changed the value from incrementally from 10,000 working my way up to 50,000. At 50,000 the strategy error disappeared and I was left with just the indicator error.
My question is this, is there a way I can get around these errors so that I can properly run the analyzer? I've attached a printed copy of my current script. Any help is much appreciated. Thank you
Comment