Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Output window error

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

    Output window error

    I have just begun implementing IOrder functionality. Specifically, I added this code to my strategy:

    protected override void OnOrderUpdate(IOrder order)
    {
    if (entryOrder != null && entryOrder == order)
    {
    if (order.OrderState == OrderState.Cancelled)
    {
    entryOrder = null;
    }
    }
    }

    protected override void OnExecution(IExecution execution)
    {
    if (entryOrder != null && entryOrder == execution.Order)
    {
    entryOrder = null;
    }
    }

    The strategy continued to work on historical data exactly as before, but when running on sim101 the output window shows this:

    **NT** Error on calling 'OnBarUpdate' method for strategy 'RKSjugJuly4RealTime/c4b77d0574c74ea3825a9cfb5c08a744': Object reference not set to an instance of an object.

    I have a very strong hunch (based on live testing and where things go wrong) that the issue has something to do with this block:

    //End time exit, go flat, stop taking trades
    if((ToTime(Time[0])>=endTime)&& (ToTime(Time[0])<=endTime + 100))
    {
    //added line below to cancel any resting order to reverse which might execute after the position is exited
    CancelOrder(entryOrder);
    entryOrder = null;
    if(Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong();
    }
    else if(Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort();
    }
    }

    #2
    Hi coolmoss,

    This message happens when accessing an empty object, and right here is likely where it would happen:
    CancelOrder(entryOrder);

    It's good practice to make this non-null check whenever accessing:

    if (entryOrder != null)
    CancelOrder(entryOrder);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan,

      Your fast responses just make my life sooooo much easier. This small change seems to have totally fixed it!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      650 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      577 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X