I have the following problem, I am programming a strategy that uses 2 series one of 2 minutes and another of 2 seconds ( the secondary one ).
Executing the strategy on the day (always happens to me) 09/11/2020.
It gives me the following error in the bar 681 (the anteultimate one that brings the Strategy Analyzer) CurrentBars[1] == -1 ALWAYS in all the bars since it begins the strategy, that I know it because at the beginning of the OnBarUpdate() I ask: if (CurrentBars[1] == -1) return, there it doesn't fail but it doesn't execute anything of the code that follows it.
Also it gives me an error in OnOrderUpdate in that same line.
I generate prints in the following way in OnOrderUpdate:
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { string nameMethod = "OnOrderUpdate"; if (CurrentBars[0] == 681) myPrint(string.Format("{0,-40} - 0.000 - Primary BarNbr = {1,7} - Secondary BarNbr = {2,7} - starting process", nameMethod, this.CurrentBars[0], this.CurrentBars[1])); if (CurrentBars[0] == 681) myPrint(string.Format("{0,-40} - 0.010 - order received = {1}", nameMethod, order)); ... at the end if ((CurrentBars[0] == 681)) { myPrint(string.Format("{0,-40} - 8.000 - post allTrades.OnOrderUpdate(true, ...) - Primary BarNbr = {2,7} - Secondary BarNbr = {3,7}", nameMethod, order, CurrentBars[0], CurrentBars[1] )); myPrint(string.Format("{0,-40} - 8.100 - order = {1} ", nameMethod, order, CurrentBars[0], CurrentBars[1] )); return; } if (sParms.levelToDebug.IndexOf(nameMethod) != -1) { myPrint(string.Format("{0,-40} - 9.000 - order orderstate is valid = [{1}]", nameMethod, order, CurrentBars[0] )); } } return // OnOrderUpdate
OnOrderUpdate - 0.010 - order received = orderId='NT-00008-358' account='Backtest' name='CTT_2' orderState=Cancelled instrument='MES 12-20' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=3668.75 quantity=1 tif=Gtc oco='CTT_2-OCO-' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-09 11:00:00' gtd='2099-12-01' statementDate='2021-01-15'
OnOrderUpdate - 1.000 - myTime = 18:58
OnOrderUpdate - 8.000 - post allTrades.OnOrderUpdate(true, ...) - Primary BarNbr = 681 - Secondary BarNbr = -1
OnOrderUpdate - 8.100 - order = orderId='NT-00008-358' account='Backtest' name='CTT_2' orderState=Cancelled instrument='MES 12-20' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=3668.75 quantity=1 tif=Gtc oco='CTT_2-OCO-' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-09 11:00:00' gtd='2099-12-01' statementDate='2021-01-15'
OnOrderUpdate - 8.000 - post allTrades.OnOrderUpdate(true, ...) - Primary BarNbr = 681 - Secondary BarNbr = -1
OnOrderUpdate - 8.100 - order = orderId='NT-00007-358' account='Backtest' name='CTT_2' orderState=Cancelled instrument='MES 12-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2814.5 quantity=1 tif=Gtc oco='CTT_2-OCO-' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-11-09 11:00:00' gtd='2099-12-01' statementDate='2021-01-15'
Strategy 'CTT/-1': Error on calling 'OnOrderUpdate' method on bar 681: Object reference not set to an instance of an object.
ATTENTION:
With Market Replay I don't have any error.
Apparently it happens in an Exit on session close, but I am not sure because it is in the anteultimate bar that the analyzer delivers ...
Translated with www.DeepL.com/Translator (free version)
Comment