Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Rejected

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

    Order Rejected

    Hello support,

    I am testing strategy under using market replay. NT reported one strategy submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself. After that output lists NT cancelling all orders, Entered internal PlaceOrder(); My strategy only getting "PendingSubmit" portion for NT generated "Close"

    A few questions:
    1. Under what circumstances a market replay would reject order?
    2. My strategy did not get the chance to receive "OrderRejected" during OnOrderUpdate. Why is this so?, which bring next question
    3. How can we handle so it does not terminate?

    Thanks.

    Best Regards.
    Edward K.

    #2
    Hi Edward, could be for example an invalid StopMarket / StopLimit order your script submitted - best would be checking directly into the logs to see which caused a rejection.

    What you see is the default strategy error handling, terminating the strategy, cancelling orders and attempting to close the position if an order sees rejected status.

    To have OnOrderUpdate() seeing this event and being able to self manage this scenario in your code, you could turn this off :

    Comment


      #3
      Hello there following from this question.

      I am using EnterLongStopLimit() and EnterShortStopLimit along with SetStopLoss SetProfitTarget methods in the Intialise.

      In a faster moving market having a few instances of receiving 'OrderRejected' and cancel requests submitted and termination of the strategy which is the default handling.

      This was following error message on the order 'Buy stop or but stop limit orders can't be placed below the market'. The EnterLongStopLimit is submitted on a bar close and the CalculateOnBarCLose = true for this strategy. So what appears to be clear is the market went beyond the stop trigger price for this entry submitted.

      If i want to continue and handle this in the OnOrderUpdate(IOrder order) section :

      as long as i store the IOrder in the OnBarUpdate

      ie longorder = EnterLongStopLimit(,,,,,)

      and then in the OnOrderUpdate(Iorder order) code

      if(longorder != null && longorder == order) {

      if (order.OrderState == OrderState.Rejected)

      {

      //

      }
      }

      do i need to submit the CancelOrder or will this cancel be submitted for me?
      If i need to cancel the order i then need to check it is cancelled onOrderUpdate?

      Essentially i just want to continue and not have the strategy terminate ... if it is the case of order being rejected on this basis - at this point it is the stop loss that is rejected as the limit will not be in place so we are talking about 1 order and thus the SetStopLoss and SetProfitTarget are not affected or in play at this point.

      I am and have gone over the advanced handling notes online but just seeking some guidance on this scenario.

      thank you

      Comment


        #4
        Originally posted by soulfx View Post
        Hello there following from this question.

        I am using EnterLongStopLimit() and EnterShortStopLimit along with SetStopLoss SetProfitTarget methods in the Intialise.

        In a faster moving market having a few instances of receiving 'OrderRejected' and cancel requests submitted and termination of the strategy which is the default handling.

        This was following error message on the order 'Buy stop or but stop limit orders can't be placed below the market'. The EnterLongStopLimit is submitted on a bar close and the CalculateOnBarCLose = true for this strategy. So what appears to be clear is the market went beyond the stop trigger price for this entry submitted.

        If i want to continue and handle this in the OnOrderUpdate(IOrder order) section :

        as long as i store the IOrder in the OnBarUpdate

        ie longorder = EnterLongStopLimit(,,,,,)

        and then in the OnOrderUpdate(Iorder order) code

        if(longorder != null && longorder == order) {

        if (order.OrderState == OrderState.Rejected)

        {

        //

        }
        }

        do i need to submit the CancelOrder or will this cancel be submitted for me?
        If i need to cancel the order i then need to check it is cancelled onOrderUpdate?

        Essentially i just want to continue and not have the strategy terminate ... if it is the case of order being rejected on this basis - at this point it is the stop loss that is rejected as the limit will not be in place so we are talking about 1 order and thus the SetStopLoss and SetProfitTarget are not affected or in play at this point.

        I am and have gone over the advanced handling notes online but just seeking some guidance on this scenario.

        thank you
        Take a gander at this thread that asks essentially the same question.



        You might want to follow that same idea.

        Comment


          #5
          Hello just to follow on from this the order is submitted on bar close at a price level which normally IS away from the current market price. I am wondering if to avoid the below order management additional complexity or coding if a simple check to GetCurrentBid() or GetCurrentAsk() would suffice as a check. This is for the CL market which is faster market and thus less liquid and in testing this on most occassions the order submission is fine and have a setting on the offset to enter at which can be adjusted over time / testing and optimisation in different market conditions. But thought i would add this to the below on better order entry/management practice on checking the current market price. thanks

          Comment


            #6
            Hello soulfx,

            koganam has provided a good link here.

            Yes, checking that your buy stop limit orders new stop price is greater than the current ask price just before the order is submitted should prevent most orders from receiving an error. In a really really fast moving market you will want to increase the distance from the ask price to prevent any slippage from causing the order to be rejected.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              thanks Chelsea and Koganam i like this approach nice and clean without unyieldy need for order state management code thanks

              Comment


                #8
                Following from my reply and testing adding Limit orders where BuyStop and BuyStopLimits for example are below market price ; there has been a few instances in CL for example where market moves very fast and market price is already above the levels set. Note i am using NON time based bar type for this strategy.

                The below code snippet as in the help section :

                protected override void Initialize()
                {
                RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
                }

                private IOrder stopLossOrder = null;

                protected override void OnBarUpdate()
                {
                if (entryOrder == null && Close[0] > Open[0])
                EnterLong();

                if (stopLossOrder == null)
                stopLossOrder = ExitLongStop(Position.AvgPrice - 10 * TickSize);
                }

                protected override void OnOrderUpdate(IOrder order)
                {
                if (stopLossOrder != null && stopLossOrder == order)
                {
                // Rejection handling
                if (order.OrderState == OrderState.Rejected)
                {
                // Stop loss order was rejected !!!!
                // Do something about it here
                }
                }
                }

                With the above TakeNoAction setting i want to confirm that with the order flow logic in the code that
                it will be either the buylimitstop or buylimit that is rejected and thus there will be no fill and no pending orders to cancel. I just want the strategy to continue and not terminate for orders rejected in these instances. Is there other codes or specific states i additionally need to test for?

                Also coding for the above does not change the behaviour when actually disabling a strategy? ie the ontermination() code i have to close open positions is processed and the exit and pending orders if any are cancelled as per the settings in tool options strategies?

                If not clear on what asking please advise

                thanks

                Comment


                  #9
                  Hi soulfx,

                  Your understanding is correct.

                  RealtimeErrorHandling.TakeNoAction will prevent the script from disabling. The rejected state is detectable in OnOrderUpdate().
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hi soulfx,

                    Your understanding is correct.

                    RealtimeErrorHandling.TakeNoAction will prevent the script from disabling. The rejected state is detectable in OnOrderUpdate().
                    Hello that is not what i stated below. I want to be able to disable the strategy ??? how else to exit? The question was if i disable with normal processiing that ninja would handle cancels of pending or exit orders as per tools strategies settings ?

                    Is there a better more thorough example ofo this somewhere?

                    Comment


                      #11
                      Hi soulfx,

                      I was responding to the following:

                      With the above TakeNoAction setting i want to confirm that with the order flow logic in the code that
                      it will be either the buylimitstop or buylimit that is rejected and thus there will be no fill and no pending orders to cancel. I just want the strategy to continue and not terminate for orders rejected in these instances. Is there other codes or specific states i additionally need to test for?
                      With this, TakeNoAction will prevent the strategy from being disabled (no the order will not be filled because it will be rejected. A rejected order is an order that was not filled and was returned with an error message about the rejection)

                      You can test for the rejected state in OnBarUpdate(). (order.OrderState == OrderState.Rejected)
                      http://www.ninjatrader.com/support/h...nt7/iorder.htm

                      Have I misunderstood your question?


                      Adding RealtimeErrorHandling.TakeNoAction will change the behavior of the script as the script will no longer disable when a rejected order is detected.
                      However, your logic will continue as written.

                      You last question seems unrelated. OnTermination() will continue run if the strategy is disabled. If you have code in this it will still be triggered.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hi soulfx,

                        I was responding to the following:



                        With this, TakeNoAction will prevent the strategy from being disabled (no the order will not be filled because it will be rejected. A rejected order is an order that was not filled and was returned with an error message about the rejection)

                        You can test for the rejected state in OnBarUpdate(). (order.OrderState == OrderState.Rejected)


                        Have I misunderstood your question?


                        Adding RealtimeErrorHandling.TakeNoAction will change the behavior of the script as the script will no longer disable when a rejected order is detected.
                        However, your logic will continue as written.

                        You last question seems unrelated. OnTermination() will continue run if the strategy is disabled. If you have code in this it will still be triggered.
                        Hello thanks for the clarification. I was confused and wanted to make sure that strategy could still be disabled and would follow the standard disable processing.
                        Yes i understand the rejection processing for the setting TakeNoAction which defines the behaviour for Rejected state for orders. i just wanted to make the distinction for that in adding the code to handle this and the standard disable a strategy process.

                        And yes OnTermination was a bit unrelated but wanted to ensure this is still invoked which i understand it is

                        thanks

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        633 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        364 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        105 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        567 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        568 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X