Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Advanced Order Handling BarsInProgress > 0

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

    Advanced Order Handling BarsInProgress > 0

    I am testing out the advanced order functionality that is similar to what is listed in the help facility for the OnOrderUpdate method as well as the related reference example Josh posted:

    Code:
    private IOrder entryOrder = null;
    
    protected override void OnBarUpdate() 
    { 
        if (entryOrder == null && Close[0] > Open[0]) 
            [COLOR="Blue"][B]entryOrder = EnterLong(); [/B][/COLOR]
    }
    
    protected override void OnOrderUpdate(IOrder order) 
    { 
        if (entryOrder != null && entryOrder.Token == order.Token) 
        { 
            Print(order.ToString()); 
            if (order.OrderState == OrderState.Filled) 
                entryOrder = null; 
         } 
    }
    except that I am looking to place orders in BarsInProgressIndex = 1 vs 0 by replacing the entry logic with:

    Code:
        if (BarsInProgress == 1)
        {
           if (entryOrder == null && Close[0] > Open[0]) 
              entryOrder = EnterLong(1, true, myOrderQty, Close[0], "myEntry");
         }
    Are there any special considerations to handle BarsInProgress = 1 orders when using the OnOrderUpdate method? I have been getting "Object reference not set to an instance of an object" run-tim errors when I attempt to do this.

    Thanks,

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    #2
    No there are no special considerations.

    The code you pasted above should not produce an object reference error and it should be fine.

    I suspect the error is coming from elsewhere. What I suggest to confirm that the above code is not producing this error is to comment out all other user code in the strategy and just let it run so that it places the one order as per your code. Assuming this works, you can then start uncommenting out other code to see where the object reference error is.

    All this error means is that you are acessing a variable that holds an object but an object is not assigned to this variable.
    RayNinjaTrader Customer Service

    Comment


      #3
      Multiple Order Objects in OnOrderUpdate

      Thanks Ray, good to know this will work without modification and in fact, your recommended debugging technique is exactly what I used to get to this point of inquiry. I am actually testing two entry orders . . . entryLongOrder and entryShortOrder.

      Code:
      protected override void OnOrderUpdate(IOrder order) 
      { 
          if (entryLongOrder != null && entryLongOrder.Token == order.Token) 
          { 
              if (order.OrderState == OrderState.Filled) 
                  entryLongOrder = null; 
           } 
          if (entryShortOrder != null && entryShortOrder.Token == order.Token) 
          { 
              if (order.OrderState == OrderState.Filled) 
                  entryShortOrder = null; 
           } 
      }
      As you can see, in the OnOrderEvent logic I am testing both for != null and == to the order.Token. It would appear that when the OnOrderEvent triggers for one entry order object the and the other entry order object has not yet been assigned to its variable so I get the error message I described. Is there a best practice for handling multiple entryorders in this method to avoid this error? Thanks.

      Whitmark
      whitmark
      NinjaTrader Ecosystem Vendor - Whitmark Development

      Comment


        #4
        Not sure I follow.

        I the OnOrderUpdate() code you pasted could not produce an object reference error since you are checkking for null references before accessing properties on the object.
        RayNinjaTrader Customer Service

        Comment


          #5
          I started over with a simplified example and found that I could manage two separate orders and place the trades on the secondary series, no problem. Thanks for developing this functionality in the latest release.

          Whitmark
          whitmark
          NinjaTrader Ecosystem Vendor - Whitmark Development

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          639 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 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
          572 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X