Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Order Quantity on partial fill

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

    Order Quantity on partial fill

    Suppose I use the unmanaged approach to submit an order for say 5 futures contracts. When the order is accepted, I will get onOrderUpdate with that order for 5 contracts. Now suppose that this is a limit order and I get only a partial fill - say only 2 contracts get filled so 3 remain.

    Questions:
    In onOrderUpdate() i get the order passed in. Is order.Quantity always going to be 5 or will it now be == 3, ie the 3 remaining contrcats?

    What about OnExecutionUpdate? There i get passed an Execution object and I get the order from execution.Order. Does that order now have Quantity=5 or Quantity=3 (the 3 remaining).

    And if Quantity keeps going down, does that mean when the order is fully filled that Quantity will be 0 and filled will be 5?

    Please explain. Thanks.

    EDIT: My basic question is this: Suppose I have an original (unmanaged) Order for 5 contracts, and I also have a stop loss order to sell those 5 contracts if the market goes against me. Now suppose that in OnExecutionUpdate() I get notified that I have a partial fill for 2 contract out of the 5, so I want to change my stoploss order from the original 5 contracts down to the remaining 3 contracts. How do I specify the correct quantity in ChangeOrder(stopLossOrder)?
    Last edited by westofpluto; 09-28-2020, 12:19 PM.

    #2
    Hello westofpluto,

    Thanks for your post.

    Order.Quantity reflects the entire quantity of the order. Order.Filled reflects how many contacts of that order have filled.

    Execution.Order represents the order that is being executed.

    SampleOnOrderUpdate demonstrates how OnOrderUpdate and OnExecutionUpdate may be used to submit target/stop and this strategy also works well to handle partial fills.

    An unmanaged version of this strategy is attached.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    To further observe these values, you can use Print()'s to see their output in the NinjaScript Output window.

    Note: This approach depends on Order/Execution events to follow: 1. OrderUpdate 2. ExecutionUpdate. When using Interactive Brokers or Rithmic based connections, the Order/Execution event ordering will be different and this sort of approach would not be reliable. We would suggest using OnOrderUpdate alone for those connection types.

    We look forward to assisting.
    Attached Files
    Last edited by NinjaTrader_Jim; 09-28-2020, 12:28 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      This helps but it doesn't really answer the question. Let me be very specific:

      What does execution.Order.Quantity represent for a partial fill? Is it the full quantity of the original order? (In my example, if the original order is 5 contracts then this is 5)? Or is this execution.Order.Quantity only the 2 contracts that have filled in a partial fill? Please answer directly rather than giving me code samples. Is this documented anywhere? Thanks.

      Comment


        #4
        What does execution.Order.Quantity represent for a partial fill? Is it the full quantity of the original order?
        Yes. Order.Quantity reflects the entire quantity of the order. If you have an order of 100 that gets a partial fill, Order.Quantity still shows the 100 when that order is executing.

        OnOrderUpdate and Order object can be referenced for what the properties mean. These documentation links are included in the SampleOnOrderUpdate link above. I have included them below for your convenience.





        Testing prints in a working example like that given in post #2 can help to observe what you can expect these values to be.
        JimNinjaTrader Customer Service

        Comment


          #5
          The tricky part is this: execution.Order.Quantity is always the size of the original order, but (confusingly enough) execution.Quantity is the number of contracts that get filled in a partial fill (ie execution.Quantity is == execution.Order.filled)

          Comment


            #6
            Hello elliot5,

            There is further explanation at the bottom of the Multi Threading Help Guide page that explains the same case for OrderUpdates.

            https://ninjatrader.com/support/help...-threading.htm

            The Order and Execution objects of OnOrderUpdate and OnExecutionUpdate will always represent the most recent Order or Execution object. The other arguments that contain the passed by value data will not reflect the most recent Order/Execution object, but the values in the sequence in which they arrive.

            If you follow the traditional SampleOnOrderUpdate approach, where execution.Order.Filled is used to get the quantity for the target/stop, you may be left with a partially unprotected position if you receive a partial fill, and it would depend on the ordering of Order and Execution events seen from Interactive Brokers and Rithmic.

            If you want to take a similar SampleOnOrderUpdate style approach in your strategy, as I do in my example, you could consider using OnOrderUpdate only, but we would have to keep some things in mind.
            • The Strategy Position object is based on Execution events. Since the strategy Position object is used with Exit methods to ensure you cannot more of a position that NinjaTrader sees as the strategy position, you would then have to use the Unmanaged Approach as we are no longer relying on Executions for the submission of our stop and target orders.
            • Additionally, if you want to use a Position object in your strategy, you would need to calculate it on your own from Filled and Part Filled OrderUpdates.
            Let me know if you have any other questions.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by maybeimnotrader, Yesterday, 05:46 PM
            5 responses
            24 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by NRITV, Today, 01:15 PM
            0 responses
            2 views
            0 likes
            Last Post NRITV
            by NRITV
             
            Started by quantismo, Yesterday, 05:13 PM
            2 responses
            16 views
            0 likes
            Last Post quantismo  
            Started by frankthearm, Today, 09:08 AM
            6 responses
            27 views
            0 likes
            Last Post frankthearm  
            Started by adeelshahzad, Today, 03:54 AM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X