I keep running into an error of "Object reference not set to an instance of an object." when I set the entryOrder to Null after it has been cancelled.
Below is the block of code that I found in several of the example strategies.
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
AssignOrderToVariable(ref order);
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
Print(string.Format("40 | OOU | entryOrder CANCELED | Currenbar: {0} | {1}",
CurrentBar, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")));
entryOrder = null;
}
}
30 | LongEntry Triggered | BarNumberOfOrder: 335 | Position Quantity: 44 | LowOfLongEntryBar: 9060 | EntryPrice: 9061.75 | InitialStop: 9059.5 | 06/30/2020 09:46:36.847 PM 4/29/2020 7:22:17 PM Strategy 'T5/204825027': Entered internal SubmitOrderManaged() method at 4/29/2020 7:22:17 PM: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=44 LimitPrice=0 StopPrice=9061.75 SignalName='Long_Entry' FromEntrySignal='' 20 | CancelEntries | entryOrder.OrderState: Working | Currenbar: 339 | 06/30/2020 09:46:36.847 PM 4/29/2020 7:23:20 PM Strategy 'T5/204825027': Cancelled custom managed order: orderId='NT-00006-27266' account='Sim101' name='Long_Entry' orderState=Working instrument='MNQ 09-20' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=9061.75 quantity=44 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-04-29 19:22:17' gtd='2099-12-01' statementDate='2020-06-30' 40 | OOU | entryOrder CANCELLED | Currenbar: 339 | 06/30/2020 09:46:36.847 PM Strategy 'T5': Error on calling 'OnBarUpdate' method on bar 339: Object reference not set to an instance of an object.
- Is the order object automatically set to null internally by NT after the order is cancelled and therefore there is no need to set to null in OOU after cancelled?
- I am also setting entryOrder to null in OEU if the order is filled as well at the beginning of each day because I am trading intraday only and neither of those cause the error.
- Please let me know if you have any feedback to what would cause the error?
- NinjaTrader_ChelseaB posted an example strat named ProfitChaseStopTrailExitOrdersExample that used an empty order object named placeHolderOrder. Can you please explain why and what placeHolderOrder specifically does in that code?
Thanks

Comment