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."


    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

    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.

          good day together, i have now spent 2 days on this and other forums looking for a solution to my problem and hope to get an answer to my question here ;-) the following scenario in unmanaged mode: -----------------------------------------------------------------------------------------------------------------------------------
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          22 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          21 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X