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

Order rejected

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

    Order rejected

    Hi, I'm getting this error :
    26/02/2021 21:30:49 Default Strategy 'KingShark1/225841965' submitted an order that generated the following error 'Order rejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    I'm using stop limit orders like : EnterLongStopLimit(LongEntryPrice, LongEntryPrice-TickSize, "Long Entry");
    and using :
    SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);

    for my profit target and stoploss

    How do I solve this issue?, could it be as a result of the market moving too fast, this issue occurs mostly during US market open on NQ

    I'm also getting this error message :
    26/02/2021 22:54:20 Order Playback101, Sell stop or sell stop limit orders can't be placed above the market. affected Order: SellShort 1 StopLimit @ 13335 x 13334.75
    Last edited by inheritag; 02-26-2021, 09:55 PM.

    #2
    Hello inheritag,

    May I confirm you are using the latest release 8.0.23.2? (Help > About)

    With the error:
    "Sell stop or sell stop limit orders can't be placed above the market."

    This means that sell stop orders, like a stop loss, cannot be submitted with a price above the current bid (GetCurrentBid()).

    We see the price is submitted with a stop limit at 13334.75, we need to know what the current bid was at that time to ensure this was greater than the sell stop.

    Print() can be used to output information to understand what is happening with a strategy.


    Use print to print the time and the value of GetCurrentBid(), one line above where the order methods are called.

    Save the output to a text file and include this with your reply and I would be happy to analyze the output.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, thank you so much was able to fix it by using:
      if (GetCurrentBid() > (ShortEntryPrice)) {
      EnterShortStopLimit(0,true, Contracts, ShortEntryPrice, ShortEntryPrice+TickSize, "Short Entry");
      }

      Comment


        #4
        Hi NinjaTrader_ChelseaB is it possible for me to send you my code to review my order placements??, entry orders are placed fine but I'm getting: Stop price can't be changed below the market, might be because I'm trying to move my stop to break-even??

        Comment


          #5
          Hello inheritag,

          This is something that you will have to review with debugging prints on your end.

          Please test to reproduce the issue, and include prints where the order is submitted/modified. With Managed Approach orders, if you call the order method again with a different price level, the order will be moved to that price level.

          When adding prints, you will want to check the price used for the order submission and you will also want to print out GetCurrentAsk/GetCurrentBid. Buy stops must be above the ask and sell stops must be below the bid.

          Please also note that with high volatility, and more commonly when orders leave NinjaTrader and need to be received and processed by the broker and exchange, the market may move fast enough to where the stop price is changed to a valid level, but that level is no longer valid when the order change was received. Increasing the distance can help if the market is close to this order, or you may consider using RealtimeErrorHanding to handle the order error so you can ignore the order error, or take a different action. More information on RealtimeErrorHandling is included below.

          RealtimeErrorHandling

          To prevent the strategy from being deactivated when an order error occurs, you can set the strategy's RealtimeErrorHandling property to IgnoreAllErrors. StopCancelCloseIgnoreRejects will keep the strategy running for rejections but not for other order errors like a failure to change an order. With this property set, you can then trap order errors in OnOrderUpdate if you would like to have the strategy attempt a different action.

          Please note that this is reserved for advanced uses that want to implement their own order error handling. Neglecting to handle an order error when having RealtimeErrorHandling set to IgnoreAllErrors or StopCancelCloseIgnoreRejects can result in damages to your account. ALWAYS monitor your automated trading strategies.

          RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm

          OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment


            #6
            Sorry to revive an old thread, but does RealtimeErrorHandling work when stops and targets are handled by an atm template? Or does it require that stops and targets are handled directly by the strategy script?

            Comment


              #7
              Hello OldHatNoobCoder,

              Welcome to the NinjaTrader forums!

              Using Atm Strategy methods do not effect a NinjaScript's position or order methods and will not effect the RealtimeErrorHandling.

              Think of these orders as having been manually submitted outside of the strategy.

              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks!!

                To clarify…if my strategy uses an atm template to place trades, and the stop from that atm gets rejected, can I use RealTimeErrorHandling to catch that rejection, ignore it to keep the strategy running, while closing the position?

                like so:
                Code:
                protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
                                                                OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                        {
                            if (order.Name == "STOP1" && orderState == OrderState.Filled)
                                stopLossOrder = order;
                
                            if (stopLossOrder != null && stopLossOrder == order)
                            {
                                if (order.OrderState == OrderState.Rejected)
                                {
                                    // Stop loss order was rejected !!!!
                                    // Do something about it here
                                    // Immediately exit the position
                                    AtmStrategyClose(atmStrategyId);​

                Comment


                  #9
                  Hello OldHatNoobCoder,

                  The order rejection would not disable the script as the order would not affect the strategy position.

                  Further, when using Atm Strategy methods order methods like OnOrderUpdate() and OnExecutionUpdate() are not going to trigger.

                  Instead, you will need to check the state the order with GetAtmStrategyEntryOrderStatus() / GetAtmStrategyStopTargetOrderStatus() on each bar update.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hmm, ok, thanks. I ended up here because

                    GetAtmStrategyEntryOrderStatus() / GetAtmStrategyStopTargetOrderStatus()

                    was one of the first things I tried, and it didn’t work. I’ve tried dozens of other things sense then. All I want is for the position to be flattened if there’s a position but no stop order or target order anymore. But when the reject hits, both get canceled and then the strategy says it’s flat, when it isn’t.

                    Comment


                      #11
                      Hello OldHatNoobCoder,

                      The Strategy position is flat because the orders do not affect the strategy position. These orders are submitted directly to the account as if they are manual orders. Atm Strategy methods do not affect the NinjaScript Strategy. This is stated in the help guide I linked in post # 7.

                      "was one of the first things I tried, and it didn’t work"
                      Specifically, what didn't work?

                      Are you printing the status array on each bar update and watching the orders on the Orders tab of the Control Center?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Specifically, what didn't work?
                        I honestly don't know. It sounds like I'm trying to do something that can't be done.

                        I guess I am confused by the ninjascript output, which does seem to show that the orders affect the strategy. Strategy market position is long after the entry gets filled, then flat again after stopped out. It also says flat, once the stop & target orders are cancelled. Am I misinterpreting this?

                        Click image for larger version

Name:	image.png
Views:	883
Size:	7.5 KB
ID:	1250247
                        Based on what you're saying, it doesn't sound like there's a way (when using an ATM Strategy) to check whether or not there 1) is a position AND 2) there is no longer a stop order or target order, and if so, close the position. Is that correct?

                        If not, I need to stop bothering with ATM Strategy in scripts and learn to control all orders from the script. Which, sounds like the best way all around, yes?​

                        Yes, I'm watching the orders on the Orders tab of the control center.

                        Comment


                          #13
                          Hello OldHatNoobCoder,

                          The account position (atm strategy position) is what is reflected with GetAtmStrategyMarketPosition() and is what is being changed.


                          This different than the NinjaScript Strategy Position which is not affected.


                          If you are using GetAtmStrategyMarketPosition() and not the Position.MarketPosition this would be accurate.


                          Order methods like OnOrderUpdate() and OnExecutionUpdate() are not going to run. So you wouldn't put any code in those methods.


                          But specifically your inquiry was about the RealtimeErrorHandling which is not going to have any effect because the NinjaScript Strategy does not have any positions or orders that would have an error that would cause cause the strategy to be disabled. So the NinjaScript Strategy is always going to keep running even if the Atm Strategy has rejections.
                          The Atm Strategy methods do not effect the NinjaScript Strategy that is calling those methods and orders will not update the order methods because the NinjaScript strategy does not have any orders.

                          If you are wanting to use OnOrderUpdate(), OnExecutionUpdate(), RealtimeErrorHandling, and the NinjaScript Strategy's position, you will need to stop using Atm Strategy methods and use native NinjaScript Strategy order methods like EnterLong() or SubmitOrderUnmanaged.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you. I appreciate your patience and helping me.

                            Early on, I tried the most simple thing I could think of. That was using Position.MarketPosition

                            I placed this under OnBarUpdate():

                            Code:
                            if (Position.MarketPosition != MarketPosition.Flat)
                                        {
                                            bool stopOrderExists = false;
                            
                                            foreach (Order order in Orders)
                                            {
                                                if (order.OrderState == OrderState.Working && order.OrderType == OrderType.StopMarket)
                                                {
                                                    stopOrderExists = true;
                                                    break;
                                                }
                                            }
                            
                                            if (!stopOrderExists)
                                            {
                                                ExitLong("Exit");​
                            This should (I thought) close the position if it is open and there isn't a stop. But nothing happens when the stop is cancelled or rejected. Is this just wrong?

                            Comment


                              #15
                              You can't (or shouldn't) mix and match between these managed order methods like ExitLong() and ATM strategy methods - at least not at the same time or in the same trade. You need to settle on one or the other approach.
                              Bruce DeVault
                              QuantKey Trading Vendor Services
                              NinjaTrader Ecosystem Vendor - QuantKey

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by r68cervera, Today, 05:29 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post r68cervera  
                              Started by geddyisodin, Today, 05:20 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post geddyisodin  
                              Started by JonesJoker, 04-22-2024, 12:23 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post JonesJoker  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              12 responses
                              3,239 views
                              0 likes
                              Last Post Leafcutter  
                              Started by AveryFlynn, Today, 04:57 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post AveryFlynn  
                              Working...
                              X