Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order rejected

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

    #31
    Hi Bruce,

    Are you meaning an example using strategy methods that uses SetStopLoss() and SetProfitTarget() to submit the stop and target?


    Are you meaning an example using the addon approach to submit a stop and target directly through the account?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #32
      Well, that second thing, but integrated into the ATM example - because it's a known situation that ATMs can get into a bind if the stop tries to move and the move is rejected. I was suggesting that the ATM example could be updated to show how to handle that.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #33
        Hello Bruce,

        You are referring to adding rejection handling logic to the SampleATMStrategy included with NinjaTrader?

        Thank you for the suggestion.

        We will take this into consideration.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #34
          The order would be submitted to the account with <Account>.CreateOrder() and <Account>.Submit().
          The problem still remains, how will the script detect that it needs to send this order?

          Comment


            #35
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello Bruce,

            You are referring to adding rejection handling logic to the SampleATMStrategy included with NinjaTrader?

            Thank you for the suggestion.

            We will take this into consideration.
            Yes, exactly. Thank you!
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #36
              Hello OldHatNoobCoder,

              You can check the stop order state is rejected with GetAtmStrategyStopTargetOrderStatus().
              Chelsea B.NinjaTrader Customer Service

              Comment


                #37
                Thanks Chelsea. I tried that one with no luck, but I could have made a mistake. I'll go back and check that revision.

                Comment


                  #38
                  Me again, thanks for your patience

                  I'm stuck here, getting error
                  name.cs No overload for method 'CreateOrder' takes 8 arguments CS1501 131 36
                  Code:
                  if (atmStrategyId.Length > 0)
                              {
                                  bool stopOrderRejected = false;
                                  string[,] stopOrders = GetAtmStrategyStopTargetOrderStatus("STOP1", atmStrategyId);
                  
                                  if (stopOrders.Length > 0)
                                  {
                                      for (int i = 0; i < stopOrders.GetLength(0); i++)
                                         {
                                      if (stopOrders[i, 2].ToString() == "Rejected")
                                      {
                                          stopOrderRejected = true;
                                          break;
                                      }
                                  }
                              }
                  
                              if (stopOrderRejected)
                              {
                                  double limitPrice = Position.AveragePrice - 10 * TickSize;
                                  Order newLimitOrder = myAccount.CreateOrder(myInstrument, OrderAction.Sell, OrderType.Limit, 0, limitPrice, 0, TimeInForce.Day, "NewLimitOrder");
                                  Account.Submit(new[] { newLimitOrder });
                              }​

                  Comment


                    #39
                    The syntax of CreateOrder is:

                    CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, OrderEntry orderEntry, TimeInForce timeInForce, int quantity, double limitPrice, double stopPrice, string oco, string name, DateTime gtd, CustomOrder customOrder)

                    As you can see, comparing this with your source above, some of your arguments are the wrong type and you are missing some others.

                    Check the documentation at https://ninjatrader.com/support/help...reateorder.htm for how to use this method.
                    Bruce DeVault
                    QuantKey Trading Vendor Services
                    NinjaTrader Ecosystem Vendor - QuantKey

                    Comment


                      #40
                      Thanks. I feel like a child learning this stuff. I didn't realize I had to fill in all the parameters, so when I got that error the first time I started removing things. I had the oco string empty because it isn't an oco. changed it, compiled ok. Now to wait for some volatility to see if it works.

                      Comment


                        #41
                        Progress... It sent the order. However, that order met with an error:
                        Click image for larger version  Name:	image.png Views:	0 Size:	7.2 KB ID:	1250875

                        Comment


                          #42
                          Hello OldHatNoobCoder,

                          You can use string.Empty for the OCOID.

                          Below is a link to a forum post with an example that places an entry with no OCOID.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #43
                            I updated to sring.Empty and still got the same error:
                            Code:
                            if (atmStrategyId.Length > 0)
                                        {
                                            bool stopOrderRejected = false;
                                            string[,] stopOrders = GetAtmStrategyStopTargetOrderStatus("STOP1", atmStrategyId);
                            
                                            if (stopOrders.Length > 0)
                                            {
                                                for (int i = 0; i < stopOrders.GetLength(0); i++)
                                                   {
                                                if (stopOrders[i, 2].ToString() == "Rejected")
                                                {
                                                    stopOrderRejected = true;
                                                    break;
                                                }
                                            }
                                        }
                            
                                        if (stopOrderRejected)
                                        {
                                            double limitPrice = Position.AveragePrice - 10 * TickSize;
                                            Order newLimitOrder = myAccount.CreateOrder(myInstrument, OrderAction.Sell, OrderType.Limit, OrderEntry.Automated, TimeInForce.Day, 0, limitPrice, 0, string.Empty, "NewLimitOrder", Core.Globals.MaxDate, null);
                                            Account.Submit(new[] { newLimitOrder });
                                        }​
                            Is there something else I need to change in order to use that? I looked at your example for an add-on, and other than seeing that string.Empty was used to send an order, I didn't see anything else to compare.

                            Comment


                              #44
                              Hello OldHatNoobCoder,

                              You should not be using the Position.AveragePrice unless you have moved to using native strategy order methods. The Position object from the strategy will always be flat. It will not change if you are using Atm Strategy methods or placing orders directly to the account. I recommend that you remove that code from your script.

                              Also, the order cannot have a quantity of 0. Please change this to 1.


                              I've copied and pasted the two lines to create the order and submit the order. I removed the Position.AveragePrice and changed the quantity to 1, and I'm not seeing an error. Below is a link to a video of the test.


                              Can you reproduced with this exported test script on your end?

                              AccountOrderSubmitTest_NT8.zip
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #45
                                Thanks Chelsea, but that didn't affect the issue. Still got the error:
                                Click image for larger version  Name:	image.png Views:	0 Size:	7.9 KB ID:	1251087
                                Also, I left it as zero based on this, on the page explaining this method:
                                limitPrice Order limit price. Use "0" should this parameter be irrelevant for the OrderType being submitted.
                                ​You can see it was sending the appropriate 1-contract size order with this setting (prior error message shared). And it was sending the order (or trying to), so I'm not sure why that change would have been necessary. If it's no different, I'd rather send the order at the more appropriate price, since close [0] gives me less control over price of the order.

                                Alas, tried it and didn't change things.​
                                Last edited by OldHatNoobCoder; 05-11-2023, 10:17 AM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                547 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                323 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                99 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                543 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                545 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X