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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    573 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    575 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X