Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

An overfill was detected on order

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

    An overfill was detected on order

    Hello, i have running a automatic strategy and sometimes are launched this alert and error: "An overfill was detected on order" then the strategy is disabled.

    I dont understand why because my strategy works OnBarClose=true and that is the functions called only one time:

    For entry long:
    Code:
    if (Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Short){
                    SetStopLoss(CalculationMode.Ticks, 20);
                    ExitShort();EnterLong(1,"");
                }
    For entry short:

    Code:
     
    if (Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Long){
                    SetStopLoss(CalculationMode.Ticks, 20);
                    ExitLong();EnterShort(1,"");
                }
    The error happend when a position is open and try to exist and open a contrary.
    Could you help me please? I dont know whats i am doing bad.


    Thank you

    #2
    Hello marynja,

    An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations.

    Your code is attempting to do opposing things, so you can improve handling by changing the structure a bit.

    You have to decide if you want reversal behavior or not and code for this. NinjaTrader Enter() methods will automatically reverse a position so if you want reversals you don't want to call Exit() method first.

    If you do not want the entries to reverse, then add a market position check for flat only before the entry conditions.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you RyanM

      Yes, really i want reversal orders when exists an open position.
      I think i understand. Then, for my code purpose is necesary remove the Exit functions because the Enter functions works as reversal order.

      Then the correctly code will be: ?

      if (Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Short){
      SetStopLoss(CalculationMode.Ticks, 20);
      EnterLong(1,"");
      }

      if (Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Long){
      SetStopLoss(CalculationMode.Ticks, 20);
      ExitLong();EnterShort(1,"");
      }

      Comment


        #4
        Yes, and you actually then don't need any market position checks.

        if (tradeConditions)
        {
        SetStopLoss(CalculationMode.Ticks, 20);
        EnterLong(1,"");
        }

        If you don't want to accept another long position while currently long, this is controlled with EntriesPerDirection along with EntryHandling properties.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Yes you are right. I wrote the position checks because i dont understand the overfill and i want made a filter.

          Thank you very much RyanM, i am going to try it.

          Comment


            #6
            Dear Ninjatrader Support,


            Hi, I'm not sure whether this is the proper place to post but as I don't know how to open a thread, I will post here.

            I have a FX strategy running on 1 min time frame and trade 100K position with IB IDEAL PRO.
            Sometimes I get partial fills and and a minute later, I get complete fill, then the Ninja will detect overfill and will disable the strategy.

            The summery of the Log is as follows;
            I think the cause of this problem happened because the order was completely filled righ after the change of a 1 min bar, right after the Ninja placed cancellation for the non filled portion, but before it was accepted by IB. (Sorry if I'm wrong)

            5:56:01 NT sent Entered Short Position 100K
            5.56:41 Partial Fill of 72K executed
            5:56:42 NT Position updated as Short
            5:56:42 NT SL, TP OCO order placed and accepted

            5:57:01 NT Change TP, SL order placed for 72K
            5:57:01 Pending Cancel Instrument for 100K order Filled 72K
            (cancellation order for the outstanding 28K because the minute bar updated)
            5:57:01 Complete fill of 100K was made for the order.
            Filled Instrument, Quantity 100K, Filled 100K
            5:57:01 Execution Quantity 28K filled
            5:57:01 Over Fill was detected and the strategy will be disabled.


            QUESTION 1
            Is there any way to avoid this from happening?

            QUESTION 2
            And is there any way to prevent the strategy to close all the positions and pending orders when the strategy is disabled?

            I have deleted the checkmark for the following two on Options Strategies NinjaScript Tab. But all positions and orders are canceled when the strategy is disabled And I lose the spread and comission.
            > Cancel entry orders when a strategy is disabled
            > Cancel exit orders when a strategy is disabled


            Look forward to hearing from you.

            Comment


              #7
              hana_maui, the issue seems here to be getting the PendingCancel before you would then see a fill for the rest of the order, technically this is then overfilled for NT as it attempting to cancel it before getting the fill. You would need to modify the code for a more finetuned order handling covering the partial fill situation / broker order feedback delay you ran into.

              The RealtTimeErrorHandling set would dictate what happens in those cases, per default the strategy is terminated but if you prefer to code your own overfill / order rejection handling, then you could set this to TakeNoAction, thus the strategy is continue to be run.

              BertrandNinjaTrader Customer Service

              Comment


                #8
                Dear Mr. Bertrand,

                Thanks for your advise.
                I will try and see if I can make some change in the codes to avoid this from happening.

                Comment


                  #9
                  Dear Mr. Bertrand,

                  Regarding our past conversation, in order to avoid disabling Strategy upon overfill, I have made following additions to the strategy.

                  Initialize()
                  {
                  RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
                  }

                  protected override void OnOrderUpdate(IOrder order)
                  {
                  if(order.OrderState == OrderState.Rejeted)
                  CancelOrder(order)
                  }

                  Even after this change,
                  It seems that that strategy will not be disabled immediately after overfill like it used to do, but will still said in the log,

                  2011/09/30 6:57:56 Strategy An over fill was detected on order. This strategy will be disabled and NinjaTrader will attempt to cancel/close any strategy generated orders and positions. Please check your account orders and positions and take any appropriate action.

                  And have closed all positions and then disabled the strategy after overfill Position updated in the strategy.


                  <QUESTION>
                  Does this mean that the change in the code is not reflected?
                  Or do I have to
                  1) remove Strategy from the Strategies Tab, or
                  2) shut down Ninjatrader, or
                  3) even reboot the computer?


                  I thought that changing
                  RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;

                  will make the strategy keep on running regardless of any error.

                  Your advice is appreciated.
                  Thank you.
                  Last edited by hana_maui; 09-30-2011, 07:34 AM.

                  Comment


                    #10
                    Hello hana_maui,

                    Overfills cannot be ignored in a managed strategy. RealTimeErrorHandling will apply only to rejected orders, not overfills.

                    Unmanaged strategies have a property IgnoreOverFill, which can be set to true to ignore these.

                    This does not necessarily mean that you should change your strategy into an unmanaged one in order to use this property. It's best first to recognize the situations where an overfill is likely, and code more order control.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Dear Mr. Ryan M,

                      Thanks for your reply.
                      That makes sense.

                      I will just make
                      liveUntilCancelled = true;

                      And cancel the Entry when the price become far from being filled.

                      Thank you for your assitance.

                      Comment


                        #12
                        An overfill was detected on order ...

                        Hello,

                        I have the same problem and I don't know why.

                        Code:
                        if (Position.MarketPosition == MarketPosition.Flat)
                        {
                            if (CrossAbove(MACD(5, 10, 3), MACD(5, 10, 3).Avg, 1)
                                && MACD(5, 10, 3).Avg[0] < 0)
                              	//&& ToTime(Time[0]) > ToTime(15, 35, 0)
                              	//&& ToTime(Time[0]) < ToTime(21, 50, 0))
                            {
                                  DrawLine("My line" + CurrentBar, 0, High[0] + 1 * TickSize, 0, Low[0] + -2 * TickSize, Color.Red);
                              	  EnterLong(DefaultQuantity, "long");
                            }
                            else if (CrossBelow(MACD(5, 10, 3), MACD(5, 10, 3).Avg, 1)
                                && MACD(5, 10, 3).Avg[0] > 0)
                              	//&& ToTime(Time[0]) > ToTime(15, 35, 0)
                              	//&& ToTime(Time[0]) < ToTime(21, 50, 0))
                            {
                                  DrawLine("My line" + CurrentBar, 0, High[0] + 1 * TickSize, 0, Low[0] + -2 * TickSize, Color.Red);
                                  EnterShort(DefaultQuantity, "short");
                            }				
                        } 
                        else if (Position.MarketPosition == MarketPosition.Short)
                        {
                          	if (CrossAbove(MACD(5, 10, 3), MACD(5, 10, 3).Avg, 1))
                          	{
                                    DrawLine("My line" + CurrentBar, 0, High[0] + 2 * TickSize, 0, Low[0] + -1 * TickSize, Color.Blue);
                              	    ExitShort("short");
                          	}
                        }			
                        else if (Position.MarketPosition == MarketPosition.Long)
                        {
                          	if (CrossBelow(MACD(5, 10, 3), MACD(5, 10, 3).Avg, 1))
                          	{
                                    DrawLine("My line" + CurrentBar, 0, High[0] + 2 * TickSize, 0, Low[0] + -1 * TickSize, Color.Blue);
                              	    ExitLong("long");
                          	}
                        }
                        I have running a automatic strategy and sometimes are launched this alert and error: "An overfill was detected on order" then the strategy is disabled.

                        Petr

                        Comment


                          #13
                          Hi Petr, have just replied to your note sent to support.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Hi I also ran into the overfill error this morning and need help with debugging.

                            The strategy is multi time frame, and it seems that a Short entry in 1440 min chart is filled while there is a exit in 1 min triggered at the same time. The funny thing is that this happens when I start the system. I could repeat the same behavior in live and sim account.

                            I wonder why a 1440 timeframe signal fires at 8.08 am, and the agian at anytime i start the system?

                            The code is the following

                            Code:
                            if (BarsInProgress == 0)
                            			{
                            					if (my conditions)
                            							{
                            								EnterShort();
                            							}
                            }
                            
                            			if (BarsInProgress == 1)
                            			{	
                            				if (Close[0] < Lows[0][0])
                            						{
                            							ExitLong();
                            						}
                            						
                            				if (Close[0] > Highs[0][0])
                            						{
                            							ExitShort();
                            						}
                            
                            				if (BarsSinceEntry(0,"",0) == 0)
                            				{
                            					if (Close[0] < Variable2)
                            					{
                            						ExitLong();
                            					}
                            					if (Close[0] > Variable1)
                            					{
                            						ExitShort();
                            					}
                            				}
                            			}

                            Comment


                              #15
                              Hello marcoheimann,
                              To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                              Please do let me know the exact settings so that I can reproductive the scenario at my end.

                              Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                              I look forward to assisting you further.

                              *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Barry Milan, Yesterday, 10:35 PM
                              4 responses
                              14 views
                              0 likes
                              Last Post Barry Milan  
                              Started by DanielSanMartin, Yesterday, 02:37 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post DanielSanMartin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post nandhumca  
                              Working...
                              X