Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop/ Stop Limit order execution difficulties

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

    Stop/ Stop Limit order execution difficulties

    Hi,

    I'm trying to create an order to enter long at the high of the previous bar if the previous bar was green. I do want to enter exactly at the previous bar's high though and so I thought I could do this using code such as this:

    I tried 2 variations:

    1. double entryPrice = Math.Min(High[1], GetCurrentAsk());
    EnterLongStop(2, entryPrice, "GreenRatReversal");


    2. double entryPrice = Math.Min(High[1], GetCurrentAsk());
    EnterLongStopLimit(0, true, 2, entryPrice, (entryPrice - TickSize * 10), "GreenRatReversal");


    However, both these orders seem to get canceled or rejected immediately. I also get errors such as:

    2010-03-22 01:20:45:648 ERROR: A Buy order placed at '3/10/2010 4:00:00 AM' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

    OR


    2010-03-22 01:24:09:807 (AMPforex) Cbi.OrderStatusEventArgs.Process: Order='eca9b52de8464e0db5cf82c886eb33e6/Sim101' Name='GreenRatReversal' New State=Rejected Instrument='$AUDJPY' Action=Buy Limit price=0 Stop price=82.62 Quantity=2 Type=Stop Filled=0 Fill price=0 Error=OrderRejected Native error='Buy stop or buy stop limit orders can't be placed below the market.'
    2010-03-22 01:24:09:854 Strategy.StrategyBase.Process.CancelOrdersClosePos itions1: Order='1c92fb18a78f4b718632cbdfbec92c2c/Sim101' Name='GreenRatReversal' State=Rejected Instrument='$AUDJPY' Action=Buy Limit price=0 Stop price=82.62 Quantity=2 Strategy='TradeLikeARat' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='eca9b52de8464e0db5cf82c886eb33e6' Gtd='12/1/2099 12:00:00 AM'
    2010-03-22 01:24:09:854 Strategy.StrategyBase.Process.CancelOrdersClosePos itions2: isTerminal=False


    I somewhat understand these errors, but I'm not sure how I could change my implementation to avoid them. I would really appreciate some pointers.


    Thanks,

    N

    #2
    Hi nitro,


    Thank you for your post. Someone will assist you shortly.

    In the meantime, is it possible that you want to use a limit order instead...

    EnterLongLimit()

    Or perhaps add a tick or two to the entry price to avoid the error.
    TimNinjaTrader Customer Service

    Comment


      #3
      Hi Tim,

      I've tried that too. Matter of fact, that was the first thing I tried

      -Nitro

      Comment


        #4
        Hi nitro,

        To ensure that the condition and price is still valid, make sure CalculateOnBarClose is set to False. Meanwhile, the error may still exist if run on historical data, as the condition is "looked for" intra-bar.
        TimNinjaTrader Customer Service

        Comment


          #5
          Tim,

          Thanks again for the response.

          This issue happens on both live data and historical data and CalculateOnBarClose is set to false.

          Sometimes, on live data, the strategy tries to set the order several times within a bar and finally terminates itself because of the numerous rejections.

          Can you maybe write a quick test program to do what I'm essentially trying to accomplish. That is, place limit buy order at High[1] if Close[0] == High[1] (buy at the high of the previous bar). This sounds fairly simple but for some reason the limit order mechanism doesn't allow this.

          - Nitro

          Comment


            #6
            Hi nitro

            I have tested this on my end and am able to execute orders ok using

            Code:
            if (Close[0] == High[1])
                 EnterLongLimit(High[1], "enter");
            Can you please post the relevant snippet of code you are attemping.
            TimNinjaTrader Customer Service

            Comment


              #7
              Tim,

              I have attached my entire strategy here. Please let me know what I'm doing wrong.

              - Nitro
              Attached Files

              Comment


                #8
                nitro,

                I suggest you add debug statements into your code to see why it keeps resubmitting itself several times. Unfortunately we will not be able to step through your code and debug it for you. If you posted an exact area of interest we can make suggestions based off of that though. Thank you.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  I have already mentioned the specific portion of my code that is causing this issue.

                  Here it is again for reference:
                  Code:
                                      if (isHourlyBiasLong &&
                                          (Close[0] <= (CurrentDayOHL().CurrentLow[0] + TickSize * 10)) &&
                                          (Close[2] < Open[2]) && (Close[1] > Open[1]))
                                      {
                  
                  double entryPrice = High[1];
                                          quickScalpOrder = EnterLongLimit(2, entryPrice, "GreenRatReversal");
                                          SetStopLoss(CalculationMode.Ticks, 10);
                  }
                  I have put in numerous debug statements in my code and I've tried to remote debug in Visual studio as well.

                  I've tried another version where I've tried to add the spread into my orders as well as such:

                  Code:
                                      if (isHourlyBiasLong &&
                                          (Close[0] <= (CurrentDayOHL().CurrentLow[0] + TickSize * 10)) &&
                                          (Close[2] < Open[2]) && (Close[1] > Open[1]))
                                      {
                                          double currentAsk = GetCurrentAsk();
                                          double currentBid = GetCurrentBid();
                                          double entryPrice = High[1];
                                          double spread = Math.Abs(currentAsk - currentBid);
                                          quickScalpOrder = EnterLongLimit(2, (entryPrice - spread), "GreenRatReversal");
                                          SetStopLoss(CalculationMode.Ticks, 10);
                  Every order as soon as it is submitted, goes through the following state change within a matter of seconds:

                  1. Accepted
                  2. Working
                  3. Pending Cancel
                  4. Cancelled

                  The attached NinjaScript trace shows the same behavior

                  The thing is that it doesn't tell me why the order is getting canceled. I'd really appreciate any help. Worst case scenario is I'd have to work with market orders
                  Attached Files

                  Comment


                    #10
                    nitro,

                    If you used TraceOrders = true it may reveal more information as to what your orders are doing. Please try this and inform us as to the output presented for the order.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      So I tried what you recommended and set TraceOrders to true; and this is what I see

                      Code:
                      3/24/2010 2:12:08 PM Entered internal PlaceOrder() method at 3/24/2010 2:12:08 PM: Action=Buy OrderType=Limit Quantity=2 LimitPrice=1169.25 StopPrice=0 SignalName='GreenRatReversal' FromEntrySignal=''
                      3/24/2010 2:12:08 PM Cancelled expired order: BarsInProgress=1: Order='59cc228598d646229aebacfbaea70487/Sim101' Name='GreenRatReversal' State=PendingSubmit Instrument='ES 06-10' Action=Buy Limit price=1169.25 Stop price=0 Quantity=2 Strategy='TradeLikeARat' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='59cc228598d646229aebacfbaea70487' Gtd='12/1/2099 12:00:00 AM'
                      3/24/2010 2:12:08 PM Cancelled expired order: BarsInProgress=2: Order='59cc228598d646229aebacfbaea70487/Sim101' Name='GreenRatReversal' State=PendingSubmit Instrument='ES 06-10' Action=Buy Limit price=1169.25 Stop price=0 Quantity=2 Strategy='TradeLikeARat' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='59cc228598d646229aebacfbaea70487' Gtd='12/1/2099 12:00:00 AM'
                      So it looks like the order is canceled because it's expired. But why would it expire within a second of me placing it?

                      My strategy now just consists of just this 1 line:


                      Code:
                              protected override void OnBarUpdate()
                              {
                                  if (BarsInProgress == 0)
                                  {
                                          quickScalpOrder = EnterLongLimit(2, High[1], "GreenRatReversal");
                                  }
                              }
                      and I still see this behavior. This is clearly an issue with the Ninjascript limit order mechanism and not some bug in my code. Please do look into this and let me know what I'd need to do to get limit orders to work.

                      Comment


                        #12
                        That solves the mystery. This is expected behavior because you are not keeping the order alive. To keep orders alive you have to either:

                        A. Call the order again on every single OnBarUpdate(). When you go into BIP1 and BIP2 you are no longer sending in keep alive orders so it auto expires and cancels out.

                        B. Use the liveUntilCancelled signature for the submission of your order which will keep the order alive without need to resubmit until the order is specifically cancelled by you.

                        Please see the "Order Submission for Entry and Exit Methods - Basic Operation" section here for more information on this: http://www.ninjatrader-support.com/H...tml?Overview36
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Yup, the liveUntilCanceled did the trick. Thanks a lot for your help Josh.

                          Comment


                            #14
                            How do a set a target order in the free version either a stop market or stop limit.

                            Comment


                              #15
                              laredo, SetProfitTarget() would use a regular Limit order per default.

                              For a StopLimit exit, please work with the Exit() methods directly -

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              633 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              567 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X