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

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).





        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.







        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.


              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.
                  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/14pT...w?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; 11-19-2020, 02:58 PM.
                          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 inanazsocial, Today, 01:15 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by rocketman7, Today, 02:12 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post rocketman7  
                              Started by dustydbayer, Today, 01:59 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post dustydbayer  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post trilliantrader  
                              Started by Davidtowleii, Today, 12:15 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Davidtowleii  
                              Working...
                              X