Announcement

Collapse
No announcement yet.

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.
      BrettNinjaTrader Product Management

      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.
            BrettNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            579 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X