Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnOrderUpdate questions

Collapse
X
 
  • 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:

    (NinjaTrader.NinjaScript.StrategyBase...)
    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 ?

    hyperscalper



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

    #2
    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."
    https://ninjatrader.com/support/help...rderupdate.htm

    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.
    https://ninjatrader.com/support/help.../nt8/order.htm

    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

    Comment


      #3
      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...
      hyperscalper
      Last edited by Hyper; 09-15-2020, 08:56 AM.

      Comment


        #4
        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

        Comment


          #5
          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.
          https://ninjatrader.com/support/foru...269#post802269
          https://ninjatrader.com/support/foru...78#post1087278
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Unsuitable, Today, 07:26 PM
          0 responses
          1 view
          0 likes
          Last Post Unsuitable  
          Started by jvanelli, Today, 06:36 PM
          1 response
          7 views
          0 likes
          Last Post jeronymite  
          Started by twitch251, Today, 05:14 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by robforee2, Today, 05:07 PM
          0 responses
          4 views
          0 likes
          Last Post robforee2  
          Started by blar58, Today, 03:16 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Melissa  
          Working...
          X