Dear happy singh ji,
i want the close line in this afl to be blue when it is above heiken ashi and red when it is below heiken ashi price
_SECTION_BEGIN("Heiken Ashi");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
p=Param("Period",6,2,40,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
Plot(C,"Close",colorBlue,styleThick);
_SECTION_END();
i want the close line in this afl to be blue when it is above heiken ashi and red when it is below heiken ashi price
_SECTION_BEGIN("Heiken Ashi");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
p=Param("Period",6,2,40,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);
HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
Plot(C,"Close",colorBlue,styleThick);
_SECTION_END();
First point
I hope you know that Heiken Ashi is not meant to compute moving average candle prices over few past days ... Code in the AFL doing that is highlighted in red. While this does not make this AFL wrong automatically, but you should be aware of the deviation being made ...
It was first thing I noticed as being off in your formula and checked up my references. You can read about Heiken Ashi here
Second Point
Close line that you had plotted in your AFL will never be above or below the Heiken Ashi's (as in never be above the Heiken's Ashi's High).
But, Heiken Ashi's Close may be below or above the actual close once in a while.... That is plotted here ...
Here is Heiken Ashi implemented as mentioned in stockcharts.com
Code:
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
HaClose = Close;
HaOpen = Open;
HaHigh = High;
HaLow = Low;
for (i = 1; i < BarCount; i++)
{
HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i])/4;
HaOpen[i] = [B](HAClose[i - 1][/B] + HaOpen[i - 1]) / 2;
HaHigh[i] = Max(Max(HAClose[i], HaOpen[i]), High[i]);
HaLow[i] = Min(Min(HAClose[i], HaOpen[i]), Low[i]);
}
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
Plot(C,"Close",[B][U]IIf(HaClose >= Close, colorBlue, colorRed)[/U][/B], styleThick);
Last edited: