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

The Curious Case of Heiken Ashi Bars

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

    The Curious Case of Heiken Ashi Bars

    Like many traders I have tried to get Heiken Ashi real values so the strategy analyzer could stop lying to us lol. I have added 1 tick secondary timeframe in builder, added 4 ticks of slippage and used NT8 Heiken8 as an input variable for indicators to read from. As of now I have almost given up on making these bars give any kind of realistic outcome during backtest.

    Has ANYONE found a method, code or indicator that works in making Heiken Ashi someone useful when making a strategy with backtesting? The false impression of every strategy being perfect needs to be rectified.
    Last edited by Teebone21; 11-17-2020, 03:59 PM.

    #2
    Hello Teebone21,

    Thank you for your note.

    We'd suggest using the Heiken Ashi Indicator with backtesting. That way, your entries and exits can use the underlying data series for fills, while you can calculate other things in your script using the Heiken Ashi values from the indicator.

    This indicator is publicly available on our NinjaTrader Ecosystem website:Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

    Note — To import NinjaScripts you will need the original .zip file.

    To Import:
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.
    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Once installed, you may add the indicator to a chart by:
    • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK
    Here is a short video demonstration of the import process:Please let me know if I can be of further assistance.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello Teebone21,

      Thank you for your note.

      We'd suggest using the Heiken Ashi Indicator with backtesting. That way, your entries and exits can use the underlying data series for fills, while you can calculate other things in your script using the Heiken Ashi values from the indicator.

      This indicator is publicly available on our NinjaTrader Ecosystem website:Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

      Note — To import NinjaScripts you will need the original .zip file.

      To Import:
      1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
      2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
      3. Select the downloaded .zip file
      4. NinjaTrader will then confirm if the import has been successful.
      Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

      Once installed, you may add the indicator to a chart by:
      • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK
      Here is a short video demonstration of the import process:Please let me know if I can be of further assistance.

      The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
      Should I be using the "Open" value for calculation ?

      Comment


        #4
        Hello Teebone21,

        Thank you for your reply.

        HAOpen would be the plot you'd want to reference if you're using the Heiken Ashi prices for calculations with that indicator. Open[0] would give you the open of the underlying series.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Just found this thread, I was referred to it from elsewhere

          My two cents worth.. as I have some experience doing this stuff.

          Teebone21 is I believe referring in the OP to misleading results arising from back-testing a strategy on Heiken Ashi bars. Well, yeah, and the reason is pretty simple really.
          Unless you do some special coding, the back-test engine, using managed orders, executes orders AT THE OPEN of the next bar. So... how do you think that works with HA bars... where the Open price is a pure fabrication... being the middle of the body of the previous bar?

          Of course, you will get rubbish trade performance, as the trade entry/exits are complete fiction! And the gap between actual market price and the HA bar open price can be huge!
          So much for the "why".

          What to do about it? Well, write your strategy to enter/exit trades at the actual price of the underlying, of course. To do that, you need to have loaded the base symbol series, and use the order entry/exit signature that refers to this data series... eg
          Code:
          EnterLong(1, qty, string)
          where the 1 refers to the added data series (so... will be "1" if you only added one additional series.) Ditto for exits (although the entries are the biggest contributor to false results unless you do this...)

          Hope that helps...
          T.

          Comment


            #6
            Originally posted by tgn55 View Post
            Just found this thread, I was referred to it from elsewhere

            My two cents worth.. as I have some experience doing this stuff.

            Teebone21 is I believe referring in the OP to misleading results arising from back-testing a strategy on Heiken Ashi bars. Well, yeah, and the reason is pretty simple really.
            Unless you do some special coding, the back-test engine, using managed orders, executes orders AT THE OPEN of the next bar. So... how do you think that works with HA bars... where the Open price is a pure fabrication... being the middle of the body of the previous bar?

            Of course, you will get rubbish trade performance, as the trade entry/exits are complete fiction! And the gap between actual market price and the HA bar open price can be huge!
            So much for the "why".

            What to do about it? Well, write your strategy to enter/exit trades at the actual price of the underlying, of course. To do that, you need to have loaded the base symbol series, and use the order entry/exit signature that refers to this data series... eg
            Code:
            EnterLong(1, qty, string)
            where the 1 refers to the added data series (so... will be "1" if you only added one additional series.) Ditto for exits (although the entries are the biggest contributor to false results unless you do this...)

            Hope that helps...
            T.
            Wow that was really good info....
            Should I add this code on all ENTER/EXITS?

            Comment


              #7
              Only applies if you are backtesting "weird" bars... like Heiken Ashi... ANYTHING for which the bar's open/close is not actually the real market price of the symbol you are working with when the bar opens. If you are running a strategy against Heiken Ashi bars.. then yes... do it for all entry/exits that your strategy manages. All standard time-based bars are just fine... even tick-based bars should be fine, there is no monkey business going on behind the scenes to mislead the back-test engine.

              If you are running tests on plain old bars, there is no need to do this, and neither should you do it, since there is some overhead in loading the second dataseries.

              Some other exotic bars also give entirely misleading backtest results...eg UniRenko.

              Really, the important take-away from this is this: You need to understand what is happening when you backtest. Everything I said in my post is documented in Ninja's resources... or elsewhere re Heiken Ashi formula (eg on Investorpedia or similar) You should read up on it... but my little summary above should keep you from going too far astray ;-)

              Cheers,
              T.

              Comment


                #8
                But this HA8 indicator does not give the same OHLC as the HA bars(When you choose DataSereis -> Type -> HA).
                Anyone knows how to get an indicator/code/workaround that will give same OHLC as the HA bars?

                Comment


                  #9
                  Hello somanko,

                  Thank you for your reply.

                  These issues are due to 2 reasons:
                  • Added behavior to round the Heiken Ashi moving average values to TickSize
                  • Issues with the original implementation
                  The difference in Tick Rounding is noted here: http://ninjatrader.com/support/helpG...HeikenAshiBars

                  If you want a "pure" Heiken Ashi study, you could use the Heiken Ashi 8 indicator on the User App Share or the Heiken-Ashi-Accurate BarsType.

                  Heiken Ashi 8 indicator - https://ninjatraderecosystem.com/use...heiken-ashi-8/

                  Heiken Ashi Accurate BarsType - https://ninjatrader.com/support/foru...e-barstype-nt8

                  Essentially, we have found some issues with our Heiken Ashi BarsType late into NinjaTrader 8's life and have made changes publicly available on our User App Share for those who need the Heiken Ashi BarsType more consistent with traditional Heiken Ashi studies. These changes are not included with productions release in effort to not change the behavior of existing scripts that already use the legacy BarsType logic.

                  Please let us know if we may be of further assistance to you.

                  The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    I am new to N8T and am trying to come up to speed quickly with HA8. As I understand it, this native capability in N8T exists; however, I'm also reading about some issues in the past that necessitated a new indicator like an enhanced HA to fix them. Have all of the problems with HA been corrected or should I be importing and using something like the JSHeikenAshi indicator from elsewhere that seems to work perfectly (if I could just figure out how to hide the pricing data in the native data series). So what is the status of HA8?

                    Comment


                      #11
                      Hello fishertodd,

                      Thank you for your note.

                      You can find the definition of Heiken Ashi bars in our help guide:One of the main differences between the built in Heiken Ashi bars and the Heiken Ashi 8 indicator would be that the indicator is designed to work with non-time based intervals, and does not round values to the tick size as the built in bars do.

                      The Heiken-Ashi bar type presents false information concerning each candle as well, which can cause issues in backtesting.

                      Here is how the Heiken-ashi is calculated:
                      HAClose = ((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
                      HAOpen = ((HAOpen[1] + HAClose[1]) * 0.5); // Calculate the open
                      HAHigh = (Math.Max(High[0], HAOpen[0])); // Calculate the high
                      HALow = (Math.Min(Low[0], HAOpen[0])); // Calculate the low

                      When you place an order it can only fill on real price data.

                      The strategy analyzer does not know what the base data is that created the Heiken-Ashi bar and it will backtest based on the false information presented.

                      This is where the indicator comes into play. In a backtest, the workaround for the above issue be to use the indicator HeikenAshi8 in your strategy calculations and use standard bars in the chart/analyzer so that the backtest results are based on real data points and your strategy can use the Heiken-ashi values for the conditional entries.

                      I cannot comment on other third party scripts accuracy.

                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        So except for backtesting, the data displays as a HA chart should, using the built-in HA bars, i.e., with the correct HA candle values represented in each candle?

                        Comment


                          #13
                          Hello fishertodd,

                          Thank you for your reply.

                          The difference would be that the built in HA bars will round their values to the nearest tick, whereas the indicator will give the raw HA values.

                          We can see this if we compare a chart with the built in HA bar type versus a chart using the indicator:

                          Click image for larger version

Name:	2022-03-10_10-40-58.png
Views:	1472
Size:	77.6 KB
ID:	1193238

                          The above is the built in HA bars, while below demonstrates the values returned from the indicator:

                          Click image for larger version

Name:	2022-03-10_10-42-29.png
Views:	1351
Size:	89.6 KB
ID:	1193239

                          Please let us know if we may be of further assistance to you.
                          Kate W.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by tgn55 View Post
                            Just found this thread, I was referred to it from elsewhere

                            My two cents worth.. as I have some experience doing this stuff.

                            Teebone21 is I believe referring in the OP to misleading results arising from back-testing a strategy on Heiken Ashi bars. Well, yeah, and the reason is pretty simple really.
                            Unless you do some special coding, the back-test engine, using managed orders, executes orders AT THE OPEN of the next bar. So... how do you think that works with HA bars... where the Open price is a pure fabrication... being the middle of the body of the previous bar?

                            Of course, you will get rubbish trade performance, as the trade entry/exits are complete fiction! And the gap between actual market price and the HA bar open price can be huge!
                            So much for the "why".

                            What to do about it? Well, write your strategy to enter/exit trades at the actual price of the underlying, of course. To do that, you need to have loaded the base symbol series, and use the order entry/exit signature that refers to this data series... eg
                            Code:
                            EnterLong(1, qty, string)
                            where the 1 refers to the added data series (so... will be "1" if you only added one additional series.) Ditto for exits (although the entries are the biggest contributor to false results unless you do this...)

                            Hope that helps...
                            T.
                            Hi,
                            It looks like you have worked with many of the issues that I am trying to sort out.
                            I understand the rationale to amend the code to refer to the real life data series, eg
                            Code:
                            EnterLong(1, qty, string)
                            where the 1 refers to the added data series

                            Have you figured out how to successfully apply real life results to backtesting Heiken Ashi strategies?

                            Best regards,
                            Dan

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by judysamnt7, 03-13-2023, 09:11 AM
                            4 responses
                            57 views
                            0 likes
                            Last Post DynamicTest  
                            Started by ScottWalsh, Today, 06:52 PM
                            4 responses
                            36 views
                            0 likes
                            Last Post ScottWalsh  
                            Started by olisav57, Today, 07:39 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post olisav57  
                            Started by trilliantrader, Today, 03:01 PM
                            2 responses
                            19 views
                            0 likes
                            Last Post helpwanted  
                            Started by cre8able, Today, 07:24 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post cre8able  
                            Working...
                            X