Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partial fill on exit

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

    Partial fill on exit

    I have been trawling the forum for hours trying to understand how to deal with partial fills. There seems to be a gap in the documentation regarding this problem, as so many people are confused.

    If I get a partial fill on a exit order, I see in the sample code that the standard behavior is to set: stopOrder = null; targetOrder = null; from within OnExecution.

    1) But what check should be done to pick up any open positions and deal with them?
    2)Do I need to issue an additional exit order to close any positions that were left open by the partial fill?
    3) If there is a partial fill on a target, why would you set its object reference (e.g. targetOrder) to null? Does this mean that once targetOrder has a status of Filled/PartFilled that the targetOrder has no further value, because I need to deal with the open position with a new order?

    A sample strategy dealing with partial fills would be great!!

    thanks

    #2
    1. Not sure what you mean by checking open positions. You would have had to keep track of open positions from the start through your entryOrder's IOrder. When the exit order has not reached a filled quantity matching the entry order's filled quantity you know you have an open position. You also know you have an open position by simply doing something like if (Position.MarketPosition != MarketPosition.Flat)

    2. Partial filled exit orders should continue to work to get you to a filled state. There is usually no additional work that needs to be done. Resetting the IOrder to null should be done after the order reaches a terminal state.

    3. Reset to null only when in a terminal state. i.e. filled, cancelled, rejected.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response.
      Josh in point (2) you state " Resetting the IOrder to null should be done after the order reaches a terminal state."
      That makes sense, but it appears to be done differently in
      SampleOnOrderUpdate, in the OnExecution method. In there, the stopOrder, targetOrder object references are set to null even if it is a partial fill, i.e., it has not reached a terminal state. See code below:

      Would it not be a good idea to hold onto the exit references (stopOrder, targetOrder) until the exit order is totally filled, so that I know that it is all good?
      However, if I do not nullify those exit variables at the part-filled state (as done in the sample), then I can see a potential problem. Referring to the first portion of code in OnExecution within SampleOnOrderUpdate; if my ENTRY order was part-filled, and now becomes fully filled, then the logic in that method will want to use the stopOrder, targetOrder variables to set up exits for the last part of my entry order.

      And if I did not previously nullify them, because they were only part-filled, then I would be overwriting the first set of object variables withe a new set. If I do that, how will I know when the first set of exits are fully filled? either way, I cannot be sure that both sets of exits have been fully filled.

      // Reset our stop order and target orders' IOrder objects after our position is closed.
      if ((stopOrder != null && stopOrder.Token == execution.Order.Token) || (targetOrder != null && targetOrder.Token == execution.Order.Token))
      {
      if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
      {
      stopOrder =
      null;
      targetOrder =
      null;
      }
      }

      thanks.

      Comment


        #4
        astrolobe,

        Please disregard the resetting on non-terminal states. If you lose references by setting to null it is gone. There would be no way for you to check back on the original set.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh, I am not sure what you are saying that I should do. Is the code in SampleOnOrderUpdate correct as it stands, or should I only nullify the exit references on "Filled"? Remember, they are going to be overwritten anyway when the second part of my original entry is filled. Sorry if I am being dense, but I need a bit more detail to clarify a workable solution.
          thanks.

          Comment


            #6
            Just null the IOrders when you are done with using them. This means when it reaches a terminal state. When a partial fill comes in the are NOT overwritten. They are amended. The orders sent amend the original, nothing is lost. Things are only "lost" when you null the IOrder.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Partial fill exit, tied to a partial fill entry.

              Josh, I understand that I need to hang onto the IOrders until they are completely filled, but I believe there is still a problem with the code in SampleOnOrderUpdate. I have attached the OnExecution method, which has been numbered to walk through a scenario which I believe might be a problem.

              Scenario:
              • I enter a order for 10 contracts. I get a partial fill of 6 contracts.
              • In OnExecution I create a stop and target for the 6 contracts at (1)
              • Before the remaining 4 entry contracts are filled, I get a partial fill for my target EXIT order for only 3 of the original 6 contracts.
              • This results in a reentry into OnExecution for the partial fill of my target exit order. Because the target exit is only a partial fill of 3 contracts (of the original partial entry fill of 6), I do NOT null the object references at (3), following your advise in your previous post.
              • Now the remaining 4 ENTRY contracts are filled. We therefore reenter OnExecution, and as the code stands at (1), we will inadvertantly overwrite the stopOrder and targetOrder references with new ones for the latest 4 entry contracts that have just been filled. (Remember those variables were deliberately not nulled previously, because the target exit order only received a partial fill of 3 contracts.)

              Bottom Line: I have no way of avoiding the loss of those exit references, which I still need to monitor as I wait for the remaining 3 exit contracts to be filled (from the original partial fill of 6 contracts).

              Hopefully my detailed sequence of events listed above will highlight a flaw in my understanding, or you will recognize that there is a issue when you get a partial fill exit, that is tied to a partial fill entry...and your code is structured like SampleOnOrderUpdate.
              Attached Files
              Last edited by astrolobe; 09-02-2009, 07:01 PM.

              Comment


                #8
                astrolobe,

                We have already concluded several posts back to ignore portions of the SampleOnOrderUpdate for your intents and purposes.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Yes, that was not the focus of my last post at all, as that was taken as a given. Please re read as the issue is that even if we ignore the parts of code discussed previously, those exit variables will be overwritten when the original order of 10 contracts is totally filled.
                  If you see in bullet 3 of my previous post I even state that my logic has assumed following your advise in your previous post..
                  You have missed the point of my detailed email, please review it again to see what I am talking about.

                  thanks
                  Last edited by astrolobe; 09-03-2009, 07:21 AM.

                  Comment


                    #10
                    It doesn't matter if it gets overwritten. The order is already filled.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      The exit order on the first 6 contracts is NOT already filled, it is only partially filled with 3 contracts. Then price reverses suddenly and completes the 10 contract entry with the last 4 contracts. This results in the exit variables in OnExecution being overwritten to create a stop and target for the final 4 entry contracts, while the second half (3 contracts) of the original target have not been filled yet. (it makes more sense in my detailed post).
                      Last edited by astrolobe; 09-03-2009, 07:37 AM.

                      Comment


                        #12
                        Not following you. There is one stop/target. As the entry order gets more partial fills, the original set of stop/target simply gets amended to accomodate. It doesn't matter if it "overwrites" the prior because the amended one it is using contains the same information and more than the original.

                        Please ensure you are running your strategy with ByStrategyPosition for the Stops and Target handling.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        647 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        368 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        108 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        571 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X