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

Is there a bug in the Heiken Ashi indicator?

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

    Is there a bug in the Heiken Ashi indicator?

    Or am I just missing something?

    I got curious about Heiken Ashi, and one thing led to another. In the end, I was reading the code and found a surprise. Here's the code where they calculate the actual values:

    Code:
                HAClose.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
                HAOpen.Set((HAOpen[1] + HAClose[1]) * 0.5); // Calculate the open
                HAHigh.Set(Math.Max(High[0], HAOpen[0])); // Calculate the high
                HALow.Set(Math.Min(Low[0], HAOpen[0])); // Calculate the low
    HAClose and HAOpen are fine. The other two lines look buggy to me, though.
    • HAHigh should be the maximum of High[0], HAOpen[0], and HAClose[0]
    • HALow should be the minimum of Low[0], HAOpen[0], and HAClose[0]

    Every place I have found on the net, including the original TASC article, agrees on including HAClose[0] in those last two calculations.

    OK -- do we have a bug here? Is there newer wisdom that makes the given calculation correct? Am I just plain missing something?

    --EV
    Last edited by ETFVoyageur; 01-09-2011, 08:33 AM.

    #2
    I have another question. I am trying to understand how the Heiken Ashi indicator works, as a route to understanding more about some indicator things. I do not understand the initial conditional in OnBarUpdate():

    Code:
    if (    Displacement + (CalculateOnBarClose ? 1 : 0) > 0
                         &&    CurrentBar > 0
                         &&    BarColorSeries[1] != Color.Transparent
                    )
                                  InitColorSeries();
    • Displacement is usually zero. That means whether or not this statement will ever call InitColorSeries() is usually gated by how the user sets CalculateOnBarClose.

    • If Displacement is non-zero, CalculateOnBarClose becomes irrelevant. In that case whether or not the conditional can proceed depends is gated by whether the Displacement is positive or negative.

    That makes no sense to me. Any ideas? (In the meantime, I'll search for any HA in the contrib stuff and see what they do.)

    --EV
    Last edited by ETFVoyageur; 01-09-2011, 08:35 AM.

    Comment


      #3
      Hello,

      I will check with product manager, on your questions on how HA should work.

      Thanks for your patience.

      Comment


        #4
        I thought about this a bit further, and realize that the code is correct as is. The answer to my original question is that I missed something. Consider:
        HAClose = (Open + High + Low + Close) / 4
        That means that HAClose can never be higher that High, nor lower than Low. I have no idea why the definition includes them in calculating HAHigh and HALow, but it does -- everywhere I have seen. There is no point to actually coding them in, though, since they can never change the result.

        --EV

        Comment


          #5
          As to the code in my second posting, I proved I never get through the conditional (I routinely have calculate on bar close turned off). So, just to be sure, I have the code in question ifdef'd out and I cannot tell any difference.

          Unless someone comes up with a good explanation for it, I'm just going to assume it was some sort of vestigial thing that is no longer needed -- at least until I find the problem it solves.

          --EV
          Last edited by ETFVoyageur; 01-10-2011, 04:40 AM.

          Comment


            #6
            Hello,

            Ok thanks for letting me know you found the solution here.

            Code is here to protect againt unknown output. Just covering the bases in this case.

            Let me know if I can be of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by f.saeidi, Today, 12:14 PM
            4 responses
            10 views
            0 likes
            Last Post f.saeidi  
            Started by ZenCortexHurry, Today, 01:07 PM
            0 responses
            4 views
            0 likes
            Last Post ZenCortexHurry  
            Started by ZenCortexHurry, Today, 01:04 PM
            0 responses
            3 views
            0 likes
            Last Post ZenCortexHurry  
            Started by Russ Moreland, Today, 12:54 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by philmg, Today, 12:55 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Working...
            X