My strategy has received the following error:
-------------------------
2021-04-21 04:01:12:554|3|4|Indicator 'SMA': Error on calling 'OnBarUpdate' method on bar 258: 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.
2021-04-21 04:01:12:565|3|4|Strategy 'Nasdaq_2': Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.
2021-04-21 04:01:12:566|1|4|Disabling NinjaScript strategy 'Nasdaq_2/195500170'
--------------------------
It seems that the error occurs within the code of the SMA indicator. After the error, NinjaTrader disables the strategy.
The problem is that this error in the indicator is not transmitted to the strategy (for example as an Exception), and since the strategy has the RealtimeErrorHandling parameter set to RealtimeErrorHandling.IgnoreAllErrors, the disabling of the strategy by NinjaTrader supposes the cancellation of live orders, but does not close the open position because my custom code to close the open position in case of error (rejected, overfill, exception, ...) is not called.
The strategy has been running for months in production with a real account. It works to the tick, and that call to the SMA is made with each tick, and it is the first time this error occurs.
The MaximumBarsLookBack parameter is set to MaximumBarsLookBack.Infinite.
One way to avoid this issue would be to receive an exception from the SMA indicator, in order for the strategy to close the open position.
Thanks
Comment