Download MetaTrader 5

Is there an error in the Heikin-Ashi indicator ?

To add comments, please log in or register
Avery Horton
312
Avery Horton  

 The Heikin-Ashi technique uses a modified formula:

  • xClose = (Open+High+Low+Close)/4
    Average price of the current bar
  • xOpen = [xOpen(Previous Bar) + Close(Previous Bar)]/2
    o Midpoint of the previous bar
  • xHigh = Max(High, xOpen, xClose)
    o Highest value in the set
  • xLow = Min(Low, xOpen, xClose)
    o Lowest value in the set

Shouldn't the highlighted line have i+1 for the HA calculation

 //--- preliminary calculation

   if(prev_calculated>1)

      pos=prev_calculated-1;

   else

     {

      //--- set first candle

      if(open[0]<close[0])

        {

         ExtLowHighBuffer[0]=low[0];

         ExtHighLowBuffer[0]=high[0];

        }

      else

        {

         ExtLowHighBuffer[0]=high[0];

         ExtHighLowBuffer[0]=low[0];

        }

      ExtOpenBuffer[0]=open[0];

      ExtCloseBuffer[0]=close[0];

      //---

      pos=1;

     }

//--- main loop of calculations

   for(i=pos; i<rates_total; i++)

     {

      haOpen=(ExtOpenBuffer[i-1]+ExtCloseBuffer[i-1])/2;

      haClose=(open[i]+high[i]+low[i]+close[i])/4;

      haHigh=MathMax(high[i],MathMax(haOpen,haClose));

      haLow=MathMin(low[i],MathMin(haOpen,haClose));

      if(haOpen<haClose)

        {

         ExtLowHighBuffer[i]=haLow;

         ExtHighLowBuffer[i]=haHigh;

        }

      else

        {

         ExtLowHighBuffer[i]=haHigh;

         ExtHighLowBuffer[i]=haLow;

        }

      ExtOpenBuffer[i]=haOpen;

      ExtCloseBuffer[i]=haClose;

     }

//--- done

   return(rates_total);

  }

//+------------------------------------------------------------------+


Heikin-Ashi Technique
Heikin-Ashi Technique
  • root
  • www.investopedia.com
A type of candlestick chart that shares many characteristics with standard candlestick charts, but differs because of the values used to create each bar. Instead of using the open-high-low-close (OHLC) bars like standard candlestick charts, the Heikin-Ashi technique uses a modified formula: Close = (Open+High+Low+Close)/4 Open = [Open (previous...
honest_knave
Moderator
2326
honest_knave  

Take a look at the bit of code preceding the snippet you posted. 

   ArraySetAsSeries(ExtLowHighBuffer,false);
   ArraySetAsSeries(ExtHighLowBuffer,false);
   ArraySetAsSeries(ExtOpenBuffer,false);
   ArraySetAsSeries(ExtCloseBuffer,false);
   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
To add comments, please log in or register