Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object Reference Error

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

    Object Reference Error

    I seem to be having a problem with this part of my code:

    s_end = ToTime(Time[0]) + 4100;
    if (s_end == ToTime(sessionEnd))
    {
    if (myOrder.OrderState == OrderState.Accepted)
    {
    CancelOrder(myOrder);
    myOrder = null;
    }
    }

    The problem I was trying to solve is when I start the strategy, the strategy will enter a limit order based on the closing of the previous bar, which happens to be the previous session. If I don't cancel that order, then the strategy will enter a limit order at the time I start the strategy, and if that is pre-market and the market is trading at or below this price, then I get an unintended fill. But if I use this code, then sometimes I will get the following error:

    Error on calling 'OnBarUpdate' method for strategy 'Pulse300LDev/bda624da93134bb8855e699a548e0674': Object reference not set to an instance of an object.

    I'm thinking this is happening when my strategy has determined that there shouldn't be any limit orders, but I'm not totally sure. Help?

    Rich
    tradethepulse.com

    #2
    Correct Rich, the error likely comes from not checking if the myOrder IOrder is null before attempting to CancelOrder() it -

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    65 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    149 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    99 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    286 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X