Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple orders: An order has been ignored

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

    Multiple orders: An order has been ignored

    Hi, all

    I read several topics how to avoid such situation when your order (Stop order) is ignored. But there is no luck when I try to enter multiple orders. Why am I doing this? For trailing purpose, one order without trail, another with trailing stop and take profit.

    0.
    Code:
                                                        
                                EnterShort (seriesnum, TrailQty, ShortTrail);
                                EnterShort (seriesnum, ContractQty, RegularShort);    ​
    1. So, I use OrderFillResolution = OrderFillResolution.High;
    2. I use check for Stop price and GetCuurentAsk() in OnPositionUpdate

    Code:
                    if (StopShort >= GetCurrentAsk())            
                    {
    
                        ExitShortStopMarket (seriesnum, true, ContractQty, StopShort, RegularShortStop, RegularShort);
                    }​
    3. I use tick series for intrabar granularity (seriesnum=1 from above code)
    Code:
                else if (State == State.Configure)
                {
                    AddDataSeries(this.Instrument.FullName, Data.BarsPeriodType.Tick, 1);    
                    //AddDataSeries(this.Instrument.FullName, Data.BarsPeriodType.Minute, 5);
                }​
    And what I got so far:
    Code:
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='ShortTrail' FromEntrySignal=''
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=3 LimitPrice=0 StopPrice=0 SignalName='RegShort' FromEntrySignal=''
    31.07.2023 9:55:00 StopShortTrail GetCurrentAsk()81,38 >= 81,2
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=81,38 SignalName='ShortTrailStop' FromEntrySignal='ShortTrail'
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=79,80 StopPrice=0 SignalName='ShortTrailTP' FromEntrySignal='ShortTrail'
    31.07.2023 9:55:00 StopShort GetCurrentAsk()81,38 >= 81,2
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,38 SignalName='RegShortStop' FromEntrySignal='RegShort'
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=3 LimitPrice=80,80 StopPrice=0 SignalName='RegShortTP' FromEntrySignal='RegShort'
    31.07.2023 9:55:00 StopShortTrail GetCurrentAsk()81,38 >= 81,2
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=81,38 SignalName='ShortTrailStop' FromEntrySignal='ShortTrail'
    31.07.2023 9:55:10 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=81,38 SignalName='ShortTrailStop' FromEntrySignal='ShortTrail' Reason='Order already has this stop price/limit price/quantity'
    31.07.2023 9:55:10 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=79,80 StopPrice=0 SignalName='ShortTrailTP' FromEntrySignal='ShortTrail'
    31.07.2023 9:55:10 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=79,80 StopPrice=0 SignalName='ShortTrailTP' FromEntrySignal='ShortTrail' Reason='Order already has this stop price/limit price/quantity'
    31.07.2023 10:13:08 Strategy 'StratCL: Cancelled pending exit order, since associated position is closed, orderId='NT-00006-21167' account='Backtest' name='ShortTrailTP' orderState=Working instrument='MCL 09-23' orderAction=BuyToCover orderType='Limit' limitPrice=79.8 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-07-31 09:55:10' gtd='2099-12-01' statementDate='2023-08-02'
    31.07.2023 10:13:00 StopShort GetCurrentAsk()81,38 >= 81,34
    31.07.2023 10:13:08 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,38 SignalName='RegShortStop' FromEntrySignal='RegShort'
    31.07.2023 10:13:08 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,38 SignalName='RegShortStop' FromEntrySignal='RegShort' Reason='Order already has this stop price/limit price/quantity'
    31.07.2023 10:13:08 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=3 LimitPrice=80,80 StopPrice=0 SignalName='RegShortTP' FromEntrySignal='RegShort'
    31.07.2023 10:13:08 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=3 LimitPrice=80,80 StopPrice=0 SignalName='RegShortTP' FromEntrySignal='RegShort' Reason='Order already has this stop price/limit price/quantity'
    31.07.2023 10:13:00 StopShortTrail GetCurrentAsk()81,38 >= 81,34
    31.07.2023 10:13:08 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=81,38 SignalName='ShortTrailStop' FromEntrySignal='ShortTrail'
    Strategy 'StratCL': An order has been ignored since the stop price ‘81.38’ near the bar stamped ‘31.07.2023 10:13:00’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
    31.07.2023 10:13:08 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=81,38 SignalName='ShortTrailStop' FromEntrySignal='ShortTrail' Reason='Invalid order price, please see log tab'
    31.07.2023 10:13:08 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=79,80 StopPrice=0 SignalName='ShortTrailTP' FromEntrySignal='ShortTrail'
    31.07.2023 10:13:08 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=79,80 StopPrice=0 SignalName='ShortTrailTP' FromEntrySignal='ShortTrail' Reason='SignalName does not have a matching FromEntrySignal to exit'
    31.07.2023 10:13:08 Strategy 'StratCL: Cancelled pending exit order, since associated position is closed, orderId='NT-00008-21167' account='Backtest' name='RegShortTP' orderState=Working instrument='MCL 09-23' orderAction=BuyToCover orderType='Limit' limitPrice=80.8 stopPrice=0 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-07-31 09:55:10' gtd='2099-12-01' statementDate='2023-08-02'
    ​


    So, any solution how to deal with it? Thank you!

    #2
    And I use
    Code:
                    EntryHandling                                = EntryHandling.UniqueEntries;
                    EntriesPerDirection                            = 4​;
    for multiple entries.

    Comment


      #3
      Hello mrboltuae,

      Thanks for your post.

      I see in the code you shared that you are dynamically calling AddDataSeries(). You should hardcode the arguments used when calling AddDataSeries as noted in the help guide.

      From the AddDataSeries() help guide: "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided."

      AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

      ​That said, the order is ignored because the stop loss is already submitted at the stop price that you are trying to submit the order to.

      In the information you shared, we can see that your strategy submitted a stop market order at the stop price 81,38.

      Entered internal SubmitOrderManaged() method at 31.07.2023 9:55:10: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,38 SignalName='RegShortStop' FromEntrySignal='RegShort'

      Then the strategy's condition to call the order method again becomes true and the strategy tries to submit the order to the same exact stop price of 81,38 so the order is ignored.

      31.07.2023 10:13:08 Strategy 'StratCL': Entered internal SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,38 SignalName='RegShortStop' FromEntrySignal='RegShort'

      31.07.2023 10:13:08 Strategy 'StratCL': Ignored SubmitOrderManaged() method at 31.07.2023 10:13:08: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,38 SignalName='RegShortStop' FromEntrySignal='RegShort' Reason='Order already has this stop price/limit price/quantity'​

      You would need to make sure that the strategy is not submitting the stop market order to the same exact price that it was already submitted to.

      You are also getting the error message: "An order has been ignored since the stop price ‘81.38’ near the bar stamped ‘31.07.2023 10:13:00’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored."

      ExitLongStopMarket orders must be below the current price at the time they are placed, and vice versa for ExitShortStopMarket or they will be ignored. By the time the order is placed it is already on the wrong side of the current price and is summarily ignored. You could consider placing your stops farther from the current price to avoid these scenarios should the market move quickly.

      I would recommend you add prints to the strategy to determine why the stop order is being ignored. One line above where the stop order is placed, print the GetCurrentAsk() and print the price being submitted to the order method to see how they are evaluating.

      ​If you are backtesting the script in the Strategy Analyzer, see this forum thread about adding intrabar granularity:
      Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.
      Last edited by NinjaTrader_BrandonH; 08-02-2023, 01:45 PM.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Brandon, hi! Thanks for the quick response, appreciate it.

        1. Thanks for the input on the Add data series, noted.
        2. How to avoid such situation when the strategy tries to submit the same order? What I have now:
        Code:
        OnBarUpdate():
                                    EnterShort (0, TrailQty, ShortTrail);
                                    EnterShort (0, ContractQty, RegularShort);    ​
        
        OnOrderUpdate()
                    else if (order.Name == RegularShort)
                    {
                        entryOrderShort = order;
        
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                            entryOrderShort = null;
                            sumFilled = 0;
                        }
        
                        // if entry order exists
                          if (entryOrderShort != null && entryOrderShort == order)
                          {
                              //Print(entryOrderShort.ToString());            
                        }                
                    }        
        
                    else if (order.Name == ShortTrail)
                    {
                        entryOrderShortTrail = order;
        
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                            entryOrderShortTrail = null;
                            sumFilled = 0;
                        }
        
                        // if entry order exists
                          if (entryOrderShortTrail != null && entryOrderShortTrail == order)
                          {
                              //Print(entryOrderShortTrail.ToString());            
                        }                
                    }    
                    ​
                    else if (order.Name == RegularShortStop)
                    {
                        stopOrderShort = order;
        
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                            stopOrderShort = null;
                            sumFilled = 0;
                        }
        
                        // if entry order exists
                          if (stopOrderShort != null && stopOrderShort == order)
                          {
                              //Print("TEST");
                            //Print(stopOrderShort.ToString());            
                        }                    
                    }    
        
                    else if (order.Name == ShortTrailStop)
                    {
                        stopOrderShortTrailStop = order;
        
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                            stopOrderShortTrailStop = null;
                            sumFilled = 0;
                        }
        
                        // if entry order exists
                          if (stopOrderShortTrailStop != null && stopOrderShortTrailStop == order)
                          {
                              //Print("TEST");
                            //Print(stopOrderShort.ToString());            
                        }                    
                    }        ​
        
                    else if (order.Name == RegularShortTP)
                    {
                        targetOrderShort = order;
        
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                            targetOrderShort = null;
                            sumFilled = 0;
                        }
        
                        // if entry order exists
                          if (targetOrderShort != null && targetOrderShort == order)
                          {
                              //Print(targetOrderShort.ToString());            
                        }                    
                    }        
        
                    else if (order.Name == ShortTrailTP)
                    {
                        targetOrderShortTrailTP = order;
        
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                            targetOrderShortTrailTP = null;
                            sumFilled = 0;
                        }
        
                        // if entry order exists
                          if (targetOrderShortTrailTP != null && targetOrderShortTrailTP == order)
                          {
                              //Print(targetOrderShort.ToString());            
                        }                    
                    }    ​
        
        OnPositionUpdate()
        
                    if (Position.MarketPosition == MarketPosition.Short
                        && (entryOrderShort != null && entryOrderShort.OrderState == OrderState.Filled))
                    {
        
                        //Print("RegularShortStop");
        
                        // +------------------------------------------------------------+
                        // | Determine ATR Target                                       |
                        // +------------------------------------------------------------+
                        var target = LowO - TargetProfit;
        
                        //ATRStop = Low[1] + (ATRMultiplier * (ATR (ATRLength) [1]));
                        if (StopShort >= GetCurrentAsk())            
                        {
                            //Print(Time[0] + " StopShort GetCurrentAsk()" + StopShort + " >= " + GetCurrentAsk());
                            ExitShortStopMarket (0, true, ContractQty, StopShort, RegularShortStop, RegularShort);
                        }
        
                        // +------------------------------------------------------------+
                        // | Set limit target to ATR                                    |
                        // +------------------------------------------------------------+
                        ExitShortLimit (0, true, ContractQty, target, RegularShortTP, RegularShort);
                        //Square targetSquare = Draw.Square (this, "initialTarget" + CurrentBar, true, 0, target, Brushes.White);
        
                    }        
        
                    if (Position.MarketPosition == MarketPosition.Short && entryOrderShortTrail != null && entryOrderShortTrail.OrderState == OrderState.Filled)
                    {
        
                        //Print("RegularShortStop");
        
                        // +------------------------------------------------------------+
                        // | Determine ATR Target                                       |
                        // +------------------------------------------------------------+
                        var target = LowO - RangeO * 5.33;
        
                        //ATRStop = Low[1] + (ATRMultiplier * (ATR (ATRLength) [1]));
                        if (StopShort >= GetCurrentAsk())            
                        {
                            //Print(Time[0] + " StopShortTrail GetCurrentAsk()" + StopShort + " >= " + GetCurrentAsk());
                            ExitShortStopMarket (0, true, TrailQty, StopShort, ShortTrailStop, ShortTrail);
                        }
        
                        // +------------------------------------------------------------+
                        // | Set limit target to ATR                                    |
                        // +------------------------------------------------------------+
                        ExitShortLimit (0, true, TrailQty, target, ShortTrailTP, ShortTrail);
                        //Square targetSquare = Draw.Square (this, "initialTarget" + CurrentBar, true, 0, target, Brushes.White);
        
                    }        ​
        3. "ExitLongStopMarket orders must be below the current price at the time they are placed, and vice versa for ExitShortStopMarket or they will be ignored." - yes, I know, that's why I'm putting the condition if (StopShort >= GetCurrentAsk()), and by prints earlier you can see that condition is true:
        Code:
        31.07.2023 10:13:00 StopShort GetCurrentAsk()81,38 >= 81,34
        31.07.2023 10:13:00 StopShortTrail GetCurrentAsk()81,38 >= 81,34

        Comment


          #5
          Hello mrboltuae,

          Thanks for your notes.

          We advise monitoring OnExecutionUpdate() to trigger the submission of stop/target orders which ensures your strategy has received the execution which is used for internal signal tracking.

          The condition to call your Exit order method is becoming true and you are using the same exact stop price when the order method is called again.

          You would need to modify your code so that you are not submitting the order to the same stop price (StopShort).

          Something you could consider doing is tracking the stop order object in OnOrderUpdate()/OnExecutionUpdate() and creating a condition that checks if the stop price being submitted to the order is not equal to the price the order was submitted at.

          See the reference sample linked below demonstrating using OnOrderUpdate()/OnExecutionUpdate(). This reference sample also demonstrates modifying a stop loss order.

          SampleOnOrderUpdate(): https://ninjatrader.com/support/help...and_onexec.htm


          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Hi, Brandon

            I moved all logic on TP and SL into OnExecutionUpdate, now I don't recieve any error which I had previously, thank you so much. But now I'm getting a strange behaviour, and specifically regarding LONG position.

            What is strange: that RegLongTP was cancelled, and I don't clear understand the reason. Have a look on output and screens from chart.

            I mean about this cancellation:
            Code:
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00009-12612' account='Backtest' name='RegLongTP' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Limit' limitPrice=82.63 stopPrice=0 quantity=7 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00008-12612' account='Backtest' name='RegLongStop' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=80.8 quantity=7 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00011-12612' account='Backtest' name='LongTrailTP' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Limit' limitPrice=84.61 stopPrice=0 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00010-12612' account='Backtest' name='LongTrailStop' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=80.8 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'​​
            Code:
            ----------SHORT-----------
            03.08.2023 8:10:48 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 8:10:48: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=7 LimitPrice=0 StopPrice=0 SignalName='RegShort' FromEntrySignal=''
            03.08.2023 8:10:48 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 8:10:48: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=3 LimitPrice=0 StopPrice=0 SignalName='ShortTrail' FromEntrySignal=''
            03.08.2023 8:10:48 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 8:10:48: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=7 LimitPrice=0 StopPrice=80,72 SignalName='RegShortStop' FromEntrySignal='RegShort'
            03.08.2023 8:10:48 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 8:10:48: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=7 LimitPrice=78,89 StopPrice=0 SignalName='RegShortTP' FromEntrySignal='RegShort'
            03.08.2023 8:10:48 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 8:10:48: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=80,72 SignalName='ShortTrailStop' FromEntrySignal='ShortTrail'
            03.08.2023 8:10:48 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 8:10:48: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=3 LimitPrice=76,91 StopPrice=0 SignalName='ShortTrailTP' FromEntrySignal='ShortTrail'
            03.08.2023 9:43:52 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00003-12612' account='Backtest' name='RegShortTP' orderState=Working instrument='MCL 09-23' orderAction=BuyToCover orderType='Limit' limitPrice=78.89 stopPrice=0 quantity=7 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 08:10:48' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 9:43:52 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00005-12612' account='Backtest' name='ShortTrailTP' orderState=Working instrument='MCL 09-23' orderAction=BuyToCover orderType='Limit' limitPrice=76.91 stopPrice=0 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 08:10:48' gtd='2099-12-01' statementDate='2023-08-05'
            ----------LONG-----------
            03.08.2023 10:19:12 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 10:19:12: BarsInProgress=1 Action=Buy OrderType=Market Quantity=7 LimitPrice=0 StopPrice=0 SignalName='RegLong' FromEntrySignal=''
            03.08.2023 10:19:12 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 10:19:12: BarsInProgress=1 Action=Buy OrderType=Market Quantity=3 LimitPrice=0 StopPrice=0 SignalName='LongTrail' FromEntrySignal=''
            03.08.2023 10:19:12 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 10:19:12: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=7 LimitPrice=0 StopPrice=80,80 SignalName='RegLongStop' FromEntrySignal='RegLong'
            03.08.2023 10:19:12 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 10:19:12: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=7 LimitPrice=82,63 StopPrice=0 SignalName='RegLongTP' FromEntrySignal='RegLong'
            03.08.2023 10:19:12 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 10:19:12: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=80,80 SignalName='LongTrailStop' FromEntrySignal='LongTrail'
            03.08.2023 10:19:12 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 03.08.2023 10:19:12: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=3 LimitPrice=84,61 StopPrice=0 SignalName='LongTrailTP' FromEntrySignal='LongTrail'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00009-12612' account='Backtest' name='RegLongTP' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Limit' limitPrice=82.63 stopPrice=0 quantity=7 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00008-12612' account='Backtest' name='RegLongStop' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=80.8 quantity=7 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00011-12612' account='Backtest' name='LongTrailTP' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Limit' limitPrice=84.61 stopPrice=0 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'
            03.08.2023 10:19:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00010-12612' account='Backtest' name='LongTrailStop' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=80.8 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-03 10:19:12' gtd='2099-12-01' statementDate='2023-08-05'​
            ​
            Attached Files

            Comment


              #7
              Just want to add more. On 4th of August there was cancellation of trail order:
              Code:
              04.08.2023 9:30:46 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 04.08.2023 9:30:46: BarsInProgress=1 Action=Buy OrderType=Market Quantity=7 LimitPrice=0 StopPrice=0 SignalName='RegLong' FromEntrySignal=''
              04.08.2023 9:30:46 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 04.08.2023 9:30:46: BarsInProgress=1 Action=Buy OrderType=Market Quantity=3 LimitPrice=0 StopPrice=0 SignalName='LongTrail' FromEntrySignal=''
              04.08.2023 9:30:46 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 04.08.2023 9:30:46: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=7 LimitPrice=0 StopPrice=81,84 SignalName='RegLongStop' FromEntrySignal='RegLong'
              04.08.2023 9:30:46 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 04.08.2023 9:30:46: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=7 LimitPrice=83,07 StopPrice=0 SignalName='RegLongTP' FromEntrySignal='RegLong'
              04.08.2023 9:30:46 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 04.08.2023 9:30:46: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=3 LimitPrice=0 StopPrice=81,84 SignalName='LongTrailStop' FromEntrySignal='LongTrail'
              04.08.2023 9:30:46 Strategy 'STRAT': Entered internal SubmitOrderManaged() method at 04.08.2023 9:30:46: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=3 LimitPrice=84,18 StopPrice=0 SignalName='LongTrailTP' FromEntrySignal='LongTrail'
              04.08.2023 11:49:33 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00008-12682' account='Backtest' name='RegLongStop' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=81.84 quantity=7 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-04 09:30:46' gtd='2099-12-01' statementDate='2023-08-05'
              04.08.2023 11:49:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00011-12682' account='Backtest' name='LongTrailTP' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Limit' limitPrice=84.18 stopPrice=0 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-04 09:30:46' gtd='2099-12-01' statementDate='2023-08-05'
              04.08.2023 11:49:00 Strategy 'STRAT: Cancelled pending exit order, since associated position is closed, orderId='NT-00010-12682' account='Backtest' name='LongTrailStop' orderState=Working instrument='MCL 09-23' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=81.84 quantity=3 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-08-04 09:30:46' gtd='2099-12-01' statementDate='2023-08-05'
              ​
              Again don't understand the reason. Why stop loss for regular long was cancelled - this is obvious, because of target hit, but why for trailing order?

              And how I enter positions OnBarUpdate():
              Code:
                                          if (entryOrderLong == null && entryOrderLongTrail == null
                                              && Position.MarketPosition == MarketPosition.Flat)
                                          {
                                              EnterLong (1, ContractQty, RegularLong);
                                              EnterLong (1, TrailQty, LongTrail);
                                          }
              ​
              OnOrderUpdate():
              Code:
                          if (order.Name == RegularLongTP)
                          {
                              targetOrderLong = order;
              
              
                              // Reset the entryOrder object to null if order was cancelled without any fill
                              if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                              {
              
                                  targetOrderLong = null;
                              }
              
                              // if entry order exists
                                if (targetOrderLong != null && targetOrderLong == order)
                                {
                              }                    
                          }
              
                          else if (order.Name == LongTrailTP)
                          {
                              targetOrderLongTrailTP = order;
              
                              // Reset the entryOrder object to null if order was cancelled without any fill
                              if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                              {
                                  targetOrderLongTrailTP = null;
                              }
              
                              // if entry order exists
                                if (targetOrderLongTrailTP != null && targetOrderLongTrailTP == order)
                                {        
                              }                    
                          }    ​
              ​

              Comment


                #8
                Hello mrboltuae,

                Thanks for your notes.

                That message indicates that a position is not present for the order or that the position the stop/target was targeting was closed in some way.

                It could be that the position has not been updated yet if you are using OnOrderUpdate() for submitting any of your orders. You should make sure that any submission of orders is done within OnExecutionUpdate() to ensure that the position is updated.

                From the SampleOnOrderUpdate reference sample linked in post # 5: "We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate() which ensures your strategy has received the execution which is used for internal signal tracking.​"

                Further, prints and TraceOrders should be used to understand exactly how the strategy is behaving. Below is a link to a forum post that demonstrates using prints and TraceOrders to understand behavior.

                https://ninjatrader.com/support/foru...121#post791121
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Hi NinjaTrader_BrandonH ,

                  I know that the topic is old, but now I have the same issues and I this topic now. As I read the chat history, I guess that this also may be a problem because there are 2 separated order submitted with different signal names. When the one order is updated, the other one may be still not updated. But this is leading to invocation of the OnOrderUpdate() method and check iof the state of the order that is still not filled. This is leading to some cancellation reports or other problems. May be the best solution is to submit one order with 2 contracts. And than only to submit different stop loss orders - one trailing and one hard-set.

                  Best wishes​
                  Last edited by nrgful; 05-05-2025, 12:00 AM.

                  Comment


                    #10
                    NinjaTrader_BrandonH,
                    One more technical question:

                    Why OnExecutionUpdate() ensures that the order is placed, but if check OnOrderUpdate() -> order.State == Filled is not ensuring proper behaviour ?
                    Why is this?

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    44 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    126 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    65 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    42 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    46 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X