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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      216 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      130 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      147 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      230 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      192 views
      0 likes
      Last Post CarlTrading  
      Working...
      X