Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order X can't be submitted: The OCO ID X cannot be reused. Please use a new OCO ID

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

    Order X can't be submitted: The OCO ID X cannot be reused. Please use a new OCO ID

    Hi guys,

    I have following error during Playback/Replay which throws few Alert messages and strategy disabled after that. For sure I do not run into issue of NON-unique IDs (you can see in code).

    I tried to prepare/isolate as much as I could to help you to reproduce the issue on your side:


    Here is what I'm attaching:
    1) log file
    2) strategy code(which has minimum code to reproduce the issue)
    3) screen with settings of strategy
    4) replay file (since blog has limits to extension/sizes/number of uploads, don't know how to upload 37 MB) (\db\replay\CL 03-19\20190213.nrd)
    I uploaded it to filebin: https://filebin.net/szwvb2n29ra7jz4i
    5) screen settings of replay controller

    Please let me know if anything else I can provide to help you to reproduce this?


    PHP Code:

    using System
    .Collections.Generic;

    namespace 
    NinjaTrader.NinjaScript.Strategies
    {
        public class 
    PL1ForNTForumStrategy Strategy
        
    {
            private 
    Dictionary<intstringlongTradesDict;
            private 
    Dictionary<intstringshortTradesDict;

            protected 
    override void OnStateChange()
            {
                if (
    State == State.SetDefaults)
                {
                    
    Name "PL1ForNTForumStrategy";
                    
    Calculate Calculate.OnEachTick;
                }
                else if (
    State == State.Configure)
                {
                    
    SetStopLoss(CalculationMode.Ticks10);
                    
    SetProfitTarget(CalculationMode.Ticks10);

                    
    longTradesDict = new Dictionary<intstring>
                    {
                        { 
    1776"LONG_BID_5355_2BDZdAn+UkOj3Cm6/YhEIA" },
                        { 
    2252"LONG_BID_5332_lQPS6wRoAUuQrkP8QPG3dg" },
                    };

                    
    shortTradesDict = new Dictionary<intstring>
                    {
                        { 
    2270"SHORT_ASK_5350_Q1ykteoKSEy43CLnYjvLyw" },
                        { 
    2277"SHORT_ASK_5360_LOW5K7DwGE6636G6O/UjyQ" },
                        { 
    2278"SHORT_ASK_5362_24OJhmysJkiFaICg6sv72Q" },
                        { 
    2312"SHORT_ASK_5385_oOE3vr4zVUmHDMMXc8Iw2A" },
                        { 
    2313"SHORT_ASK_5390_r86tcxxAi0qSx7pjhKpzig" },
                        { 
    2316"SHORT_ASK_5400_z1fv93n/s0KgRVEUYMyYLg" },
                    };
                }
            }

            protected 
    override void OnBarUpdate()
            {
                if (
    longTradesDict.ContainsKey(CurrentBar))
                    
    EnterLong(longTradesDict[CurrentBar]);
                else if (
    shortTradesDict.ContainsKey(CurrentBar))
                    
    EnterShort(shortTradesDict[CurrentBar]);
            }
        }

    Attached Files
    Last edited by NinjaTrader_Jim; 05-25-2020, 09:40 AM.

    #2
    Hello login_dejavu,

    Thanks for your message.

    I suggest emailing us at platformsupport [at] ninjatrader [dot] com regarding specifics with order rejections. We will often want to see the log and trace files. While you have posted them here and I was able to check, there is some personal information that can be found from the log files which you do not want to share publicly. I have removed the log file from your post.

    The OCO error occurs on the profit target's submission. This happens because the Profit Target is OCO tied with the Stop Loss and the Stop Loss has already received a rejection. You can consider the following which occurs:
    1. Set methods prep NinjaTrader to submit target and stop when the entry order comes back as filled.
    2. The Stop loss gets submitted first and gets rejected for being submitted to the other side of the market. This can happen in regular scenarios when there is higher volatility.
    3. The Profit Target is then placed, and since the Stop Loss was already rejected and the two are tied with OCO, the ODO ID is now invalid and the Profit Target gets the mentioned rejection.

    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.

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

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

    Code:
    The example snippet below shows how a rejection can be trapped for a Stop loss order which would be submitted with SetStopLoss.
    
    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
    int quantity, int filled, double averageFillPrice,
    Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
    {
        if (order.Name == "Stop loss" && order.OrderState == OrderState.Rejected)
            ExitLong();
    }
    I look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      thanks for your response! Actually I though I cleaned the log from all sensitive, but maybe missed something... so thanks that you delete it.
      I just want to make sure that this is expected behavior.

      Thanks!
      Last edited by login_dejavu; 05-25-2020, 10:26 AM.

      Comment


        #4
        Other possible solutions:
        1) you can set `Unique` order names, which might avoid that OCO errors:
        Code:
        OnBarUpdate()
        {
            myOrder = EnterLongStopMarket(0, true, DefaultQuantity, myPrice, "MyEntry"+ CurrentBar);
        }
        
        OnExecutionUpdate(..................)
        {
             SetProfitTarget(BuyStopSignal.ToString(), CalculationMode.Price, buyProfitTarget);
             SetStopLoss(BuyStopSignal.ToString(), CalculationMode.Price, buyStopLoss, false);
        }
        2) note the NT behavior.
        Last edited by ttodua; 01-16-2022, 03:59 AM.

        Comment


          #5
          Chelsea's got a sample with ocostring

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fitspressoburnfat, Today, 04:25 AM
          0 responses
          1 view
          0 likes
          Last Post fitspressoburnfat  
          Started by Skifree, Today, 03:41 AM
          1 response
          4 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          23 views
          0 likes
          Last Post xiinteractive  
          Working...
          X