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

Limit order issue (Strategy shuts down)

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

    Limit order issue (Strategy shuts down)

    I developed a strategy and tried to use limit orders but I got a few issues.
    The first, and major one, is that sometimes I get the following message "Limit price cannot be lower than the bid" and the strategy shuts down.

    1) Could you please explain me why I cannot place a limit order below the bid price?

    2) Is this constraint always on or just on the positions I'm holding already?

    Thank you

    #2
    Hello,


    You cannot place a short (sell) limit order below the bid price. This is a limitation of the exchange. NinjaTrader does not establish this limitation. These are basic limit order rules.
    DenNinjaTrader Customer Service

    Comment


      #3
      So, what is the best way to get around it?
      To use a variable like MAX(mylimit, bid) as a LongLimit would prevent the strategy from shutting down?

      Thank you

      Comment


        #4
        That could be a potential solution, but if the bid is moving extremely fast it can ultimately still end up higher than your limit price while your limit order is inflight. You will just need to put your limit order a bit further away in this instance.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I created a super simple strategy to test the execution, yet, it doesn't work.

          Here is the strategy:

          {
          double limitlong = Math.Max(GetCurrentAsk(), Close[1]);
          double limitshort = Math.Max(GetCurrentBid(), Close[1]);

          // Condition set 1
          if (Close[0] > Close[1])
          {
          EnterLongLimit(DefaultQuantity, limitlong, "Long");
          ExitShortLimit(limitlong, "", "Short");
          }

          // Condition set 2
          if (Close[0] < Close[1])
          {
          EnterShortLimit(DefaultQuantity, limitshort, "Short");
          ExitLongLimit(limitshort, "", "Long");
          }
          }

          As soon as I start it, I get in the Log "An Exit() method to submit an exit order at '29/09/2008 0.32.00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."

          Thank you

          Comment


            #6
            That is because you can't be in a long and a short position like that simultaneously. Please see the Internal Order Handling Rules at the bottom of this article: http://www.ninjatrader-support.com/H...verview36.html
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thank you. I'm aware of the Internal Order Handling Rules, but I need to find a way around them, otherwise it'd become impossible to trade an asset Long/Short with limit orders!

              I did the following, using the MarketPosition method, yet I get the same error in the Log.

              double limitlong = Math.Max(GetCurrentAsk(), Close[1]);
              double limitshort = Math.Max(GetCurrentBid(), Close[1]);

              // Condition set 1
              if (Close[0] > Close[1]
              && Position.MarketPosition==MarketPosition.Flat)
              {
              EnterLongLimit(DefaultQuantity, limitlong, "Long");

              }

              // Condition set 2
              if (Close[0] < Close[1]
              && Position.MarketPosition==MarketPosition.Long)
              {
              ExitLongLimit(limitshort, "", "Long");

              }

              ExitShortLimit(limitlong, "", "Short");



              // Condition set 3
              if (Close[0] < Close[1]
              && Position.MarketPosition==MarketPosition.Flat)
              {
              EnterShortLimit(DefaultQuantity, limitshort, "Short");

              }

              // Condition set 4
              if (Close[0] > Close[1]
              && Position.MarketPosition==MarketPosition.Short)
              {
              ExitShortLimit(limitlong, "", "Short");

              }
              }

              Thank you

              Comment


                #8
                That is right. You cannot even submit a limit order in the opposite direction when you still have a limit order working in the first direction.

                There is no way around this because of the implications of such an approach. Remember, when you are long and you put in an EnterShort() it essentially tries to close your long position before entering you into your desired short position. When you have two simultaneously working limit orders in opposite directions this "close position" logic goes haywire. What if both get filled at the same time? What happens to closing the opposite direction's position? It gets messy real fast. This is why the rules are in place. You simply cannot do it.

                You can try using two strategies, one containing the long logic and one containing the short logic, but communication between the strategies is not supported.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  What if I used Limit orders to enter the positions (either Long or short) and then I used Set() rules (SetStopLoss, SetProfitTarget) to exit the positions?
                  In this way both Long and Shorts would coexist in the same strategy and I'd be using limit orders both for entries and exits.

                  Thank you

                  Comment


                    #10
                    stefy,

                    The issue is not only in exits. The issue is with entries as much so as it is with exits. You cannot have two limit orders working to try and enter long and short at the same time.

                    Methods that generate orders (excluding market orders) to enter a position will be ignored if:
                    • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      I understood, the only way around is to play a Long and a Short separate strategies and just check them.

                      Another issue: if I want to trade a Breakout system, using EnterLongStopLimit and EnterShortStopLimit, I understand I'm unlikely to experience the problems above, since if my breakout fails, my stop loss will close my position before the order in the opposite direction takes place.
                      Am I correct?

                      Thank you

                      Comment


                        #12
                        You will experience the same problem. Stop-Limit orders ultimately become limit orders. What if you hit your long's stop and it became a limit order. Before the limit order is filled you come back down and hit the short's stop. Now you are stuck with two limit orders working simultaneously. Same problem as before.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Let's say the first limit order is on and the price is hitting the stop of my second StopLimit order. Can't I cancel the first limit order when this second stop is hit, right before my second limit order is sent?
                          Is it possible to do so with the CancelOrder() method?

                          Thank you

                          Comment


                            #14
                            You could, but you will only want to submit your second stop-limit after you have confirmed that your first order was cancelled successfully. To do so you will want to check the IOrder object's OrderState. You will want to ensure it is in a terminal state and then place your new order.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Understood. To make it more simple, I was wondering, is it possible to call my order status, and say:
                              if (order_status = limit order on)
                              place market order (for opposite direction)
                              else
                              place limit order.

                              Thank you

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Aviram Y, Today, 05:29 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Aviram Y  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              3 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              7 responses
                              34 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cls71, Today, 04:45 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post cls71
                              by cls71
                               
                              Started by mjairg, 07-20-2023, 11:57 PM
                              3 responses
                              218 views
                              1 like
                              Last Post PaulMohn  
                              Working...
                              X