So from within my strategy I check for CurrentBars[x] for all my series and return before a safe distance.
I also added the following to my strategy:
if (CurrentBar < BarsRequiredToTrade { return; };
Nevertheless I kept getting range exceptions and eventually made a copy of your EMA which I called EMA2 and added some debugging statements to it. This allows me to print more detailed debug information if there was an exception being thrown in onBarUpdate():
Time Category Message 1/8/2021 12:30:09 PM NinjaScript
"12/28/2020 6:02:00 PM: EMA2 during OnBarUpdate(): 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.Series`1.get_Item(Int32 barsAgo) at NinjaTrader.NinjaScript.Indicators.EMA2.OnBarUpdat e() in c:\Users\michael\Documents\NinjaTrader 8\bin\Custom\Indicators\EMA2.cs:line 80
Bars period parsed during error: 2
CurrentBar]: 5336
Value[0] = 3808.17520499579
Value[1] = 3808.22526356601
What's really strange here is that this exception is being thrown intermittently several minutes or so after starting it. Look at the date of the exception - it's the very first bar on my chart. So it should have thrown this exception right on launch and not at some unspecified time later.
Also see that it's happily printing Value[0] and Value[1] which I capture beforehand. So basically I have no idea WHY this is happening as it should not. The timing of the exception being thrown is wrong plus it clearly has enough bars.
Heck I even added this to the beginning of my EMA2's onBarUpdate() method:
if (CurrentBar < BarsRequiredToPlot { return; };
And it's still throwing that error intermittently. Something's very screwy here and I've burned half my week on this already. Your help would be appreciated.
Thanks,
Michael
Comment