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

parabolic stop fails

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

    parabolic stop fails

    Hi,
    Very often in backtesting, the parabolic stop fails. Why is this? Please see attached. You can see it working properly on some trades and then failing on others (huge red line). This happens often, accross different strategies. Please share your thoughts.
    thanks,
    David
    Attached Files

    #2
    Hello trader3000a,

    Thanks for your post.

    Please review the help guide document on the differences on real-time vs backtest (historical).
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

    Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

    Although logic-wise very similar, this technique works differently from the ParablicSAR indicator. The indicator will provide trailing stop levels 'always in the market' assuming a constant market position switch, either long or short (reversing). The SetParabolicStop() method in contrast will apply the same parabolic trailing technique sensitive to price acceleration to the custom strategy entry signal/position it is associated with.

    Parabolic stop orders are modified based on the strategies 'Calculate' settings. In the case of 'Calculate' on bar close, when the bar closes the parabolic stop order modification will occur using the closing price of the bar as the reference price to apply the trail offset. Subsequently, if the open price of the next bar is significantly higher or lower then the current close price then there is a possibility that the calculated parabolic stop price is now an invalid stop price.

    Ultimately, if a strategy is not behaving as expected then debugging prints must be added to the strategy that prints out the price the stop is being submitted to, the Time of the bar, and the CurrentBar.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    Something you could consider is using the Parabolic SAR indicator using the same settings are your SetParabolicStop() method to visualize the stop.

    See the help guide documentation below for more information about SetParabolicStop() - https://ninjatrader.com/support/help...abolicstop.htm

    And, see this publicly available documentation about Parabolic SAR indicator - https://www.investopedia.com/trading...parabolic-sar/

    To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar. Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

    High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

    Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

    TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

    Developing for Tick Replay -
    https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

    Additional information may be found in this NinjaTrader Forum post —
    https://ninjatrader.com/support/foru...mance?t=102504

    Please let us know if we may be of further assistance to you.​​​​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon,

      Here are 3 screenshots from 3 identical backtests of an OnBarClose strategy, but with each test using a different one of 3 varieties of stops available. One using paprabolic stop, one using trail stop, and one using stop loss. All using the same initial stop of 80 ticks.

      The trail stop, and stop loss tests perform as expected, and the parabolic stop fails. I have done this test on many other instances on many different dates, different symbols, etc.

      thanks,
      David
      Attached Files
      Last edited by trader3000a; 02-20-2023, 06:58 AM.

      Comment


        #4
        Hello trader3000a,

        Thanks for your note.

        This would be the expected behavior of using SetParabolicStop(). The SetParabolicStop() method works differently than the SetStopLoss() and SetTrailStop() methods. These differences are stated in post # 2 and seen below.

        The SetParabolicStop() method in contrast will apply the same parabolic trailing technique sensitive to price acceleration to the custom strategy entry signal/position it is associated with. Parabolic stop orders are modified based on the strategies 'Calculate' settings. In the case of 'Calculate' on bar close, when the bar closes the parabolic stop order modification will occur using the closing price of the bar as the reference price to apply the trail offset

        See the attached screenshot and simple example script used to test this.

        Please let me know if I may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi Brandon,
          I'm fully versed on the way the different stops are expected to work, and have tested them all thousands of times over years.
          Please see the second trade on the parabolic stop example, the first file of the 3 attached files.The parabolic stop is set for an initial stop of 80 ticks, and the trade loses 311 ticks before closing out at the end of the session. As far as I know, stops aren't designed to move backwards, but please let me know if that's incorrect.
          thanks,
          David

          Comment


            #6
            Hello David,

            Thanks for your note.

            It would be hard to say how the stop is behaving without testing what you are trying to do on my end. That said, are you also using SetStopLoss() in your script? If so, SetParabolicStop would be ignored and SetStopLoss() would take precedence.

            From the help guide: "The SetParabolicStop() method can NOT be used concurrently with the SetStopLoss() or SetTrailStop() method for the same position, if any of methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence."

            You could consider unchecking the 'ExitOnSessionClose' option when running the strategy to see if the SetParabolicStop order ever fills.

            Please note that the SetParabolicStop() method is not a static stop loss order and will trail similarly to how the ParabolicSAR indicator works. When an order is submitted the stop loss will be placed a set number of ticks away from the entry order. If the parabolic stop is not reached before the bar closes, the stop trails so that it remains X number of ticks away from the Close price of the bar that just closed, not X number of ticks from the entry order.

            See the demonstration video linked here that shows how the parabolic stop trails when a bar closes if the stop is not reached: https://brandonh-ninjatrader.tinytak...NF8yMTAyMjY4NQ

            Let me know if I may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hi Brandon,
              I know how the parabolic stop works and how it trails. At this point, you're reiterating the function of a parabolic stop, but I don't need any help there. As I said earlier, I've tested it thousands of times in all possible environments. I'm fully versed in the documentation. I feel I was clear with my examples and no, there are no concurrent stop orders.
              Since we're stuck at this point, perhaps you could pass this issue on to the vendor of the code, or your software development team. The stop is clearly being skipped over by historical data during backtest for some reason.
              thanks,
              David
              Last edited by trader3000a; 02-21-2023, 04:27 PM.

              Comment


                #8
                Hello David,

                Thanks for your note.

                The parabolic stop order is not being skipped over when running a backtest on historical data. The parabolic stop order is not being reached/filled before it trails when one bar closes and the next bar begins building.

                The demonstration video shared in post # 6 shows how the parabolic stop will trail so that it remains X number of ticks away from the Close price of the bar that just closed. You could test the example script attached in post # 4 which was used to test this.

                If you are still having issues, please provide a simple example script that demonstrates that the parabolic stop is working incorrectly as well as the exact steps and settings used to reproduce the issue.

                Let me know if I may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Brandon,
                  Here's a screenshot of a sample of results of your strategy from post Groups I ran it as is, using the settings visible in your screenshot. ES, 5 minute, Use instrument settings (default is ETH). I ran it for the year of 2022. Connection is Rithmic for NinjaTrader brokerage.

                  Of course, there are many trades that executed properly lower on the list, but we can see that there were many trades where the stop simply didn't happen. Like I said, I know how the Parabolic stop works. This issue isn't about how it works, but that it doesn't seem to have been placed at all.

                  thanks,
                  David
                  Attached Files
                  Last edited by trader3000a; 02-23-2023, 10:27 AM.

                  Comment


                    #10
                    Hello David,

                    Thanks for your note.

                    I have tested the ParabolicStopTest script I shared using the same exact settings in the Strategy Analyzer and see that the parabolic stop is behaving as expected. We can see that when the parabolic stop is reached, the Exit Name column in the Trades Display of the Strategy Analyzer says 'Parabolic stop'. If the Parabolic stop was not reached before it trails and the Exit On Session Close behavior is triggered, the Exit Name column says 'Exit on session close'.

                    Let me know if I may assist further.​
                    Attached Files
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Brandon,
                      I'm not sure why you're showing me your succesful test. I'm glad it works for you, but if you look at my identical test, using your add-on, there are dozens of losing trades in the many thousands of dollars each. I'm asking that you help to figure out what the problem is, but it seems like you're saying that since it worked for you, there's no problem. Can you please pass this to someone else?
                      thanks,
                      David

                      Comment


                        #12
                        Hello David,

                        This is Chelsea the lead of the Engineering Support team stepping in for Brandon.

                        I will do some testing on my end to verify the parabolic stop is working as intended.

                        So that I know specifically the issue you are having, may I clarify what you mean by "fails"?

                        Is this real-time or backtest?
                        Was the order from SetParabolicStop() in a working state?
                        Was the order ignored? (shown in the trace orders)
                        Did the order not move the price you are expecting?
                        What specifically happened to the order?
                        What version of NinjaTrader are you using?

                        May I also have the debugging output from TraceOrders and prints?
                        https://ninjatrader.com/support/foru...121#post791121
                        The order object from OnOrderUpdate() should be in the prints as well to know what happened with the order.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,
                          The parabolic stop works as intended when it is placed. However, during backtesting, there are evident dozens of trades where the parabolic stop failed to initialize once a position was entered, resulting in a position with no stop. The issue arises when I have a large cache, and only when backtesting while connected to rithmic for NT. When testing offline, the issue doesn't occur, despite a large cache.
                          My version is latest.
                          I've cleared the cache and the problem is gone, but will recur soon. Once the issue is recreated, I'll send you the data.
                          thanks,
                          David

                          Comment


                            #14
                            Hello David,

                            When you say no order is submitted, you are seeing the TraceOrder show the set method call setting the method, the entry order filling from the order object printed from OnOrderUpdate(), and no stop order submitted from the order object in OnOrderUpdate(), is this correct?

                            I look forward to receiving the output from prints and trace orders that will show the issue.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea,

                              I've attached files. The stratagy is the one your colleague created, and I added some prints. This test was January 2022 only, but the issue is not isolated to that time frame. You'll see the top 8 trades in the the TradesJanuary snapshot, where they closed out on session close, although the stop should have closed the positions much sooner. Let me know what else you need to help me correct the problem.
                              thanks,

                              David
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by llanqui, Today, 10:32 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              45 responses
                              3,992 views
                              3 likes
                              Last Post johntraderuser2  
                              Started by TAJTrades, Today, 09:46 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post TAJTrades  
                              Started by rhyminkevin, Yesterday, 04:58 PM
                              5 responses
                              62 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Started by realblubb, Today, 09:28 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post realblubb  
                              Working...
                              X