Heikin Ashi formula problem

Hi!
I have created the code below:

_SECTION_BEGIN("HEIKIN ASHI EXPLORE 2");
NNClose[0] = (Open[0]+High[0]+Low[0]+2*Close[0]) / 5;
NNOpen[0] = Open[0];
NNHigh[0] = NNOpen[0];
NNLow[0] = Min( Low[0], Min( NNClose[0], NNOpen[0] ) );

for (i=1; i<BarCount; i++)
{
NNClose[i] = (Open[i]+High[i]+Low[i]+Close[i]*2) / 5;
NNopen[i] = (NNOpen[i-1] + NNClose[i-1]) / 2; // Here is the problem when using Arrays: Haopen always uses its own previous value
NNHigh[i] = MA(NNOpen[i],5);
NNLow[i] = MA(NNClose[i],5);
}

barcolor = IIf(NNClose >= NNOpen,colorGreen,colorRed);
PlotOHLC( NNOpen, NNHigh, NNLow, NNClose, "", barcolor, styleCandle );

_SECTION_END();

I get an error message for NNHigh and NNLow.

How can I solve this problem to calculate this NNHigh and NNLow?

Thank You,

/Leif Axelsson
Sweden

@AsaLeffe I already gave you a link to the correct method for coding Heikin-Ashi.

Your code is incorrect and you keep refusing to acknowledge, or use (or thank me for) the correct code.

I looked at the free intro to your favorite book and the tiny modification of the original Heikin Ashi results in a difference of less than 0.01% over hundreds of securities and thousands of bars per security. For example this summary run on 100 stocks over 2,500 bars showing the average original HaClose, modified, and the average difference.

image

Really why bother? I guess the author had to sell some books.

Use the original and you'll be fine. Or take the original and make the one tiny modification (double weighting the Close) and you will still be fine.

Good luck!

4 Likes

Hi!

Thank You for Your suggestions. Finally it my code works!

/Leif