Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged bracket orders and IB TWS work around

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

    Unmanaged bracket orders and IB TWS work around

    I've come across a baffling problem when submitting unmanaged OCA orders to TWS, and here is the work around to save you time, if you come across it too:

    The problem:

    When the strat submits the first OCA order to TWS, it works fine. All subsequent OCA orders are rejected by TWS, however, with the error message displayed in TWS as "Cancelled by system: OCA group already filled".

    Nothing gets written to the NT output window even when TraceOrders = true when the orders are cancelled. The strat works perefectly with a SIM account too.

    The cause:

    It finally dawned on me that I was using the same OCA string for every trade. TWS was then rejecting the orders as the OCA string was the same as the previous order which had already been filled.

    The solution:

    Give each OCA bracket order a unique string. I use CurrentBar, as long as the OCA trade is initiated in the same bar. It works perfectly.

    Code:
    if ( longOrder == null )
         longOrder        = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, 1, High[1] + 2 * TickSize, High[1] + TickSize, "Entry" + CurrentBar.ToString(), "Long Limit");
    
    if ( shortOrder == null )
     shortOrder        = SubmitOrder(0, OrderAction.SellShort, OrderType.StopLimit, 1, Low[1] - 2 * TickSize, Low[1] - TickSize, "Entry" + CurrentBar.ToString(), "Short Limit");
    Chris
    Ninjascript Consultant

    #2
    Thanks for sharing your findings Chris.

    Comment


      #3
      Chris, as I was testing this scenario - you can check the IOrder native error returned in OnOrderUpdate() that would show you this error (which also would 'sit' in your log file / log tab).

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      597 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      555 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X