Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit order issue (Strategy shuts down)

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

    #16
    Yes. You would want to check for Working or Accepted states. Or if your original is in a terminal state then place a limit order.
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      How can I do it? Which methods do I need to check the states?

      Thank you

      Comment


        #18
        Please review the Help Guide article on IOrder objects. http://www.ninjatrader-support.com/H...V6/IOrder.html
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          For the time being I decided to use EnterStop orders to avoid such problems.
          I just tried to run the strategy and I get in the Log that Enter() methods have been ignored and "A SellShort stop order placed at '04/01/2008 15.00.00' has been ignored since the stop price is greater than or equal to close price of the current bar".
          Obviously it can happen that the stop price from bar[1] is higher than the stop price in bar[0].
          How could I work around this?

          Thank you

          Comment


            #20
            stefy,

            You simply have to submit at a price level that is valid. In real-time this is generally not an issue if you don't submit stop losses so close to your entry price. In backtesting it is more difficult to control these scenarios because you do not know what is going to happen on the next bar.

            If you are just going to use a regular stop order I suggest you use the SetStopLoss() method for that order instead.
            Josh P.NinjaTrader Customer Service

            Comment


              #21
              But I need to backtest my strategy somehow.
              I'm using just EnterLongStop and EnterShortStop, the exits and stop losses are just handled as common market orders.

              if (conditions)
              {
              // Entry Long Condition
              EnterLongStop(DefaultQuantity, uplimit, "LongStop");

              // Entry Short Condition
              EnterShortStop(DefaultQuantity, lowlimit, "ShortStop");
              }

              Thank you

              Comment


                #22
                stefy,

                There is no way around this. You just simply have to submit at a valid price. You can program logic that checks to see if your order is rejected. Then if it is just resubmit or whatever you would like. If you want an order to be guaranteed to submit just submit them as market orders.
                Last edited by NinjaTrader_JoshP; 11-03-2008, 01:56 PM.
                Josh P.NinjaTrader Customer Service

                Comment


                  #23
                  At the end of my code in OnBarUpdate, I should write something like:

                  if (order.OrderState == OrderState.Rejected)
                  //I enter without any conditions
                  {EnterLong}

                  Is the above correct?

                  Thank you

                  Comment


                    #24
                    No. You need to access the correct IOrder object. Then you need to use the correct method call for EnterLong with the paranthesis. EnterLong().

                    When working with IOrders it is best to work from within the OnOrderUpdate() method. Please see the Help Guide example. There is also a reference sample available showing you some more examples on using OnOrderUpdate().
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #25
                      So far I did this:

                      Variables region

                      private IOrder EntryOrderL = null;
                      private IOrder EntryOrderS = null;

                      OnBarUpdate()

                      {
                      if (EntryOrderL == null)

                      {
                      EntryOrderL = EnterLongStop(0, true, DefaultQuantity, MaxRange, "LongStop");
                      }

                      if (EntryOrderS == null)

                      {
                      EntryOrderS = EnterShortStop(0, true, DefaultQuantity, MinRange, "ShortStop");
                      }
                      }

                      protected override void OnOrderUpdate(IOrder order)
                      {
                      if (EntryOrderL != null && EntryOrderL.Token == order.Token)
                      {
                      Print(order.ToString());
                      if (order.OrderState == OrderState.Rejected)
                      {
                      EnterLong(DefaultQuantity, "Long");
                      EntryOrderL = null;
                      }
                      }

                      if (EntryOrderS != null && EntryOrderS.Token == order.Token)
                      {
                      Print(order.ToString());
                      if (order.OrderState == OrderState.Rejected)
                      {
                      EnterShort(DefaultQuantity, "Short");
                      EntryOrderS = null;
                      }
                      }
                      }

                      In the backtest, it takes just two trades at the beginning of the period (one entry, one exit).
                      I simply want to input StopLimit orders and, if they are rejected (for the reason that the Stop price is higher/lower than the close price) I want to substitute them into Market orders. It seems to me the only way to have a backtest quite close to reality.
                      What do I need to change in the code?

                      Thank you

                      Comment


                        #26
                        Hi stefy,

                        The reason you are only taking one trade is because your entry condition is for the IOrder objects to be null. That is fine, but you do not reset your objects to null. You only reset them from a rejected state. You will also want to reset them in a cancelled or filled state as well.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Following your suggestion, I edited the code as follows:

                          private IOrder EntryOrderL = null;
                          private IOrder EntryOrderS = null;

                          OnBarUpdate()

                          {
                          if (EntryOrderL == null)

                          {
                          EntryOrderL = EnterLongStop(0, true, DefaultQuantity, MaxRange, "LongStop");
                          }

                          if (EntryOrderS == null)

                          {
                          EntryOrderS = EnterShortStop(0, true, DefaultQuantity, MinRange, "ShortStop");
                          }
                          }


                          protected override void OnOrderUpdate(IOrder order)
                          {
                          if (EntryOrderL != null && EntryOrderL.Token == order.Token)
                          {
                          Print(order.ToString());
                          if (order.OrderState == OrderState.Rejected)
                          {
                          EnterLong(DefaultQuantity, "Long");
                          }
                          if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Rejected)
                          {
                          EntryOrderL = null;
                          }
                          }

                          if (EntryOrderS != null && EntryOrderS.Token == order.Token)
                          {
                          Print(order.ToString());
                          if (order.OrderState == OrderState.Rejected)
                          {
                          EnterShort(DefaultQuantity, "Short");
                          }

                          if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Rejected)
                          {
                          EntryOrderS = null;
                          }
                          }
                          }

                          Now I got more trades executed, but in the Log file I keep on getting the same error code Enter() methods have been ignored and SellShort stop order has been ignored since the stop price is greater than or equal to close price of the current bar.

                          Thank you

                          Comment


                            #28
                            Right. Isn't that what your code is trying to address? When you submit an invalid price you will still get that message, but now you will be able to submit a market order in response. Also, I am not sure if submitting an order at an invalid price is rejected or not. It may be a Cancelled state.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #29
                              No, there is something wrong clearly, for some currencies I get zero trades (instead of the normal few hundreds), for other currencies I get many less trades. It basically stops to trade at some point (depending on the currency).

                              Maybe if I attach a sample of the code it can be easier to explain?

                              Thank you

                              Comment


                                #30
                                If it does not trade you need to debug it slowly. Take it step by step. Start simple and then slowly introduce layers of complexity. Print out values for the IOrder object. Maintain the use of TraceOrders = true. Go through one line at a time till you figure out what is breaking.
                                Josh P.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                648 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                369 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                573 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                575 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X