Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged OCO group reset

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

    Unmanaged OCO group reset

    I am running some tests with unmanaged orders, when I close the position manually the OCO stop loss and profit target orders cancel as expected. When re-running the strategy I get the following message:
    5/6/2021 4:50:31 Order Sim101, Order 'fdd6c7f2104249fa8b59a17d4bbcf518' can't be submitted: The OCO ID ‘ocoO14’ cannot be reused. Please use a new OCO ID. affected Order: BuyToCover 1 Limit @ 3976
    I have this code in play - so not sure why the OCO group is not being reset.

    //Reset our stop order and target orders' Order objects after our position is closed.
    if ((myStopOrderSHORT != null && myStopOrderSHORT == execution.Order) || (myTargetOrderSHORT != null && myTargetOrderSHORT == execution.Order))
    {
    if (execution.Order.OrderState == OrderState.Filled
    || execution.Order.OrderState == OrderState.PartFilled)
    {
    myStopOrderSHORT = null;
    myTargetOrderSHORT = null;
    }
    }


    Simple answer no doubt. Ideas?


    #2
    Hello elliot5,

    The error is noting that you used the same string for the OCO id, you need to use a unique ID for every OCO. You can find an example of generating unique OCO strings in the following post: https://ninjatrader.com/support/foru...579#post770579


    I look forward to being of further assistance.

    Comment


      #3
      Thx - when are the used oco strings deleted? only on restart of the strategy? i use alot of individual orders and would ideally like to be able to clear the used oco`s every day or even better immediately. Producing the unique oco`s is not the problem - the problem is that the same trade the next day might need to use them again. My entry orders are sent in groups of small sizes, each with a unique oco.
      Last edited by elliot5; 05-06-2021, 10:43 AM.

      Comment


        #4
        Hello elliot5,

        The OCO's are tied to the orders, it would not be expected for an OCO order to ever reuse an OCO id after it had been used. There is no means to clear the used ID's as they are tied to the past orders.

        If the same trade on the next day occurs you would just need to make a new OCO at that time for that new orders.

        OCO ids are not intended to be a way of naming the OCO, its an id that links the two orders so one cancels others. The unique aspect of that is a requirement for OCO's to work correctly and target the right other orders when need to cancel them occurs.

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

        Comment


          #5
          Found the solution.- GetATMStrategyUniqueID() works wonders with creating oco ids for multiple entries. Thanks for the assistance. Regards to all.
          Last edited by elliot5; 05-07-2021, 05:35 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          43 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 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