Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

OCO ID cannot bre reused. Please use a new OCO ID.

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

    OCO ID cannot bre reused. Please use a new OCO ID.

    I'm getting this error on all of my strategies. Is this related to a string issue? All of my system submit an initial stop and profit target via onexecutionupdate once an order is filled. Then I use addition exit rules that are implemented via onbarupdate. Is this the problem? If I'm going to profit using a a trigger that occurs via onbarupdate do i need to not use a profit target sent out via onexecutionupdate? When both the stop and profit target go out simultaneously after a fill via onexecutionupdate and then another market order goes out to exit a position with both of those orders still live will that cause a strategy to crash? I need to solve this problem today. I've seen this issue posted all over the forums and everyone just asks for the log and trace files but there must be 1 or more common causes since this is a frequent issue.

    #2
    Hello gordongekko,

    Thank you for your post.

    Each OCO ID will need to be unique, so you would add something to each submitted instance of the protective orders that is unique like CurrentBar. For example:
    Code:
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1, 0, Position.AveragePrice - 4 * TickSize,[B] "OCO: " + CurrentBar[/B], "Exit Long Stop Loss");
    Please let me know if you have any questions.

    Comment


      #3
      So in other words, if you don't do that it will keep using the same order id in the string and thus crash when on the second trigger after running it? Also if i submit stop and profit target orders immediately after a fill be preloading them into onstatechange or via onexecutionupdate and then I send a 3rd order to exit an existing position via the onbarupdate method do i need to cancel the oco stop and target orders first?
      Last edited by gordongekko; 02-05-2018, 05:50 PM.

      Comment


        #4
        Hello gordongekko,

        Thank you for your response.

        If the OCO ID is not unique per order set then it will reject the orders with the same OCO ID that was already used for an order that was submitted.

        If you close the position with another order you will need to cancel the other orders.

        Please let me know if I may be of further assistance.

        Comment


          #5
          Is it possible to use the managed approach and assign an initial profit target and stop loss based on variables obtained via the on bar update method and used to send out price based stops via onexecuationupdate once an order has been filled via a trigger generated from onbarupdate and still have additional exit options that use onbarupdate? This is what I'm trying to do and probably why i keep running into these oco order error messages.

          I created a very simple demo system using the order logic I want to use for my actual strategies. Can you check this to make sure I didn't mess up any syntax with the strings, order ids, or other syntax.

          This code compiles but i'm still get duplicate order id errors and im assuming its do to the additional exit option in the onbarupdate method. Here is the demo strategy full code:



          ************************************************** *******************************


          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.Indicators;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion

          //This namespace holds Strategies in this folder and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Strategies
          {
          public class LINECROSS3EXITDEMO : Strategy
          {
          double bulltarget = 0;
          double beartarget = 0;
          double bullstop = 0;
          double bearstop = 0;
          private MACD MACD1;


          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Enter the description for your new custom Strategy here.";
          Name = "LINE CROSS 3 EXIT DEMO";
          Calculate = Calculate.OnBarClose;
          EntriesPerDirection = 1;
          EntryHandling = EntryHandling.AllEntries;
          IsExitOnSessionCloseStrategy = true;
          ExitOnSessionCloseSeconds = 30;
          IsFillLimitOnTouch = false;
          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
          OrderFillResolution = OrderFillResolution.Standard;
          Slippage = 0;
          StartBehavior = StartBehavior.WaitUntilFlat;
          TimeInForce = TimeInForce.Gtc;
          TraceOrders = false;
          RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
          StopTargetHandling = StopTargetHandling.PerEntryExecution;
          BarsRequiredToTrade = 50;
          // Disable this property for performance gains in Strategy Analyzer optimizations
          // See the Help Guide for additional information
          IsInstantiatedOnEachOptimizationIteration = true;

          }
          else if (State == State.Configure)
          {

          }
          else if (State == State.DataLoaded)
          {
          MACD1 = MACD(Close, 12, 26, 9);
          }
          }

          protected override void OnBarUpdate()
          {
          if (CurrentBars[0] < BarsRequiredToTrade)
          return;


          if (CrossAbove(MACD1.Avg, 0, 1))
          {
          bullstop = MIN(Low, 5)[0] -2*TickSize;
          bulltarget = MAX(High, 20)[0];
          EnterLong(Convert.ToInt32(DefaultQuantity), @"BULL TRIGGER");
          }


          if (CrossBelow(MACD1.Avg, 0, 1))
          {
          bearstop = MAX(High, 5)[0] +2*TickSize;
          beartarget = MIN(Low, 20)[0];
          EnterShort(Convert.ToInt32(DefaultQuantity), @"BEAR TRIGGER");
          }



          // ADDITIONAL EXIT OPTIONS VIA ON BAR UPDATE IN ADDITION TO THE TARGET AND STOPS ASSIGNED VIA ONEXECUTIONUPDATE //


          if(Close[0] < Low[1] && Position.MarketPosition == MarketPosition.Long)
          {
          ExitLong(DefaultQuantity,"BULL TRIGGER EXT","BULL TRIGGER"); // DO I HAVE TO CANCEL THE CURRENT PROFIT TARGET AND STOP (OCO ORDERS) BEFORE I SEND THIS ONE OUT?
          }
          if(Close[0] > High[1] && Position.MarketPosition == MarketPosition.Short)
          {
          ExitShort(DefaultQuantity,"BEAR TRIGGER EXIT","BEAR TRIGGER");
          }


          }


          protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
          {

          if (execution.Order.Name == "BULL TRIGGER")
          {
          SetProfitTarget(@"BULL TRIGGER", CalculationMode.Price, bulltarget);

          SetStopLoss(@"BULL TRIGGER", CalculationMode.Price, bullstop, false);
          }

          if (execution.Order.Name == "BEAR TRIGGER")
          {
          SetProfitTarget(@"BEAR TRIGGER", CalculationMode.Price, beartarget);

          SetStopLoss(@"BEAR TRIGGER", CalculationMode.Price, bearstop, false);
          }
          }


          }
          }



          ************************************************** *******************************

          Comment


            #6
            Hello gordongekko,

            Thank you for your response.

            The code you provided appears to be correct. Are you stating this code is generating the OCO ID errors?

            You would need to move the Stop Loss instead of using the Exit method. So you would not cancel the SetStopLoss or SetProfitTarget but you would re-submit the Stop Loss at a new level. Per our Order Handling rules for Managed Approach the Exit method would be ignored: https://ninjatrader.com/support/help...antedPositions

            I look forward to your response.

            Comment


              #7
              I'm still getting this OCO id can't be reused error. I'm using the managed approach for my entries (via onbarupdate) and my exits(stop orders placed via onexecutionupdate). Again, I'm using the managed approach and thus according to the documentation should not need to create a unique order id like you do when using using unmanaged orders. This is wasting a huge amount of time and I need an actual solution to this problem. My strategy works as intended except for 2 errors.

              1. the stop mit (placed above the current market price) shows up as a stop limit order which is not what the code is submitting.

              2. Usually within the first 5 completed trades the strategy will termite itself and give a duplicate oco id error.

              Can somebody please tell me how to prevent this as in give me the actual code to change whatever is causing this. This is my entry code and stop code:


              ******************************************

              ENTRY CODE VIA ONBARUPDATE

              ******************************************

              if(Position.MarketPosition == MarketPosition.Flat)
              {
              EnterLong(DefaultQuantity, @"BULL TRIGGER");
              bullStop = MIN(Low, 5)[0] -2*TickSize;
              bullTarget = MAX(High, 20)[0];
              }



              ************************************************** ***********

              EXIT ORDER(S) CODE VIA ONEXECUTIONUPDATE

              ************************************************** ***********


              protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
              {

              if (execution.Order.Name == @"BULL TRIGGER")
              {
              ExitLongStopMarket(bullStop, @"BULL TRIGGER");

              ExitLongMIT(bullTarget, @"BULL TRIGGER");

              }

              if (execution.Order.Name == @"BEAR TRIGGER")
              {
              ExitShortStopMarket(bearStop, @"BEAR TRIGGER");

              ExitShortMIT(bearTarget, @"BEAR TRIGGER");

              }

              }








              *********************************
              Last edited by gordongekko; 02-07-2018, 10:54 AM.

              Comment


                #8
                Hello gordongekko,

                Thank you for your response.

                Please send me your log and trace files so I may investigate this matter further. You can do this by going to the Control Center-> Help-> Mail to Platform Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

                Please list 'ATTN: Patrick H' in the subject line and reference this thread in the body of the email.

                I look forward to assisting you further.

                Comment


                  #9
                  I have the same error regarding OOC id

                  Hi Guys,

                  I am receiving the same OCO id error with the latest NT 8.0.12.0 build, has there been any resolution?

                  Thanks,

                  Shane.

                  Comment


                    #10
                    I don't remember the exact cause at this point. I'm currently using gtc orders for targets and stops so they don't have to be resubmitted every time on bar update is called which wasn't discussed in this thread. You should post the portion of the code containing the logic for your stop and or target orders otherwise its really difficult to determine the cause.

                    Comment


                      #11
                      Originally posted by adams29 View Post
                      Hi Guys,

                      I am receiving the same OCO id error with the latest NT 8.0.12.0 build, has there been any resolution?

                      Thanks,

                      Shane.
                      Hello Shane,

                      Thank you for your note.

                      Please send me your log and trace files so that I may look into what occurred. You can do this by going to the Control Center-> Help-> Mail to Platform Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

                      Please list 'ATTN: Patrick H' in the subject line and reference this thread in the body of the email.

                      I look forward to assisting you further.

                      Comment


                        #12
                        Has a solution been found for this? I am currently experiencing something similar when dealing with stops.

                        Comment


                          #13
                          Hello Rogue_Two,

                          Thank you for your post.

                          This is due to the re-use of an OCO ID that was used for a prior order that was submitted. The solution is to use unique OCO IDs going forward.

                          I can take a closer look into this for you if you would like to me your log and trace files.
                          You can do this by going to the Control Center-> Help-> Mail to Platform Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

                          Please list 'ATTN: Patrick H' in the subject line and reference this thread in the body the email.

                          I look forward to assisting you further.

                          Comment


                            #14
                            He NinjaTrader_PatrickH,
                            I have the same error. but I use managed approach in my strategy.
                            I've sent you an email using Help -> Email support.
                            Handlar
                            NinjaTrader Ecosystem Vendor - Handlar

                            Comment


                              #15
                              I'm having the same problem. Strategy runs for a few trades and then ID errors start showing up. Placing sl and tp in OnExcecutionUpdate(). Where can I get an aswer on this issue?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ZenCortexCLICK, Today, 04:58 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ZenCortexCLICK  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              172 responses
                              2,280 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post Irukandji  
                              Started by adeelshahzad, Today, 03:54 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post adeelshahzad  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X