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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        44 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        180 views
        0 likes
        Last Post jeronymite  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Working...
        X