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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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 aa731, Today, 02:54 AM
          0 responses
          4 views
          0 likes
          Last Post aa731
          by aa731
           
          Started by thanajo, 05-04-2021, 02:11 AM
          3 responses
          470 views
          0 likes
          Last Post tradingnasdaqprueba  
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          10 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,237 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          6 views
          0 likes
          Last Post thread
          by thread
           
          Working...
          X