Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to prevent error: Order is in a state that prohibits using it as a compound leg

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

    How to prevent error: Order is in a state that prohibits using it as a compound leg

    I am getting a runttime error: "Order is in a state that prohibits using it as a compound leg" when my strategy runs and my target fills before my stop gets placed. Is there any way in my strategy to prevent this?

    In my strategy, when an entry order is filled, I submit a stoploss order and a target order one after the other (stop first, then target):

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    ...
    stopPrice = execution.Order.AverageFillPrice - StoplossTicks*TickSize;
    exitLongStop(execution.Order.Quantity, stopPrice, STOP_LOSS_1_ORDER_NAME, oco1ExitUnique);

    targetPrice = execution.Order.AverageFillPrice + Target1Ticks*TickSize;
    exitLongTarget(execution.Order.Quantity, targetPrice, PROFIT_TARGET_1_ORDER_NAME, oco1ExitUnique);
    ...
    }

    private void exitLongStop(int posSize, double price, string name, string oco) {
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, posSize, 0.0, price, oco, name);
    }

    private void exitLongTarget(int posSize, double price, string name, string oco) {
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, posSize, price, 0.0, oco, name);
    }

    It looks like even though I submit the stop order first, the target ends up getting filled first, ie before the stop order even gets accepted. I suspect this is just due to how submitted orders can sometimes travel through the internet. Is there any way to force the stop order to get there first so this error doesn't happen?

    #2
    Hello westofpluto,

    Thank you for your post.

    It would seem unlikely a second order could fill before the first order is at least accepted - I'd like to look at your log files that show this occurring to see what may be causing it. However, since these can contain personally identifiable information, please send them to us directly from the platform.

    You can send these by going to the Control Center-> Help-> Email Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

    Please reference the following ticket number in the body of the email: 3210172 ATTN Kate W. Also, please include a link to this post in the body of the email as well.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      That's the problem. We submit the stoploss order and the target in the same place, one after the other. It is occasionally possible (it occasionally happens to me) that the target order gets accepted and filled before the stoploss gets accepted, thereby causing the problem.

      I think the solution is to only submit the stoploss, wait for the stoploss has been accepted (in OnOrderUpdate) and then submit the target.

      Comment


        #4
        Hello westofpluto,

        Thank you for your reply.

        As long as your broker isn't TD Ameritrade that ought to work, though you'll want to make sure you're not calculating the price at which to put the target until you actually submit it. TDA requires the stop and target to be sent together so that could be problematic with them. You could also consider changing the strategy to use RealTimeErrorHandling of IgnoreAllErrors, and catch the rejection and handle it however you wish (though if the target's getting filled you probably don't need it anymore), however, you'll still get a popup informing you of the rejection.

        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        88 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        151 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        80 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        53 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        62 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X