Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

entryOrder = null; ERROR

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    entryOrder = null; ERROR

    Hello,

    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.
    Code:
            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;
                }
    }
    Below is the error:
    Code:
    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.
    Questions:
    1. 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?
    2. 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.
    3. Please let me know if you have any feedback to what would cause the error?
    4. 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
    Last edited by Epistemophilic; 06-30-2020, 10:11 PM.

    #2
    Hello Epistemophilic,

    The error 'Object reference not set to an instance of an object' means that you are using a variable with no object assigned to it (a null value).

    An object reference is a variable. 'Not set to an instance of an object' means nothing was assigned to that variable.

    You will need to check for null before using any variable that be null.

    Below is a link to the help guide on checking for null references.


    You will need to identify the variable causing the error. Use prints above each line to identify which variable is null.

    Below is a link to a forum post that demonstrates using prints to understand behavior.


    No, order objects are not set to null by NinjaTrader as these will continue to hold the order information for later use.

    The placeHolderOrder is used because you must assign order objects from OnOrderUpdate and not when calling the entry method.
    https://ninjatrader.com/support/help...rderupdate.htm
    Last edited by NinjaTrader_ChelseaB; 01-09-2022, 04:50 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X