Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO ID reused

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

    OCO ID reused

    Hello,

    when trading from a script strategy there appears now the message
    14.04.2020 11:31:32 Order Sim101, Order '89f008c6c8d24746a47905174e834e64' can't be submitted: The OCO ID ‘d1c26a88cde7457ea49fecb07d1e7782’ cannot be reused. Please use a new OCO ID. affected Order: Sell 1 Limit @ 21,11
    I have never had this before in 10 years from a script strategy. Why does this occur please?

    Thank you!
    Tony

    #2
    Hello Tony,

    Thanks for your message.

    This happened with a limit order that is OCO'd. This likely was seen with a strategy using SetStopLoss/SetProfitTarget as these orders will be OCO paired. This can also be seen with Atm strategies.

    NinjaTrader submits the stop, and then the target. The stop gets a rejection, and the OCO becomes invalid. The profit target then gets rejected with the error you noted because its OCO paired order is already filled/cancelled/rejected.

    To prevent the strategy from being deactivated, you can set the strategy's RealtimeErrorHandling property to IgnoreAllErrors or StopCancelCloseIgnoreRejects. With this property set, you can then trap order rejections in OnOrderUpdate if you would like to have the strategy attempt a different action. For example, you could call ExitLong() to exit the position, or you could use ExitLongStopMarket/ExitLongLimit to place other protective orders.

    RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm

    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

    Please let us know if you have any questions.

    Comment


      #3
      You can also find another solution here: https://ninjatrader.com/support/foru...ort-aa/1101528

      Comment


        #4
        Chelsea's got a sample with ocostring

        Comment


          #5
          i'm not using any scripts that i know of, just the atm strategies

          if i'm getting this oco id cannot be reused... what do i do if if there is no code to change?

          thank you for the help

          Comment


            #6
            Hello whats1thingnow,

            Thanks for your note.

            What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 7.0.1000.? or 8.0.?.?)

            Are you using NinjaTrader Desktop or NinjaTrader Web when this error occurs?​

            To clarify, are you running a NinjaScript strategy that uses Atm Strategy Methods?

            Or, are you manually submitting orders with Chart Trader or the SuperDOM and using Atm Strategy Templates seen in the Chart Trader window/SuperDOM window?

            I look forward to assisting further.
            <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


              #7
              NinjaTrader_BrandonH I get this order rejection sometimes when using an ATM strategy with Markers Plus executing orders. Is there anything that can be done to at least handle the orders automatically in that case?

              Comment


                #8
                Hello tradgrad,

                Thanks for your notes.

                If this behavior is in regard to using ATM Strategies with the third-party Markers Plus addon, please contact the developer of the addon directly so that they may look into what in their addon could be causing the behavior to occur. Or, so they may provide direction on how to properly use their third-party addon.

                If you try to submit ATM Strategy templates without using the Markers Plus addon, does the behavior persist?

                I look forward to assisting further.
                <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
                  NinjaTrader_BrandonH Thanks for the reply. I'm fairly certain this is not an "error" with Markers Plus that they could or would need to address. I'm pretty sure it's simply the result of fast market movement. When I get this "OCO ID ‘##’ cannot be reused. Please use a new OCO ID" error, it comes in tandem with a "Rejected: Buy[/Sell] stop or Buy[/Sell] stop limit orders can't be placed below[/above] the market" error.

                  So I suppose what is happening is the original order is filled and price moves out of range of the ATM TP/STP before those bracket orders can be placed, so that when they are attempted, the STP is rejected for being above/below the market, and the TP is rejected with the "OCO ID cannot be reused" response, basically as NinjaTrader_Jim described in the second post.

                  This is a rare occurrence, but it does happen in backtesting.
                  I'm only really concerned with how to prevent this from leaving a naked (i.e. unbracketed) order open.

                  I see that NTJim mentioned a couple of methods for doing this with error handling within NT Strategies, but in my case, I'm not running any Strategies.
                  Is there some way to have NT immediately close an order when the brackets get rejected anyway?

                  Comment


                    #10
                    Hello tradgrad,

                    Thanks for your notes.

                    "So I suppose what is happening is the original order is filled and price moves out of range of the ATM TP/STP before those bracket orders can be placed, so that when they are attempted, the STP is rejected for being above/below the market, and the TP is rejected with the "OCO ID cannot be reused"

                    If this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this could occur.

                    Are you able to reproduce the behavior when testing it on the Playback connection?

                    Playback: https://ninjatrader.com/support/help...connection.htm

                    If so, please let me know the exact steps and settings you used to reproduce the behavior so that I may try to reproduce it on my end.

                    Also, so that I may confirm if this is the case, please send us your log and trace files to support[AT]ninjatrader.com so we may investigate this further. In the subject of your email include ATTN: Brandon H and in the body of the email include a link to this forum post.

                    Follow the steps below to manually attach your log and trace files to your response so I may investigate this matter further.
                    • Open your NinjaTrader folder under, "Documents" (sometimes called, "My Documents")
                    • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
                    • Send the 2 compressed folders as attachments to this email.
                    • Once complete, you can delete these compressed folders.
                    I look forward to assisting further.​
                    <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


                      #11
                      NinjaTrader_BrandonH Yes, the backtesting I was referring to is Playback connection. Unfortunately it involves proprietary indicators, so you wouldn't necessarily be able to reproduce on your end.

                      I'm aware that there wouldn't be a way to prevent this kind of thing from occurring. My question was, NTJim mentioned a couple of methods for automatically dealing with this when it does occur by using error handling within NT Strategies...but in my case, I'm not running any Strategies. So is there some way to have NT immediately close an order when the brackets get rejected even though I'm not using NT Strategies?

                      Comment


                        #12
                        Hello tradgrad,

                        Thanks for your note.

                        RealtimeErrorHandling could be used to handle this within NinjaScript strategies as you have mentioned.

                        If you are not using a NinjaScript strategy then there are no features available in NinjaTrader to immediately close an order when the ATM Strategy stop loss/profit target returns rejected. You may consider selecting the 'Close' button in Chart Trader or on the SuperDOM window to close the order when you see an ATM Strategy stop loss/profit target returns rejected. Or, you could right-click on the position in the Positions tab of the Control Center and select 'Close position'.

                        Please let me know if I may assist further.
                        <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


                          #13
                          NinjaTrader_BrandonH so the RealtimeErrorHandling can only be used if the rejection is the result of a trade initiated by a Strategy? Is it possible to create a Strategy that would simply close trades when the bracket orders are rejected so that the trade isn't left open without the brackets?

                          Comment


                            #14
                            Hello tradgrad,

                            Thanks for your note.

                            That is correct. RealtimeErrorHandling can only be used in a NinjaScript strategy if the orders are being submitted by that strategy.

                            The strategy must submit the orders that are returning rejected to use RealtimeErrorHandling to manage order rejections that occur.

                            You could program the strategy to submit entry orders with Atm Strategy templates attached and if the script submits an order that returns rejected, you could use RealtimeErrorHandling to handle the rejected order.

                            Atm Strategy Methods would need to be used in an unlocked NinjaScript strategy. An example of AtmStrategy Methods could be seen by opening a New > NinjaScript Editor window, opening the Strategies tab, and double-clicking on the SampleAtmStrategy file.

                            Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm
                            Using Atm Strategies: https://ninjatrader.com/support/help...strategies.htm

                            Below is a link to a forum post with helpful information about getting started with NinjaScript.
                            https://ninjatrader.com/support/foru...040#post786040

                            Here is a link to our publicly available training video, 'NinjaScript Editor 401', for you to view at your own convenience.

                            NinjaScript Editor 401: https://youtu.be/H7aDpWoWUQs?list=PL...We0Nf&index=14

                            Please see the example in the help guide link below that demonstrates using RealtimeErrorHandling and trapping a rejected order in OnOrderUpdate().

                            RealtimeErrorHandling: https://ninjatrader.com/es/support/h...orhandling.htm
                            OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.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


                              #15
                              NinjaTrader_BrandonH what if I used the OnOrderUpdate() method?

                              Wouldn't something like this be able to check for order rejections and flatten any open positions in response, regardless of whether the orders were placed by a NinjaScript strategy or manually entered through the platform?

                              Code:
                              protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
                              {
                                  if (orderState == OrderState.Rejected)
                                  {
                                      // Get the parent order (the bracket order)
                                      Order parentOrder = null;
                                      if (order.Parent != null)
                                      {
                                          parentOrder = order.Parent;
                                      }
                                      else if (order.BracketParent != null)
                                      {
                                          parentOrder = order.BracketParent;
                                      }
                              
                                      // If the parent order is a limit or stop order
                                      if (parentOrder != null && (parentOrder.OrderType == OrderType.Limit || parentOrder.OrderType == OrderType.Stop))
                                      {
                                          // Get the associated bracket orders
                                          Order stopLossOrder = parentOrder.StopLossOrder;
                                          Order profitTargetOrder = parentOrder.ProfitTargetOrder;
                              
                                          // If the rejected order is the stop loss or profit target order
                                          if (order == stopLossOrder || order == profitTargetOrder)
                                          {
                                              // Get the open orders that are associated with the parent order
                                              List<Order> openOrders = new List<Order>();
                                              foreach (var o in Account.GetOrders())
                                              {
                                                  if (o.Parent == parentOrder || o.BracketParent == parentOrder)
                                                  {
                                                      openOrders.Add(o);
                                                  }
                                              }
                              
                                              // If there is only one open order (i.e., the naked order)
                                              if (openOrders.Count == 1)
                                              {
                                                  // Close the open order
                                                  ExitOrder(openOrders[0]);
                                              }
                                          }
                                      }
                                  }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              62 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              134 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              75 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              50 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X