Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancelled exit order, since associated position is closed

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

    Cancelled exit order, since associated position is closed

    Hello Ninjatraders,

    I wondered if anybody had an idea why I exitLongMIT orders are being cancelled?

    Scenario and log below:
    1. limit order is placed
    2. limit order is entered
    3. long exits are placed
    4. first partial LE25(18495.25)(10-13-0) is hit
    5. LE75, LE100, LE125 orders are cancelled because: "Cancelled pending exit order, since associated position is closed"
    All orders are placed with advanced order handling live until cancelled.
    All order have unique ID's.

    Time 11/04/2025 10:13:00:
    Execution:execution='c3bee1d43bcb454f8b5774fd02d92 96a' instrument='MNQ JUN25' account='Playback101' exchange=Default price=18475.5 quantity=2 marketPosition=Long orderId='82ba51fd15e64a8c8bff2011aa96710f' time='2025-04-11 10:13:12' sod=False statementDate='2025-04-11'
    Execution.orderrderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=PartFilled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=2 averageFillPrice=18475.5 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    EntryOrderrderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=PartFilled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=2 averageFillPrice=18475.5 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    Time 11/04/2025 10:13:00: execution happened, still LONG, adjust stoploss contracts
    Time 11/04/2025 10:13:00: adjust LONG stop contracs to 2
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=2 LimitPrice=0 StopPrice=18413,25 SignalName='Stoploss' FromEntrySignal='Friday:10:14-36'
    Time 11/04/2025 10:13:00:
    Execution:execution='3f348517c43041d695abf4111259f 7b0' instrument='MNQ JUN25' account='Playback101' exchange=Default price=18475.75 quantity=198 marketPosition=Long orderId='82ba51fd15e64a8c8bff2011aa96710f' time='2025-04-11 10:13:12' sod=False statementDate='2025-04-11'
    Execution.orderrderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=Filled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=18475.7475 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    EntryOrderrderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=Filled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=18475.7475 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    Time: 11/04/2025 10:13:00 - CancellAllOrders: resetEntryAndStop = False
    Time: 11/04/2025 10:13:00 - current order list:
    orderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=Filled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=18475.7475 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    orderId='f51c79723c1240ab9fcb4f7fa285d515' account='Playback101' name='Stoploss' orderState=Accepted instrument='MNQ JUN25' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=18413.25 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=757 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    Time 11/04/2025 10:13:00 : Placing exit orders for long position
    Time 11/04/2025 10:13:00: adjust LONG stop contracs to 200
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=200 LimitPrice=0 StopPrice=18413,25 SignalName='Stoploss' FromEntrySignal='Friday:10:14-36'
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Amended matching order at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=200 LimitPrice=0 StopPrice=18413,25 SignalName='Stoploss' FromEntrySignal='Friday:10:14-36'
    Time 11/04/2025 10:13:00 : Placing exit MIT orders for LONG position
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=MIT Quantity=33 LimitPrice=0 StopPrice=18590,25 SignalName='LE125(18590,25)(10-13-0)' FromEntrySignal='Friday:10:14-36'
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=MIT Quantity=33 LimitPrice=0 StopPrice=18555,00 SignalName='LE100(18555)(10-13-0)' FromEntrySignal='Friday:10:14-36'
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=MIT Quantity=33 LimitPrice=0 StopPrice=18519,75 SignalName='LE75(18519,75)(10-13-0)' FromEntrySignal='Friday:10:14-36'
    11/04/2025 10:13:12 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:12: BarsInProgress=0 Action=Sell OrderType=MIT Quantity=68 LimitPrice=0 StopPrice=18495,25 SignalName='LE25(18495,25)(10-13-0)' FromEntrySignal='Friday:10:14-36'
    Time 11/04/2025 10:13:00:
    Execution:execution='0f35163a122145709e9ffdaf1fe7d f0e' instrument='MNQ JUN25' account='Playback101' exchange=Default price=18494.75 quantity=1 marketPosition=Short orderId='15b7ed2abdea44b2ad27e75cfbb80481' time='2025-04-11 10:13:22' sod=False statementDate='2025-04-11'
    Execution.orderrderId='15b7ed2abdea44b2ad27e75cfbb80481' account='Playback101' name='LE25(18495,25)(10-13-0)' orderState=PartFilled instrument='MNQ JUN25' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=18495.25 quantity=68 tif=Gtc oco='' filled=1 averageFillPrice=18494.75 onBehalfOf='' id=761 time='2025-04-11 10:13:22' gtd='2099-12-01' statementDate='2025-04-11'
    EntryOrderrderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=Filled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=18475.7475 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    Time 11/04/2025 10:13:00: execution happened, still LONG, adjust stoploss contracts
    Time 11/04/2025 10:13:00: adjust LONG stop contracs to 199
    11/04/2025 10:13:22 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:22: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=199 LimitPrice=0 StopPrice=18413,25 SignalName='Stoploss' FromEntrySignal='Friday:10:14-36'
    11/04/2025 10:13:22 Strategy 'MWFuturesOpeningRangeGap/355822868': Amended matching order at 11/04/2025 10:13:22: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=199 LimitPrice=0 StopPrice=18413,25 SignalName='Stoploss' FromEntrySignal='Friday:10:14-36'
    11/04/2025 10:13:22 Strategy '355822868/MWFuturesOpeningRangeGap: Cancelled pending exit order, since associated position is closed, orderId='e804335f825346d3ae7f9a3122ccc4a4' account='Playback101' name='LE75(18519,75)(10-13-0)' orderState=Accepted instrument='MNQ JUN25' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=18519.75 quantity=33 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=760 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    11/04/2025 10:13:22 Strategy '355822868/MWFuturesOpeningRangeGap: Cancelled pending exit order, since associated position is closed, orderId='136dced9f5774483b77b99422f0f111b' account='Playback101' name='LE100(18555)(10-13-0)' orderState=Accepted instrument='MNQ JUN25' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=18555 quantity=33 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=759 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    11/04/2025 10:13:22 Strategy '355822868/MWFuturesOpeningRangeGap: Cancelled pending exit order, since associated position is closed, orderId='1643096df8ef497c893d4b86d1d0ce3e' account='Playback101' name='LE125(18590,25)(10-13-0)' orderState=Accepted instrument='MNQ JUN25' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=18590.25 quantity=33 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=758 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    11/04/2025 10:13:22 Strategy '355822868/MWFuturesOpeningRangeGap: Cancelled pending exit order, since associated position is closed, orderId='f51c79723c1240ab9fcb4f7fa285d515' account='Playback101' name='Stoploss' orderState=Accepted instrument='MNQ JUN25' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=18413.25 quantity=199 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=757 time='2025-04-11 10:13:22' gtd='2099-12-01' statementDate='2025-04-11'
    Time 11/04/2025 10:13:00:
    Execution:execution='a4c0cd64db4c4547bab772c70d52b 9ed' instrument='MNQ JUN25' account='Playback101' exchange=Default price=18494.5 quantity=67 marketPosition=Short orderId='15b7ed2abdea44b2ad27e75cfbb80481' time='2025-04-11 10:13:22' sod=False statementDate='2025-04-11'
    Execution.orderrderId='15b7ed2abdea44b2ad27e75cfbb80481' account='Playback101' name='LE25(18495,25)(10-13-0)' orderState=Filled instrument='MNQ JUN25' orderAction=Sell orderType='MIT' limitPrice=0 stopPrice=18495.25 quantity=68 tif=Gtc oco='' filled=68 averageFillPrice=18494.5036764706 onBehalfOf='' id=761 time='2025-04-11 10:13:22' gtd='2099-12-01' statementDate='2025-04-11'
    EntryOrderrderId='82ba51fd15e64a8c8bff2011aa96710f' account='Playback101' name='Friday:10:14-36' orderState=Filled instrument='MNQ JUN25' orderAction=Buy orderType='MIT' limitPrice=0 stopPrice=18475.25 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=18475.7475 onBehalfOf='' id=756 time='2025-04-11 10:13:12' gtd='2099-12-01' statementDate='2025-04-11'
    Time 11/04/2025 10:13:00: execution happened, still LONG, adjust stoploss contracts
    Time 11/04/2025 10:13:00: adjust LONG stop contracs to 132
    11/04/2025 10:13:22 Strategy 'MWFuturesOpeningRangeGap/355822868': Entered internal SubmitOrderManaged() method at 11/04/2025 10:13:22: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=132 LimitPrice=0 StopPrice=18413,25 SignalName='Stoploss' FromEntrySignal='Friday:10:14-36'​
    Thanks in advance for the help since I am currently stuck.

    I tried:
    • having fromSignalentry empty
    • having fromsignalentry matched to enty order
    • placing stoploss before limit entries
    • placing stoploss after limit entries
    Extra info:
    • the quoted log contains trace orders
    • the quoted log is the logic that is handled within OnExecutionUpdate override.
    • in the logic of OnExecutionUpdate or onBarUpdate (which is set to calculate on bar close), we never enter a statement that would close these order manually.

    I never have had this issue before with creating strategies and could not find an answer in previous asked questions matching my exact scenario.

    Kind regards,

    Jelle

    #2
    Extra visual information what log looks like.
    Click image for larger version

