• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Understanding backtest stop-loss error message

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

    Understanding backtest stop-loss error message

    I am coding a strategy and am receiving numerous instances of the following error message: A Buy order placed at '[time]' has been ignored since the stop price is less than or equal to the close price of the current bar.

    I have searched the NinjaTrader forums and have read many posts related to this error message, but none have answered the question that I have about the error itself, nor how to work around the error to achieve what I wish to do.

    Assume that my strategy is reduced to the following condition in order to go long.
    All logic takes place in the OnBarUpdate method.
    Calculate is set to OnBarClose.

    Condition:
    * Completed bar is a Doji.

    Parameters to enter long position:
    * Entry point is the high of the Doji.
    * Stop loss is the low of the Doji.
    * Profit target is twice the absolute difference between the entry point and the stop loss. (2:1 reward/risk ratio.)

    For long positions, aren't stop prices supposed to be set to a price that is less than the current price?

    How may I otherwise enter a long position using my parameters?

    Thank you.

    #2
    Hello rgoudie,

    A buy stop order must be above the current ask price. (This is also true for manually placed orders. Try placing a stop market order below the ask price on the SuperDOM)

    When the order is submitted, is the stop price parameter greater than the GetCurrentAsk()?


    A sell stop order must be below the current ask price.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I think that I might be confusing terms. Is the stop price the same thing as a the stop loss???

      Comment


        #4
        Hello rgoudie,

        A stop loss would be a term used for a protective stop market or stop limit order used to protect loss from a position.

        The order itself would be a stop market order stop limit order and would have a stop price (and in the case of a stop limit order would also have a limit price).

        https://www.investopedia.com/terms/s/stoporder.asp
        https://www.investopedia.com/terms/s...limitorder.asp
        https://www.investopedia.com/ask/ans...derdetails.asp

        A stop order could be used as an entry order to enter a position or as a stop loss to exit a position protecting against loss.
        A stop order could also just be used as an exit order behind the market to exit the position after gaining profit to lock in the profit but still allow for more gain.

        https://ninjatrader.com/support/help...stopmarket.htm
        https://ninjatrader.com/support/help...gstoplimit.htm
        https://ninjatrader.com/support/help...etstoploss.htm
        https://ninjatrader.com/support/help...stopmarket.htm
        https://ninjatrader.com/support/help...gstoplimit.htm

        In NinjaTrader we refer to a stop loss as a stop market order submitted by a Set method such as SetStopLoss() in NinjaScript or from an Atm Strategy when placing manual orders.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for the links.

          Comment


            #6
            I am still having issues with backtesting my strategy.

            I am still receiving this error message on the very first date in my historical data:

            Strategy 'One-Minute Candlestick Trading Strategy./-1': A Buy order placed at '2020-01-02 02:44:00' 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.

            Here is data associated with the attempted order. Can you help me understand where the error is?

            ### Date: 2020-01-02 02:44:00
            Prices: [Open=$8,815.00 | High=$8,816.25 | Low=$8,814.75 | Close=$8,815.00 | Volume=203 ]
            Current ask: $8,815.00
            SetProfitTarget(CalculationMode.Price, $8,819.25)
            EnterLongStopLimit(1, $8,816.25, $8,814.75)


            Thank you.

            Comment


              #7
              Hello rgoudie,

              I would recommend you use prints to understand the behavior.

              The message is letting you know that a buy stop order was submitted with the stop price less than the current ask.

              Below is a link to a forum post that demonstrates using prints to understand behavior.
              https://ninjatrader.com/support/foru...121#post791121

              One line above where the stop order is placed, print the GetCurrentAsk(), and print the price being submitted to the order method.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                The data included in my previous message displays all data including the current ask price. Why did you think that I included it?

                Comment


                  #9
                  Hello rgoudie,

                  Would this be output from a print from the NinjaScript Output window from using GetCurrentAsk(), or information that you visually found from looking at a chart?

                  (Technically, in historical data, GetCurrentAsk() and GetCurrentBid() return the Close price, however it is good practice to use these as this will affect real-time data).

                  May I test your script and confirm that you have added this print in the code?

                  To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                  1. Click Tools -> Export -> NinjaScript...
                  2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                  3. Click the 'Export' button
                  4. Enter a unique name for the file in the value for 'File name:'
                  5. Choose a save location -> click Save
                  6. Click OK to clear the export location message
                  By default your exported file will be in the following location:
                  • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                  Below is a link to the help guide on Exporting NinjaScripts.
                  http://ninjatrader.com/support/helpG...-us/export.htm
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    This data was generated within the strategy. Could you please just examine the prices and see why these would generate the error message? Thanks.

                    ### Date: 2020-01-02 02:44:00
                    Prices: [Open=$8,815.00 | High=$8,816.25 | Low=$8,814.75 | Close=$8,815.00 | Volume=203 ]
                    Current ask: $8,815.00
                    SetProfitTarget(CalculationMode.Price, $8,819.25)
                    EnterLongStopLimit(1, $8,816.25, $8,814.75)

                    Comment


                      #11
                      Hello rgoudie,

                      With the ask price you have shown I would not expect the buy stop order to be rejected.

                      Likely, the prices you have shown are not the prices being used by the strategy at the time the order is being placed.

                      Let me know if you would like me to confirm this.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I feel so frustrated. I am still struggling with this issue. It doesn't make sense. Here is the first order that my strategy attempts. It fails because of the same error mentioned since the beginning of this post.

                        Here are the prices at the time of attempted execution. They are being logged to a text file. (This is the same thing as logging to the Output window.)
                        This logging takes place in the OnBarUpdate method.
                        Calculate = Calculate.OnBarClose

                        ### Date: 2020-01-02 02:44:00
                        Completed bar: Open[0] = 8815.00 | High[0] = 8816.25 | Low[0] = 8814.75 | Close[0] = 8815.00 | Volume[0] = 203
                        GetCurrentAsk(): 8815.00
                        Bars.GetOpen(CurrentBar + 1): 8815.25
                        SetProfitTarget(CalculationMode.Price, 8819.25)
                        EnterLongStopLimit(1, 8816.25, 8814.75)


                        What is the problem with this long stop-limit order?

                        Thanks.

                        Comment


                          #13
                          Hello rgoudie,

                          This is Jim, replying on behalf of Chelsea who is out of the office at this time.

                          The best way to understand the error is to focus on the single order submission that caused the error. For example, note the bar that had placed the order, and create a new test strategy that will only place the order(s) in question, and then prints the OHLC of the next bar.

                          We should also note that there is no intrabar movement with historical processing. If the strategy is using Standard Order Fill Resolution, it will create "virtual bars" based on the OHLC of the next bar to simulate how market data moved and then fill the order. If you use Order Fill Resolution set to High and use a 1 tick data series, the order will be filled with intrabar granularity because it is submitted to the single tick data series. Cases where this error is seen can be resolved using Order Fill Resolution set to High or adding a single tick data series to the strategy and submitting orders to that strategy.

                          Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

                          More information on Historical Fill Processing can be found here - https://ninjatrader.com/support/help...ical_fill_.htm

                          Below is a video demonstration showing the debugging steps that can be taken to analyze how the error was received.

                          Demo - https://drive.google.com/file/d/14pTjU15ft2FKRyOGxpu1hfla0MKpR1ZP/view?usp=drivesdk

                          I attached the test script from the demo as well.

                          Let us know if you have any questions.
                          Attached Files
                          Last edited by NinjaTrader_Jim; 06-15-2020, 06:42 AM.
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            Thank you, Jim. However, this link does not lead to a video. It is just the Understanding Historical Fills link.


                            Originally posted by NinjaTrader_Jim View Post
                            Hello rgoudie,
                            This is Jim, replying on behalf of Chelsea who is out of the office at this time.

                            Below is a video demonstration showing the debugging steps that can be taken to analyze how the error was received.

                            Demo - https://ninjatrader.com/support/help...ical_fill_.htm

                            Comment


                              #15
                              Well, my problem was due entirely to that fact that I completely misunderstood what a stop price was. I did a bit of research and changed my order type to match what I wanted. My strategy is now working as expected.

                              Thak you.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pol133, Today, 04:36 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChristopherS  
                              Started by login_dejavu, 07-12-2020, 07:28 AM
                              6 responses
                              50 views
                              0 likes
                              Last Post MojoJojo  
                              Started by faustf, Today, 03:50 AM
                              3 responses
                              17 views
                              0 likes
                              Last Post faustf
                              by faustf
                               
                              Started by MojoJojo, Today, 03:55 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post MojoJojo  
                              Started by GLFX005, Today, 03:54 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post GLFX005
                              by GLFX005
                               
                              Working...
                              X