Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopLoss ignored

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

    StopLoss ignored

    Hello,
    I am getting an error while submitting a stop loss order for which I cannot find an explanation.
    I have isolated the problem in a concrete example scenario. You can easily test it and get the same results from the Strategy Analyzer, ES 06-20, 15-min bars, from January 01, 2020 to January 09, 2020, so that the numbering of the bars corresponds.

    1.- On January 8, 2020 at 3:00 PM in bar # 332 I send a buy Stop-Limit order to enter long, at the stop price of 3242.50. The log reports ok.

    Click image for larger version

Name:	step01_lores.jpg
Views:	1247
Size:	272.7 KB
ID:	1094640
    2.- When I receive the filling of the entry order, within the OnExecutionUpdate, I send an exit bracket where the stop-loss order has a stop price = 3235.00.
    The log reports that the stop loss order has been ignored because its stop price (3235.00) is above the market.
    I understand that the closing price taken into account is that of bar # 342, which is well above the stop loss. So how is it possible that the stop loss order is ignored?

    Click image for larger version

Name:	step02_lores.jpg
Views:	1172
Size:	531.7 KB
ID:	1094641


    3.- What is surprising (unless I am conceptually wrong), is that if the OrderType of the ENTRY order is StopMarket instead of StopLimit, the stop-loss order (it is a EXIT order) works fine. I don't understand how it can influence if the entry order is already filled.

    Click image for larger version

