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

Heikin Ashi Indicator

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

    Heikin Ashi Indicator

    It appears there is a disparity between the Heikin Ashi calculation by Ninjatrader and that of Dan Valcu's original article in S&C Feb 2004. Specifically the calculation of the maximum high and minimum low as follows;
    haHigh = Maximum(H, haOpen, haClose)
    haLow = Minimum(L, haOpen, haClose)

    The Heiken Ashi indicator in Ninjatrader does not use the haClose in these calculations. Not being a programmer, when I add the "HAClose" to lines 75 and 76, I get an error. The Math.Max and Math.Min take 2 arguments and not 3 and here I have added a 3rd. Can someone please offer a simple correction? Thanks.
    Attached Files

    #2
    Hello Wi!s0n,
    Thanks for your note.

    I will forward your feedback to development for future consideration.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by Wi!s0n View Post
      It appears there is a disparity between the Heikin Ashi calculation by Ninjatrader and that of Dan Valcu's original article in S&C Feb 2004. Specifically the calculation of the maximum high and minimum low as follows;
      haHigh = Maximum(H, haOpen, haClose)
      haLow = Minimum(L, haOpen, haClose)

      The Heiken Ashi indicator in Ninjatrader does not use the haClose in these calculations. Not being a programmer, when I add the "HAClose" to lines 75 and 76, I get an error. The Math.Max and Math.Min take 2 arguments and not 3 and here I have added a 3rd. Can someone please offer a simple correction? Thanks.
      Math.Max and Math.Min are pairwise operators. You have to use successive invocations to use them to evaluate multiple values.

      Code:
      [FONT=Courier New]HAHigh.Set(Math.Max(HAClose[[COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], Math.Max(High[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], HAOpen[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]]))); [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]// Calculate the high[/COLOR][/FONT][/COLOR][/FONT]
      [FONT=Courier New]HALow.Set(Math.Min(HAClose[[COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], Math.Min(Low[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]], HAOpen[[/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]]))); [/FONT][FONT=Courier New][COLOR=#008000][FONT=Courier New][COLOR=#008000]// Calculate the low[/COLOR][/FONT][/COLOR][/FONT]
      However, analysis of the logic of the math of the equations shows that it really is not necessary to make that evaluation. For the HAHigh, you are seeking the maximum value of the High, HAOpen, and HAClose on the same bar. The HAClose can NEVER be higher than the High, so there is no need to evaluate if it is. Similarly, the HAClose can NEVER be lower than the Low, so there is no need to evaluate that either, for the HALow.

      The fact that the original describer of the technique did not realize the redundancy in the math, does not preclude coding the conditions more efficiently.

      IOW, the only reason that I posted the code, is to demonstrate how to find the Max or Min value of multiple variables. In the particular case of the Heiken Ashi, using that code goes beyond pointless: it actually increases the complexity of the evaluation, and, to boot, CPU utilization, to no effective purpose. Granted the cost of one extra evaluation is miniscule in the grand scheme of things, it is still a bad idea to write code that is absolutely useless in terms of evaluation of its ultimate goal.
      Last edited by koganam; 02-05-2022, 10:12 AM.

      Comment


        #4
        Thank you, Koganam

        Certainly a more thoughtful and respectful reply than simply, "I will forward your feedback to development for future consideration."

        Comment


          #5
          Hello Wi!s0n,
          We modified the indicator and tested it further. However functionally we didnt find any difference.

          I am attaching the modified indicator. Please let us know if you find any difference between the original HeikenAshi indicator and the modified (HeikenAshi1) indicator.
          Attached Files
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Thank you Joydeep.

            Comment


              #7
              Originally posted by NinjaTrader_Joydeep View Post
              Hello Wi!s0n,
              We modified the indicator and tested it further. However functionally we didnt find any difference.

              I am attaching the modified indicator. Please let us know if you find any difference between the original HeikenAshi indicator and the modified (HeikenAshi1) indicator.
              Just curious, but what was the point? I have already given a detailed mathematical explanation of why the modification to test the Close is unnecessary. In point of fact, not just unnecessary, but actually bad practice.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rjbtrade1, 11-30-2023, 04:38 PM
              2 responses
              72 views
              0 likes
              Last Post DavidHP
              by DavidHP
               
              Started by suroot, 04-10-2017, 02:18 AM
              5 responses
              3,021 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Stanfillirenfro, Today, 07:23 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cmtjoancolmenero, Yesterday, 03:58 PM
              3 responses
              22 views
              0 likes
              Last Post cmtjoancolmenero  
              Started by olisav57, Yesterday, 07:39 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X