No announcement yet.

Partner 728x90


OnOrderUpdate questions

  • Filter
  • Time
  • Show
Clear All
new posts

    OnOrderUpdate questions

    Unmanaged strategy.
    I am aware that the Order object has the "instantaneous" status; and that OnOrderUpdate
    callbacks may "lag" behind the "real" status. But just some questions you could help me with:

    public void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
    int quantity, int filled, double averageFillPrice,
    Cbi.OrderState newOrderState, DateTime time, Cbi.ErrorCode error, string comment);

    ODDLY, I want to represent Buy or so-called "Long" quantities as negative numbers;
    and Sell or "Short" fill quantities as positive numbers (maybe opposite of most people).
    I'll know whether a given Order is intended for a Long or Short position, so I can
    assign my own minus or plus sign to the Order Fill Quantity.

    #1 is the "quantity" argument the Total Order quantity as originally submitted and requested?

    #2 is the "filled" argument the cumulative fill, with behavior as follows:

    So, if the order quantity is 3, and 3 separate executions (each 1 contract) occurred,
    then I could expect 3 callbacks: quantity=3,filled=1; quantity=3,filled=2; quantity=3, filled=3
    on the last of which I'd probably get OrderState.Filled ? This is in the case of a normal execution,
    and not some error condition scenario.

    I AM KEEPING IN MIND that the Order object's states may "race ahead" of those OnOrderUpdate
    callbacks in time.

    OR SHOULD I SIMPLY HANDLE OnExecutionUpdate, and not bother with OnOrderUpdate ?


    Last edited by Hyper; 09-14-2020, 08:43 PM. Reason: Another question OnExecutionUpdate

    Hello hyperscalper,

    From the help guide:
    "OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated."

    This means the Order object from OnOrderUpdate will be the updated Order object, not the Order object returned by an order method.

    Yes, Order.Quantity will be the quantity the order is submitted with.

    Yes, Order.Filled is the amount filled for the order so far.

    Yes, the order state of an order will be OrderState.PartFilled until the order is fully filled and then the state becomes OrderState.Filled.

    If you are assigning orders to variables, this must be done from OnOrderUpdate().

    If you are not assigning orders to variables, the logic can be entirely in OnExecutionUpdate().
    Chelsea B.NinjaTrader Customer Service


      Thank you; that helps me a lot! So, yes I am assigning Order references to variables. And I do want
      to be able to use an orderA.Equals(orderB) to identify. So I guess you are saying that I could do that
      only with the Order reference from OnOrderUpdate, but that the execution.Order field could not be
      used for that purpose... lots to think about. [edit] So I guess I need to consider a unique Tag field,
      like Name or comment, which would appear in any proper clone of Order as an identification method?...
      And NOT use object references or hashcodes for identification...
      Last edited by Hyper; 09-15-2020, 08:56 AM.


        So, I won't dumbly attempt to do any Order object references; just using the Name field with some
        notion of a unique Order ID concept is how to deal with individual Order's... That's guaranteed
        to be stable from first assignment through the Order's lifetime. Sounds good to me !!
        Thanks so much for pointing that out; it saves me a lot of trial and error (mostly error)
        time ! hyperscalper


          Hello Hyper,

          Yes, this is the recommended approach that has an example in the OnOrderUpdate documentation.

          Also, below I am providing a link to a few examples.

          Chelsea B.NinjaTrader Customer Service


          Latest Posts


          Topics Statistics Last Post
          Started by JTizz, Today, 03:32 PM
          1 response
          Last Post NinjaTrader_ChrisL  
          Started by ebaydan777, Today, 02:41 PM
          1 response
          Last Post NinjaTrader_ChrisL  
          Started by aligator, Today, 02:28 PM
          1 response
          Last Post NinjaTrader_ChristopherJ  
          Started by daniel_weber8, Today, 01:21 PM
          1 response
          Last Post NinjaTrader_ChristopherS  
          Started by jungsoohuh, Today, 12:07 PM
          1 response
          Last Post NinjaTrader_PaulH