Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to avoid overfill when exit submitted when stop is executed

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

    how to avoid overfill when exit submitted when stop is executed

    Hi,

    I would like to avoid an overfill problem that crashes my strategie tests. It happens when I submit an ExitLong that happens to be executed at the same moment/price of the stop order.

    Is this the best solution ?

    Code:
     if ( exit trade conditions && 
         stopRunnerOrder != null && stopRunnerOrder.StopPrice != GetCurrentBid()) )
    {
      ...
      exitRunnerOrder = ExitLong(.... );
    }
    Thx.

    #2
    Hello,

    Thanks for the note and welcome to the NinjaTrader support forum.

    Over-Fills is a serious issue that can occur when using complex entry conditions that bracket the market in both directions end up with both entries being filled instead of one being cancelled. Over-Fills can also occur when you place a trade quickly hoping to close a position while a prior order to close the same position already had an in-flight execution. The exact scenarios in which an over-fill can occur is highly dependent on the specific strategy programming. By default, NinjaTrader will protect against over-fills even though you are using the Unmanaged approach by halting the strategy, but should you decide to custom program your own over-fill handling it is up to you to either prevent over-fills from being a possibility in your code or by introducing logic to address over-fills should one occur.

    With the above said, the best approach I can think of it to first cancel your stop loss order and recieve confirmation back that it is cancelled and then submit the exit order.

    This would entail working with iOrder objects.







    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Thank you Brett.

      How about submitting the Exit order (as before in OnBarUpdate), and Cancel the eventual Exit in the stop handling (in OnExecution) ?

      something like
      Code:
      if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
      {
        if (stopRunnerOrder != null && stopRunnerOrder == execution.Order)
        {
          // if stop is executed dring submission of exit, cancel the exit
          if ( exitRunnerOrder != null )
              CancelOrder(exitRunnerOrder);
          stopRunnerOrder = null;
          exitRunnerOrder = null;                    
      ...

      Comment


        #4
        Hello,

        Not sure I would want to do this as you will still run into in flight executions. You cannot cancel the order fast enough since the cancel request must be sent from your PC and back. The issue is you dont know if the stop order is executed until after you submit the exit order and you find that your in an overfill in flight execution situtation.

        ONly solution I can think of off top of head is to first cancel the stop order and then wait for confirmation it is cancelled. Then submit the exit order.

        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment


          #5
          Thank you Brett. I'll do as you suggested.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          670 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          379 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          582 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X