Name:	step03_lores.jpg
Views:	1101
Size:	40.3 KB
ID:	1094642


    I attach the code.

    Thanks.

    #2
    Hello cls71,

    Use prints to understand behavior and don't look visually at a chart.

    Use numbers. Print the information the script is using and this will help to reduce confusion.

    Print the GetCurrentAsk() at the time the order is submitted. A buy stop order will need to have the stop price be below the ask with the limit price equal to or below the stop price (unless it's a simulated stop).


    Below is a link to an example of placing protective orders in OnExecutionUpdate() when the entry is filled.



    When you mention:
    " I don't understand how it can influence if the entry order is already filled."
    I'm not certain I am understanding what this means.
    I will not be possible to change the price of an order that has already filled.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,
      It seems to me that you have not fully understood the problem, or I have not explained myself well. My native language is not English.
      But the truth, I can't think what else to contribute to explain the problem. With the code + images + Ninjascript Output it should be understood.

      I Use prints & numbers to understand behavior and don't look visually at a chart. The chart is only as example. Please see the screenshots of the NinjaScript Output or the code that prints out all the useful information.

      I summarize:

      CASE 1:
      I submit an ENTRY StopLimit order to buy. The filled is correct in 3242.5.
      When I confirm the filled of the entry, I submit a EXIT StopMarket order with stop price = 3235.00. This is the stoploss order which is ignored.
      (Well, it should not be ignored because the cause proposed in the Output is not true. But ok, let's assume that it is an error and thus demonstrate that there is a bug).

      CASE 2:
      Now I do the same but instead of a StopLimit order to ENTRY, I submit a StopMarket. The filled is correct in 3242.5 (same as before). There is no difference from submitting a ENTRY StopLimit.
      And just like before, when I confirm the filled of the entry, I submit a StopMarket order (stoploss order) with stop price = 3235.00 (same as before). So far everything is as in the first case. But surprisingly the stoploss order is NOT ignored. This shows that there is some kind of internal bug.

      Thanks

      Comment


        #4
        Hello cls71,

        There is a stop loss being ignored correct? We will need to know why the order is being ignored.

        Is the order a buy order or sell order? What is the ask or the bid price at the time the order is submitted? This would would find from adding prints.

        If the stop is a buy order and is below the ask the order will be ignored. If the stop is a sell order and is below the ask the order would be ignored.
        If the stop limit is a buy order and the limit price is below the stop price the order will be ignored. If the stop limit is a sell order and the limit price is above the stop price, the order will be ignored.

        I tested the script you provided, but I am seeing an order ignored due to being placed before BarsRequiredToTrade is met and no other orders are placed.


        Are you able to reproduce the behavior using the script you have provided?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          I am going to try to present the problem in a simpler and more detailed way. Again.

          Inside OnStateChange method, in Set.Defaults it changes:
          Code:
          TraceOrders = true;
          BarsRequiredToTrade = 0;
          IsUnmanaged=true;
          Inside the OnBarUpdate method write these lines of code:
          Code:
          if (CurrentBar == 1)
            SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopLimit, 1, 3242.50, 3242.50, string.Empty, "My Entry");
          And inside the OnExecutionUpdate method, write just one line of code:
          Code:
          SubmitOrderUnmanaged (0, OrderAction.Sell, OrderType.StopMarket, quantity, 0.0, price - 4, string.Empty, "My stoploss");

          Open NinjaScript Output and run the StrategyAnalyzer ONLY on January 8, 2020 , ES 06-20 , 15min Bars. You will see that the stop-loss order is ignored.

          Now change the code to submit the entry order in the OnBarUpdate and write:
          Code:
          SubmitOrderUnmanaged (0, OrderAction.Buy, OrderType.StopMarket, 1, 0.0, 3242.50, string.Empty, "My Entry");
          And when you run the StrategyAnalyzer the stop loss order is NOT ignored. Now you see that there is a BUG ??? What does the type of the entry order have to do with ignoring an exit order?

          The stop-loss order should not be ignored in any case. But I present the problem to you like this, with the two types of entry orders, so that anyone can understand that there is a bug.
          Attached Files

          Comment


            #6
            Hello cls71,

            Did I incorrectly test the script in the video I have provided?

            What steps did I take that were incorrect?

            Are you running the script provided in post #1 with the exact steps and data shown in the video I have provided but you are getting a different result?
            If you are running the script you provided me in the video on the same data with a new instance but getting different results, I would want to schedule a call with you so that I may see that you are taking the exact steps shown in the video and investigate further.

            Have you made changes to the defaults? If so, may I confirm that the instance of the script was removed and a new instance added so the new defaults are pulled?


            I've tested the new script you have provided which does have different behavior than the previous script you have provided, but I was not able to reproduce an ignored order. An order was placed and then cancelled at the end of the session.


            When using the unmanaged approach I would only expect orders to be ignored due to BarsRequiredToTrade not being met, or the EntriesPerDirection not being met, or an invalid price is supplied as the stop or limit price with SubmitOrderUnmanaged().
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              at the beginning of the post I explained on what dates the error occurs:
              "I have isolated the problem in a concrete example scenario. You can easily test it and get the same results from the Strategy Analyzer, ES 06-20, 15-min bars, from January 01, 2020 to January 09, 2020, so that the numbering of the bars corresponds, etc "

              Please, in the Strategy Analyzer do the test only for January 8, 2020. In the NinjaScript Output you will get the ignored stop-loss message. I attach a link to the video.


              Comment


                #8
                Hello cls71,

                Thank you for pointing out my mistake.

                I have retested using a date range with January 8th to January 8th on ES 06-20 using 15 minute bars in the Strategy Analyzer.

                I'm seeing an order named 'My Buy' filled with the close information at 9:45 on the 8th while the My stoploss filled with the information at 9:30.

                execution='NT-00000-169' instrument='ES 06-20' account='Backtest' exchange=Default price=3242.5 quantity=1 marketPosition=Long orderId='NT-00000-169' time='2020-01-08 09:45:00' sod=False statementDate='0001-01-01'

                Strategy 'Zs8TestOrder01/-1': A Sell stop order placed at '1/8/2020 9:30:00 AM' has been ignored since the stop price is greater 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.

                I am inquiring further with our development, I appreciate your patience.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB, is there any news on this issue? Thanks

                  Comment


                    #10
                    cls71,

                    Our development is still looking into this issue.

                    At this time I have a tracking number we may provide should you want to check back with us.

                    This issue is being tracked with ID# NTEIGHT-14422.

                    This tracking number will also be listed in the release notes if there is a correction.



                    If I receive any updates about this I will update you as well.

                    Thank you for reporting this behavior.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I am having a similar issue...

                      Unmanaged strategy stoploss orders being rejected.
                      In 8.0.21, it gave an error about the stop being above the market (so, same error as cls71 reported) but I have been running 8.0.22 the last couple weeks.
                      It now rejects the order, but with a different error message:

                      "An order has been ignored since the stop price ‘10028.75’ near the bar stamped ‘10/06/2020 11:20:00 PM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored."
                      [Note: the reported date and time is Australia format... it translates to the bar 20 minutes AFTER the open on June 10, for you US folk...]

                      This on a vanilla StopMarket order, that executes with a stop price below market (on a long entry). My desired stop was 10 ticks... and placed immediately the long position is executed (ie, in OnExecutionUpdate)

                      Now, this was on NQ, 5 minute bars... but I have had similar failures on YM. Spent ages examining my code (it seems it is fine) I eventually managed to eliminate the error by increasing the stop to... 50 ticks !!! Only then would the stoploss position get created.

                      Question to Ninja: is this behaviour due to the order being rejected by:
                      1. the broker
                      2. the exchange
                      3. internal Ninja logic
                      If it is internal Ninja logic, well, it is pretty ordinary still, maybe downright broken.
                      If it is coming from the broker or exchange, I guess I could write code to catch the rejection and resubmit with a larger stop... but - seriously... not accepting the order short of specifying a 50 tick stop ??? PS... I have seen the same behaviour using two different brokers (one of them NinjaTrader brokerage)... so my guess it is NOT broker-related.

                      Can we please get confirmation of where this is actually originating.. so I can plan what to do about it.

                      Edit: Seems it MUST be internal Ninja logic... as this happens on historical data... so I guess broker/exchanges are not in view.
                      If I am right... can we PLEASE get it changed?

                      Regards,
                      T.
                      Last edited by tgn55; 06-17-2020, 05:57 AM. Reason: More thoughts...

                      Comment


                        #12
                        Hello tgn55,

                        Ignored orders are ignored by NinjaTrader.

                        I've noted that you are also experiencing the behavior reported by cls71.

                        NTEIGHT-14422 is an open ticket and this is being worked on by our developers.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Chelsea according to the 8.0.22 release notes, 1422 was fixed. I looked at this... its how I picked up this thread!

                          The behaviour changed from 8.0.21 to 8.0.22. At least, the error message changed.

                          Can you PLEASE confirm if such errors... on historical bars... are generated by the broker? I can't really believe that's how things work...
                          This is a SERIOUS issue... as running a strategy on chart that has maybe several days data... if the strategy leaves an unprotected position running, it can really mess things up. Apart from potential huge losses... but it also impacts on any live trades going forward, if for example, the strategy does nothing unless flat.

                          In my strategy... it is rendered unusable for the rest of the session for this reason.

                          Thank God when I hit this issue, it was running on a SIM account... 5 contracts on ES, with NO protection, running until end of session... Hmm...

                          Comment


                            #14
                            Hello tgn55,

                            Historical orders are the same as backtest and are not submitted live to the broker.

                            These are virtual orders.

                            Any messages from TraceOrders such as messages an order has been ignored are 100% generated by NinjaTrader.

                            I've retested the script provided by cls71 and I can confirm that there are no stop orders ignored on bars where the order price is between the high and the low on a single series script. (Also there are no ignored orders at all)


                            If you test this script with the instructions and script provided by cls71 are you still able to reproduce the issue this forum member reported using 8.0.22.2?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Chelsea I have not run cls71's script...glad you have confirmed what seems to be obvious... backtests, and any historical stuff... is handled internally.

                              So... now that is settled... Ninja is deciding to reject a stop-loss order, placed 10 ticks below the market. Or 20... or 30... or 40... and finally, at 50 ticks, it is accepted.
                              You gotta be kidding! This decision is NINJA's ... and could cause SERIOUS damage!

                              I do not have a simple little test script like cls71 to demonstrate it... just a significant trading script, which I might add, was based on the unmanaged OCO examples provided by Ninja... and I have tested it thoroughly. It works fine... until Ninja decides to spit the dummy and reject stop-loss orders placed WELL below the market. I do my own logging, but also run with TraceOrders on...

                              It's now after 5:30 AM where I am... maybe I'll cut a little demo tomorrow... a bit late to start now!

                              PS... I acknowledge the bar I entered on had a large range... but, maybe, if Ninja is going to do behind-the scene intervention on UNMANAGED orders (???) perhaps you could
                              1. Document that you do so, and what the rules are, and even better...
                              2. Provide a mechanism for the user to TURN IT OFF
                              If this was using the Managed Order system, I'd be less surprised.... but surely in UNMANAGED ... there should be no invisible messing, implementing an undocumented policy that could have disastrous consequences ????

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              139 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              75 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              50 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X