Name:	image.png
Views:	82
Size:	28.3 KB
ID:	1340432Click image for larger version

Name:	image.png
Views:	78
Size:	27.0 KB
ID:	1340433​​

    Comment


      #3
      Hello,

      The message 'Cancelled pending exit order, since associated position is closed' means that another order exited the position made by the entry this exit is attached to so it is automatically cancelled.

      To confirm, you want the exit order to remain open even though the position was closed by another order?

      If so, you would need to use the unmanaged approach.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello,

        The message 'Cancelled pending exit order, since associated position is closed' means that another order exited the position made by the entry this exit is attached to so it is automatically cancelled.

        To confirm, you want the exit order to remain open even though the position was closed by another order?

        If so, you would need to use the unmanaged approach.
        Hey NinjaTrader_ChelseaB,

        Currenty I already use the unmanaged approach.
        Example of the intra bar order placement is seen in the 2 images.

        The 1st image shows you the entry and that the take profit targets are placed including stoploss.
        The 2nd image shows that the first tp target was hit, filled and that the stop contracts have been adjusted.

        To confirm, you want the exit order to remain open even though the position was closed by another order?
        Currently I already use the unmanaged approach. I always use this and hence why I am confused why the tp targets are closed with this message.
        This due to it not being linked to an order of my understanding.

        Example code used for the take take partial profits upon complete fill of the limit order:
        Code:
        PlaceStopLoss();
        
        Print(string.Format("Time {0} : Placing exit MIT orders for LONG position", Time[0]));
        if (entryInformationObject.AmountOfContracts125 > 0) placedOrders.Add(ExitLongMIT(0, true, (int)entryInformationObject.AmountOfContracts125, (double)entryInformationObject.Exit125, $"LE125({entryInformationObject.Exit125})({timeID})", ""));
        if (entryInformationObject.AmountOfContracts100 > 0) placedOrders.Add(ExitLongMIT(0, true, (int)entryInformationObject.AmountOfContracts100, (double)entryInformationObject.ExitFull, $"LE100({entryInformationObject.ExitFull})({timeID})", ""));
        if (entryInformationObject.AmountOfContracts75 > 0) placedOrders.Add(ExitLongMIT(0, true, (int)entryInformationObject.AmountOfContracts75, (double)entryInformationObject.Exit75, $"LE75({entryInformationObject.Exit75})({timeID})", ""));
        if (entryInformationObject.AmountOfContracts50 > 0) placedOrders.Add(ExitLongMIT(0, true, (int)entryInformationObject.AmountOfContracts50, (double)entryInformationObject.Midpoint, $"LE50({entryInformationObject.Midpoint})({timeID})", ""));
        if (entryInformationObject.AmountOfContracts25 > 0) placedOrders.Add(ExitLongMIT(0, true, (int)entryInformationObject.AmountOfContracts25, (double)entryInformationObject.Exit25, $"LE25({entryInformationObject.Exit25})({timeID})", ""));​
        where the placestoploss method is just a simple method confirming if we are long, short and how many contracts are on the line

        Code:
        private void PlaceStopLoss()
        {
            foreach (Cbi.Order stoplossOrder in placedOrders.FindAll(x => x == null || x.Name == "Stoploss")) placedOrders.Remove(stoplossOrder);
            if (MarketPosition.Long == Position.MarketPosition)
            {
                if (GetCurrentBid() < entryInformationObject.StoplossPrice)
                {
                    Print(string.Format("Time {0}: PRICE ALREADY BELOW 'LONG' STOP EXIT ORDERS", Time[0]));
                    ExitAllOrders();
                }
                else
                {
                    Print(string.Format("Time {0}: adjust LONG stop contracs to {1}", Time[0], Position.Quantity));
                    entryInformationObject.stoplossOrder = ExitLongStopMarket(0, true, Position.Quantity, entryInformationObject.StoplossPrice.Value, "Stoploss", "");
                    placedOrders.Add(entryInformationObject.stoplossOrder);
                }
            }
            else if (MarketPosition.Short == Position.MarketPosition)
            {
                if (GetCurrentAsk() > entryInformationObject.StoplossPrice.Value)
                {
                    Print(string.Format("Time {0}: PRICE ALREADY BELOW 'SHORT' STOP EXIT ORDERS", Time[0]));
                    ExitAllOrders();
                }
                else
                {
                    Print(string.Format("Time {0}: adjust SHORT stop contracs to {1}", Time[0], Position.Quantity));
                    entryInformationObject.stoplossOrder = ExitShortStopMarket(0, true, Position.Quantity, entryInformationObject.StoplossPrice.Value, "Stoploss", "");
                    placedOrders.Add(entryInformationObject.stoplossOrder);
                }
        
            }
            else
            {
                Print(string.Format("Time {0}: we are flat and doing nothing", Time[0]));
            }
        }​
        As seen in the code, we are using unmanaged MIT orders which are not linked to an entry order. Meaning it should not show the message 'Cancelled pending exit order, since associated position is closed'.

        In my other strategies I do not have this issue even though I use the same approach.

        Hopefully you could set me into the right direction (maybe some api section I have not yet read) to see to which these exitMIT orders are linked to so I can debug it further and figure out what is happening.

        Kind regards, Jelle

        Comment


          #5
          Hello mw_futures,

          "Currently I already use the unmanaged approach."

          The unmanaged approach uses SubmitOrderUnmanaged() for all order submissions.
          Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


          If you have ExitLongMIT() and ExitShortStopMarket() in the code, this is the managed approach, not the unmanaged approach.

          Any Exit method attaches to a specific entry when using the managed approach.

          "As seen in the code, we are using unmanaged MIT orders which are not linked to an entry order."

          I am not seeing SubmitOrderUnmanaged() in your code.

          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hey NinjaTrader_ChelseaB ,

            I just did some reading in the API and I see what I have missed.
            I will make some code modifications and get back to you!

            I indeed made the mistake of not using the correct method.
            Thanks for pointing it out! Sometimes through the trees you do not see the forest.

            Kind regards, Jelle

            Comment


              #7
              NinjaTrader_ChelseaB, extremely good news. Your sharp eyes of mentioning the SubmitOrderUnmanaged() indeed solved it all.
              It is working smooooooooth as butter now. Thanks a lot!

              Like I said, I think that I did not see the trees through the forest anymore. Such a stupid mistake...

              Kind regards, Jelle

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              116 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              61 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              40 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              43 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              82 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X