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 change errors

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

    order change errors

    i have a order change error and this is what i see on the log.
    2021-07-23 8:03:40 AM Order Sim101, Unable to change order since new limit price is greater/equal ask price or smaller/equal bid price. affected Order: SellShort 1 Limit @ 1.37431

    Is this message format limited to SIM or will i get the same message format from FXCM and or IB?
    My goal is to intercept this and change from limit to market order on orderupdate.
    Cbi.OrderState orderState = rejected
    , Cbi.ErrorCode error,-> what would this look like?
    string comment-> what would this look like?
    where would this message be?

    #2
    Hello junkone,

    Thanks for your question.

    This would be handled with RealtimeErrorHandling set to IgnoreAllErrors because the order error does not mean the order was rejected. You would then look for ErrorCode.UnableToChangeOrder in OnOrderUpdate to trap the order error.

    The comment string will show the same message that you see with the error: "Unable to change order since new limit price is greater/equal ask price or smaller/equal bid price"

    Let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      would the comment string be the same for all the brokers that i may use. I do have a multibroker use licence and currently have fxcm and ib

      Comment


        #4
        Hello junkone,

        The comment would be the same as the native error when looking at the log entries.

        2021-07-23 06:22:45:832|1|32|Order='c143f282c00f47dbac12707f6 e6a65d1/Sim101' Name='' New state='Working' Instrument='GBPCAD' Action='Sell' Limit price=1.72893 Stop price=0 Quantity=10,000 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Unable to change order' Native error='Unable to change order since new limit price is greater/equal ask price or smaller/equal bid price.'

        Native errors will show the broker's message when applicable so this may change depending on the broker. I suggest simply checking the ErrorCode of the error in OnOrderUpdate to properly identify it.
        JimNinjaTrader Customer Service

        Comment


          #5
          is there any potential issues if i re-entered a rejected order in order update. i can trace the transaction till the new submitorderunmanaged and cannot find any entries in he log for the submitorder unmanageed.

          Code:
          protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
          int quantity, int filled, double averageFillPrice,
          Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
          {
          try
          {
          
          // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
          // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediately after submitting
          switch (order.Name)
          {
          case ENTRYLONG:
          
          
          entryOrderLong = order;
          
          
          if (order.OrderState == OrderState.Filled)
          {
          // do something
          
          }
          else if (order.OrderState == OrderState.Rejected && entryOrderLong != null && error== ErrorCode.UnableToChangeOrder && order.OrderType==OrderType.Limit && isChangeOrderFailed( comment))
          
          {
          // change order to market order.
          addEventinDB("change order failed for long, entering market",order.Time.ToString()); // i can see thsi entry in my logs.
          entryOrderLong = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, entryOrderLong.Quantity, 0, 0, "", ENTRYLONG); // cannot see this entry in my logs and no exception so far.
          
          
          
          }

          Comment


            #6
            Hello junkone,

            You can't change the order type, but you may cancel and replace the order. I have attached a quick and dirty example to demonstrate. It is intended to be simple so there is just enough order tracking logic to get the example to work. For a more in depth example on tracking order objects in an unmanaged strategy, have a look at the Unmanaged Template we share on the forums.

            Right now, I'm guessing that IOrder might be obsolete in NT8?; and that NinjaTrader.Cbi.Order is the readonly handle to a specific order. I am doing an Unmanaged strategy; and want to hold this Order in an instance of an OrderWrapper custom class. I could be wrong, but don't see IOrder in Object Browser with Visual Studio?
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              now, i remember i had the same prob few years back and got the same answer. why cannot NT give a error or warning or exception. this makes no sense to me that it can skip over a line of code especially a create order one.

              Comment


                #8
                Hello junkone,

                As a best practice, it would be good to have all order submission methods use unique names. This way it is identifiable what specific order methods fired to create the entries that we see on the chart, and this also helps for debugging so we know where to look if there are issues.

                With this modification here, we can see that the stop loss order from the example never goes away, but a new order is submitted. This is also the unmanaged approach and we are essentially telling NinjaTrader "buy or sell here with this order type, and return the order object associated." There is not any internal functionality to track the order types and change them.

                Code:
                if (error == ErrorCode.UnableToChangeOrder)
                {
                    Print("Order change failed, submitting hard exit.");
                    //CancelOrder(stopLoss);
                    //stopLoss = null;
                    stopLoss = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "Stop loss");
                }
                In general, we should always cancel and replace an order if we want to change the type. Some brokers may support this natively, but NinjaTrader does not, even if the broker allows it.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  hold on. i am using unmanaged and so i expect NT to execute what i want to. When i isue a order to modify to market order, i expect it to complete. I notice that Ninjatrader does not execute the code to change from limit to market. How do i know as a programmer that Ninjatrader will selectively ignore the commands.
                  Either, i manage the orders or ninjatrader manages the orders.
                  when i set to "unmanaged", I expect Ninjatrader to blindly execute the orders that my code is issuing and not have a selective amnesia.

                  Comment


                    #10
                    Hello junkone,

                    When we are dealing with unmanaged, there is no layer between what we are telling NinjaTrader. SubmitOrderUnmanaged literally means submit an order, and ChangeOrder means change an order.

                    We should not use SubmitOrderUnmanaged or ChangeOrder with an expectation that the order type will change because, in general, order types cannot be changed and they must be cancelled and replaced.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      where does it say in your documentation?

                      Comment


                        #12
                        Hello junkone,

                        SubmitOrderUnmanaged definition states: Generates an Unmanaged order.

                        ChangeOrder definition states: Amends a specified Order.

                        We should only understand the unmanaged approach as simply what the method does, and with the definition given, we should just understand the methods as generating orders and amending orders. No more and no less.

                        As far as changing an order type, there is no way to change an order type manually, so we should not expect to be able to do so through NinjaScript. It is not openly stated in the platform as this is a very uncommon feature. As far as I know, only TD Ameritrade supports doing so natively, but we do mention in our Connection Guide that we do not support the "changing order type of active order" feature that is exclusive to TD Ameritrade.

                        1. TD Ameritrade supports changing the order type of an active order. This is not a common practice. NinjaTrader does not support this feature.
                        https://ninjatrader.com/ConnectionGu...nnection-Guide


                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          the error code you shared earlier is incorrect. Here is the screenshot of the debug info.
                          the error i need to look for is
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by benmarkal, Yesterday, 12:52 PM
                          3 responses
                          22 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by helpwanted, Today, 03:06 AM
                          1 response
                          16 views
                          0 likes
                          Last Post sarafuenonly123  
                          Started by Brevo, Today, 01:45 AM
                          0 responses
                          11 views
                          0 likes
                          Last Post Brevo
                          by Brevo
                           
                          Started by aussugardefender, Today, 01:07 AM
                          0 responses
                          6 views
                          0 likes
                          Last Post aussugardefender  
                          Started by pvincent, 06-23-2022, 12:53 PM
                          14 responses
                          244 views
                          0 likes
                          Last Post Nyman
                          by Nyman
                           
                          Working...
                          X