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

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.

    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.

        Comment


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by PaulMohn, Today, 05:00 AM
          0 responses
          6 views
          0 likes
          Last Post PaulMohn  
          Started by ZenCortexAuCost, Today, 04:24 AM
          0 responses
          5 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by ZenCortexAuCost, Today, 04:22 AM
          0 responses
          2 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by SantoshXX, Today, 03:09 AM
          0 responses
          16 views
          0 likes
          Last Post SantoshXX  
          Started by DanielTynera, Today, 01:14 AM
          0 responses
          3 views
          0 likes
          Last Post DanielTynera  
          Working...
          X