Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Pending Order Cancel From Strategy

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

    #16
    The script is attached
    Attached Files

    Comment


      #17
      Hello samish18,

      With the script you have provided, you are ensuring that the order is not in an accepted state.

      You will need to instead check the order is in a working or accepted state.

      if (myEntryOrder != null && (myEntryOrder.OrderState == OrderState.Accepted || myEntryOrder.OrderState == OrderState.Working))
      CancelOrder(myEntryOrder);
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Thank you for the clarification, the strategy is now running without the error. I noticed however, that running live, the strategy takes far more trades than when backtesting over the same period. Why might this be?

        Comment


          #19
          Hello samish18,

          There are differences between real-time and backtest.

          To understand specifically what is causing differences with your script, it would be necessary to write the information the script is processing to text file and compare the output.

          Below is a link to a support article with direction.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            I do not understand how any of the issue described relate to my script, I am using limit orders and running on bars measured in ticks

            Comment


              #21
              Hello samish18,

              If the results are different, then either the data (bar type, interval, range from first to last bar) or the logic is different.

              Writing the values out to file tells us what is different and why the results are different.

              This relates to your script because you are getting different number of trades.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Where should I put the print statement to investigate this?

                Comment


                  #23
                  Hello samish18,

                  The article linked in post # 19 provides an example script that writes information to text file and a video demonstrating how the information can be used to see what values, order times, execution prices, etc., are specific different between backtest and real-time and why.
                  The example is using the C# StreamWriter class to write to file.
                  This also discusses using TickReplay and 1-tick intra-bar granularity.

                  The values should be written to file one line above the conditions that submit the order, and should include the time of the bar and all values used in the condition set along with labels for each value and comparison operator (so we know how the values are being compared).
                  Further in OnOrderUpdate / OnExecutionUpdate the order.ToString()/execution.ToString() should be written as well, to see the order objects update and the fill times and prices.

                  The start bar date and time and end bar date and time must be the same. If you don't plan to test for an entire session in real-time, you can test over a small amount of time defined in a custom trading hours template. This is demonstrated in the video linked from the article.

                  Run this in real-time, then backtest over the exact same data, and provide the output from each.
                  I'll be happy to assist with analyzing the output and spotting what is causing differences.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    I am now getting an error: Sim101, Order 'abc...' can't be submitted: The OCO ID 'xyz...' cannot be reused. Please use a new OCO ID and then the following message "Strategy submitted an order theat generated the following error 'Order Rejected'. Strategy sent cancel requests, attempted to close the position and terminated itself." How may I fix this issue?

                    Comment


                      #25
                      Hello samish18,

                      This would depend on why the order was rejected.

                      What was the full error message?

                      May I have you copy and paste this? (Click on the error message on the Log tab of the Control Center and press Ctrl + c to copy then Ctrl + v to paste in your next post)
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        I attached the error messages
                        Attached Files

                        Comment


                          #27
                          Hello samish18,

                          Is there one more error appearing on the Log tab of the Control Center?

                          The OCO rejected order is due to the order using an OCOID that was already used by a previous order that is either rejected, filled, or cancelled.

                          As you are using the managed approach, this is likely from a Set method like SetStopLoss() and SetProfitTarget().
                          My guess is that a stop was submitted with an invalid stop price.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            I can't find another error message in the log tab - it was likely buried by other messages. How can I avoid this issue with the SetStopLoss and SetProfitTarget?

                            Comment


                              #29
                              Hello samish18,

                              We would want to confirm the issue first.

                              May I have a screenshot of the Log tab of the Control Center showing buy limit order that was rejected OCO scrolled to the center?


                              With set methods, you would need to ensure the stop price is below the bid for a sell or above the ask for a buy

                              double stopPrice = Low[0];

                              if (stopPrice >= GetCurrentBid())
                              stopPrice = GetCurrentBid() - TickSize;

                              SetStopLoss(CalculationMode.Price, stopPrice);

                              And that these are reset using a number of ticks before calling an entry order method.

                              SetStopLoss(CalculationMode.Ticks, 20);
                              EnterLong();
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                Does this indicate that the price of the instrument is moving past the profit target/stop loss during the current bar?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, 03-13-2026, 05:17 AM
                                0 responses
                                87 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                151 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                80 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                53 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                62 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X