So, here is my code:
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time){ Logger("OnExecutionUpdate1:Execution of order: "+execution.Order.ToString()); Logger("OnExecutionUpdate2:"+execution.Order.FromEntrySignal.ToString()); }
Sometimes (I noticed this only with "name = 'Exit on session close'") I get the error "Object reference not set to an instance of an object".
In the NinjaScript Output:
ES 09-20 04.01.2020 0:59:00 OnExecutionUpdate1:Execution of order: orderId='NT-08694-3445' account='Backtest' name='Exit on session close' orderState=Filled instrument='ES 09-20' orderAction=BuyToCover orderType='Market' limitPrice=0 stopPrice=0 quantity=3 tif=Gtc oco='' filled=3 averageFillPrice=3214 onBehalfOf='' id=-1 time='2020-01-04 01:00:00' gtd='2099-12-01' statementDate='2020-06-12' Strategy 'strategy1v1/-1': Error on calling 'OnExecutionUpdate' method on bar 4080: Object reference not set to an instance of an object.
I assume that the error was caused by the line with "OnExecutionUpdate2:" .
I do the following:
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time){ Logger("OnExecutionUpdate1:Execution of order: "+execution.Order.ToString()); //Logger("OnExecutionUpdate2:"+execution.Order.FromEntrySignal.ToString()); }
The error does not appear.
When I uncomment, it appears again.
Questions:
Why?
What is the logical explanation?
Why I can use "execution.Order.ToString()" and can not use "execution.Order.FromEntrySignal.ToString()"?
More often it does not cause an error, but sometimes it causes - why?
Comment