Smoothed Heikin Ashi for Amibroker?

#1
Does anyone have the AFL for Smoothed Heiken Ashi indicator which is available on Metatrader. It is one of the best indicators I have ever seen - is also much better than the Standard Heikin Ashi.

Thanks in advance for your help
 
#2
Does anyone have the AFL for Smoothed Heiken Ashi indicator which is available on Metatrader. It is one of the best indicators I have ever seen - is also much better than the Standard Heikin Ashi.

Thanks in advance for your help
not sure wht u have seen on metatrader.... but see if this helps

SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );

regds
raminder
 
#3
Thanks for your suggestion. Am posting the MQ5 indicator

//+------------------------------------------------------------------+
//| iHeikenAshiSm.mq5 |
//| Integer |
//| http://dmffx.com |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link "http://dmffx.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 17
#property indicator_plots 1
//--- plot HeikenAshi
#property indicator_label1 "HeikenAshi"
#property indicator_color1 DodgerBlue,Red
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1

enum eType
{
CANDLES=DRAW_COLOR_CANDLES,
BARS=DRAW_COLOR_BARS
};

enum eVar
{
HeikenAshi=0,
Price=1
};

/*
The Heiken Ashi indicator with smoothing.
Depending on the parameter TYPE (BARS,CANDLES) it can be plotted as bars or candles.
Depending on the parameter Variant (HeikenAshi,Price) it can plot HeikenAshi bars
or conventional candles, painted as Heiken Ashi bars.

Parameters:

Variant - bars to plot (candles): barsы (candles) Heiken Ashi or standard price bars (candles);
Type - drawing type: bars or candles;
MAPeriod - МА period;
MAMethod - МА method: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA;
SmPeriod - smoothing period;
SmMethod - smoothing method: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA.
*/

//--- input parameters
input eVar Variant = HeikenAshi; /*Variant*/ // Heiken Ashi or price
input eType Type = CANDLES; /*Type*/ // drawing type - bars or candles
input int MAPeriod = 1; /*MAPeriod*/ // МА period
input ENUM_MA_METHOD MAMethod = MODE_SMA; /*MAMethod*/ // МА method: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA
input int SmPeriod = 1; /*SmPeriod*/ // Smoothing period
input ENUM_MA_METHOD SmMethod = MODE_SMA; /*SmMethod*/ // Smoothing method: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA

//--- indicator buffers
double HeikenAshiBuffer1[];
double HeikenAshiBuffer2[];
double HeikenAshiBuffer3[];
double HeikenAshiBuffer4[];
double HeikenAshiColors[];

double OpenMABuffer[];
double HighMABuffer[];
double LowMABuffer[];
double CloseMABuffer[];

double _open[];
double _high[];
double _low[];
double _close[];

double _openSm[];
double _highSm[];
double _lowSm[];
double _closeSm[];

int OpenMAHandle,HighMAHandle,LowMAHandle,CloseMAHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping

PlotIndexSetInteger(0,PLOT_DRAW_TYPE,Type);

SetIndexBuffer(0,HeikenAshiBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,HeikenAshiBuffer2,INDICATOR_DATA);
SetIndexBuffer(2,HeikenAshiBuffer3,INDICATOR_DATA);
SetIndexBuffer(3,HeikenAshiBuffer4,INDICATOR_DATA);
SetIndexBuffer(4,HeikenAshiColors,INDICATOR_COLOR_INDEX);

SetIndexBuffer(5,OpenMABuffer,INDICATOR_DATA);
SetIndexBuffer(6,HighMABuffer,INDICATOR_DATA);
SetIndexBuffer(7,LowMABuffer,INDICATOR_DATA);
SetIndexBuffer(8,CloseMABuffer,INDICATOR_DATA);

SetIndexBuffer(9,_open,INDICATOR_DATA);
SetIndexBuffer(10,_high,INDICATOR_DATA);
SetIndexBuffer(11,_low,INDICATOR_DATA);
SetIndexBuffer(12,_close,INDICATOR_DATA);

SetIndexBuffer(13,_openSm,INDICATOR_DATA);
SetIndexBuffer(14,_highSm,INDICATOR_DATA);
SetIndexBuffer(15,_lowSm,INDICATOR_DATA);
SetIndexBuffer(16,_closeSm,INDICATOR_DATA);

PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
PlotIndexSetInteger(1,PLOT_SHOW_DATA,false);
PlotIndexSetInteger(2,PLOT_SHOW_DATA,false);
PlotIndexSetInteger(3,PLOT_SHOW_DATA,false);

OpenMAHandle=iMA(_Symbol,PERIOD_CURRENT,MAPeriod,0,MAMethod,PRICE_OPEN);
HighMAHandle=iMA(_Symbol,PERIOD_CURRENT,MAPeriod,0,MAMethod,PRICE_HIGH);
LowMAHandle=iMA(_Symbol,PERIOD_CURRENT,MAPeriod,0,MAMethod,PRICE_LOW);
CloseMAHandle=iMA(_Symbol,PERIOD_CURRENT,MAPeriod,0,MAMethod,PRICE_CLOSE);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
static bool error=true;
int start,start2,start3;
int begin2;
int beginX;
if(prev_calculated==0)
{
error=true;
}
if(error)
{
start=MAPeriod;
begin2=start;
start2=begin2;
start3=start2;
beginX=start3;
error=false;
ArrayInitialize(HeikenAshiBuffer1,EMPTY_VALUE);
ArrayInitialize(HeikenAshiBuffer2,EMPTY_VALUE);
ArrayInitialize(HeikenAshiBuffer3,EMPTY_VALUE);
ArrayInitialize(HeikenAshiBuffer4,EMPTY_VALUE);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MAPeriod+SmPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,MAPeriod+SmPeriod);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,MAPeriod+SmPeriod);
PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,MAPeriod+SmPeriod);
}
else
{
start=prev_calculated-1;
start2=start;
start3=start;
}

if(CopyBuffer(OpenMAHandle,0,0,rates_total-start,OpenMABuffer)==-1)
{
error=true;
return(0);
}
if(CopyBuffer(HighMAHandle,0,0,rates_total-start,HighMABuffer)==-1)
{
error=true;
return(0);
}
if(CopyBuffer(LowMAHandle,0,0,rates_total-start,LowMABuffer)==-1)
{
error=true;
return(0);
}
if(CopyBuffer(CloseMAHandle,0,0,rates_total-start,CloseMABuffer)==-1)
{
error=true;
return(0);
}
if(start2==begin2)
{
_open[start2]=OpenMABuffer[start2];
_high[start2]=HighMABuffer[start2];
_low[start2]=LowMABuffer[start2];
_close[start2]=CloseMABuffer[start2];
start2++;
}
for(int i=start2;i<rates_total;i++)
{
_close=(OpenMABuffer+HighMABuffer+LowMABuffer+CloseMABuffer)/4;
_open=(_open[i-1]+_close[i-1])/2;
_high=MathMax(HighMABuffer,MathMax(_open,_close));
_low=MathMin(LowMABuffer,MathMin(_open,_close));
}
fMAOnArray2(_open,_openSm,SmPeriod,SmMethod,beginX,start3,rates_total);
fMAOnArray2(_high,_highSm,SmPeriod,SmMethod,beginX,start3,rates_total);
fMAOnArray2(_low,_lowSm,SmPeriod,SmMethod,beginX,start3,rates_total);
fMAOnArray2(_close,_closeSm,SmPeriod,SmMethod,beginX,start3,rates_total);
if(Variant==HeikenAshi)
{
for(int i=start3;i<rates_total;i++)
{
HeikenAshiColors=HeikenAshiColors[i-1];
HeikenAshiBuffer1=_openSm;
HeikenAshiBuffer2=MathMax(_highSm,MathMax(_openSm,_closeSm));
HeikenAshiBuffer3=MathMin(_lowSm,MathMin(_openSm,_closeSm));
HeikenAshiBuffer4=_closeSm;
if(_closeSm<_openSm)HeikenAshiColors=1;
if(_closeSm>_openSm)HeikenAshiColors=0;
}
}
else
{
for(int i=start3;i<rates_total;i++)
{
HeikenAshiColors=HeikenAshiColors[i-1];
HeikenAshiBuffer1=open;
HeikenAshiBuffer2=high;
HeikenAshiBuffer3=low;
HeikenAshiBuffer4=close;
if(_closeSm<_openSm)HeikenAshiColors=1;
if(_closeSm>_openSm)HeikenAshiColors=0;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| fMAOnArray2 |
//+------------------------------------------------------------------+
void fMAOnArray2(const double &aData[],double &aMA[],int aPeriod,int aMethod,int aBegin,int aStart,int aRatesTotal)
{
double p1;
double p2;
double tWS=0;
switch(aMethod)
{
case MODE_SMA:
aStart=MathMax(aStart,aBegin+aPeriod);
for(int i=aStart;i<aRatesTotal;i++)
{
if(i==aBegin+aPeriod)
{
aMA=0;
for(int j=0;j<aPeriod;j++)
{
aMA+=aData[i-j];
}
aMA/=aPeriod;
}
else
{
aMA=aMA[i-1]-(aData[i-aPeriod]-aData)/aPeriod;
}
}
break;
case MODE_EMA:
if(aStart==aBegin)
{
aMA[aBegin]=aData[aBegin];
aStart++;
}
p1=2.0/(1.0+aPeriod);
p2=(1.0-p1);
for(int i=aStart;i<aRatesTotal;i++)
{
aMA=p1*aData+p2*aMA[i-1];
}
break;
case MODE_LWMA:
aStart=MathMax(aStart,aBegin+aPeriod);
tWS=(1.0+aPeriod)/2.0*aPeriod;
for(int i=aStart;i<aRatesTotal;i++)
{
aMA=0;
for(int j=0;j<aPeriod;j++)
{
aMA+=aData[i-j]*(aPeriod-j);

}
aMA/=tWS;
}
break;
case MODE_SMMA:
if(aStart==aBegin)
{
aMA[aBegin]=aData[aBegin];
aStart++;
}
p1=1.0/aPeriod;
p2=(1.0-p1);
for(int i=aStart;i<aRatesTotal;i++)
{
aMA=p1*aData+p2*aMA[i-1];
}
break;
}
}
//+------------------------------------------------------------------+
//| fMADrawBegin |
//+------------------------------------------------------------------+
int fMADrawBegin(int aPeriod,int aMethod)
{
switch(aMethod)
{
case 1: return(10*aPeriod);
case 2: return(20*aPeriod);
}
return(aPeriod);
}
//+------------------------------------------------------------------+



This gives a very good smoothened trend
 
#4
Thanks for your help. Could you please check iHeikenAshiSm.mq5 in the MQL5 website - it provides the details of the smoothing.

It is an awesome indicator.
 
#5
I do not know about mq5 formula.

I give below heikin ashi smoothed afl ,which I had copied.




_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
//Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Heiken Ashi Smoothed");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
p=Param("Period",6,2,30,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 );
_SECTION_END();
Line=ParamToggle("Show Line chart also","Hide|Show",0);
if(Line==1) {
Plot(C,"Close",colorBlack,styleLine);
}

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


Hope you find this useful.

Further, I request you to give details as to how you use this, for our information.

Thanks
 
#6
Dear Sir,

Thank you for sharing a formula. I am not sure if it is right formula. The Smoothened Heiken Ashi method helps you get into a trend that is definitely forming and helps you also stay with the trend till it is exhausted. I am pasting below an image of a standard Candlesticks chart (in black and white candles) along with the Smoothened Heiken Ashi candles (blue indicates uptrend and red indicates downtrend). You can see for yourself if you entered at the first blue, you could have stayed in it for a long time to capture most of the uptrend.

 
#7
Just wanted to add the the size of the body in the candle helps you understand the strength of a trend. If you see a large blue body with a small tail being formed and the body size keeps getting progressively smaller, it is pointing to exhaustion of momentum of the trend and you can even plan and get out before a red candle is formed (or in the case of a downtrend, before a blue candle is formed)
 
#8
Just wanted to add the the size of the body in the candle helps you understand the strength of a trend. If you see a large blue body with a small tail being formed and the body size keeps getting progressively smaller, it is pointing to exhaustion of momentum of the trend and you can even plan and get out before a red candle is formed (or in the case of a downtrend, before a blue candle is formed)
Thank you, Babubhai. Can you give more information on how to interpret these candles ?? I see them in MT4 but have no idea how to read them.

 
#9
Dear Sir,

Thank you for sharing a formula. I am not sure if it is right formula. The Smoothened Heiken Ashi method helps you get into a trend that is definitely forming and helps you also stay with the trend till it is exhausted. I am pasting below an image of a standard Candlesticks chart (in black and white candles) along with the Smoothened Heiken Ashi candles (blue indicates uptrend and red indicates downtrend). You can see for yourself if you entered at the first blue, you could have stayed in it for a long time to capture most of the uptrend.


I am not able to see your chart. Can you put up image shack picture?

Thanks


I am enclosing picture from my slightly modified afl for information.

changes are as follows
from parameters, period=25 and show linechart
and added 5sma in red.

full afl is as follows









_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
//Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
//Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Heiken Ashi Smoothed");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;
p=Param("Period",6,2,30,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 );
_SECTION_END();
Line=ParamToggle("Show Line chart also","Hide|Show",0);
if(Line==1) {
Plot(C,"Close",colorWhite,styleLine);
}


a=LinearReg(HaClose, 5 ) ;
b=LinearReg( HaClose, 5 ) ;

Plot( IIf(HaHigh>HaOpen,a,b), _DEFAULT_NAME(), colorRed, ParamStyle("Style") );

Plot( LinearReg( HaOpen, 5 ), _DEFAULT_NAME(), colorWhite, ParamStyle("Style") );


_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();



_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 900, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
//Hor=Param("Horizontal Position",800,800,800,800);

Hor=Param("Horizontal Position",500,500,200,20);




Ver=Param("Vertical Position",50,50,250,50);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();




_SECTION_BEGIN("Price Line");

PriceLineColor=ParamColor("PriceLineColor",ColorRGB(82,82,82));
PriceLevel = ParamField("PriceField", field = 3 );

Daysback = Param("Bars Back",100,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));


side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorLightBlue );
}


_SECTION_END();


/*
_SECTION_BEGIN("Linear Regression");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( LinearReg( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Linear Regression1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( LinearReg( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

*/





_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

//Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//(Title = StrFormat(" - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));

(Title = StrFormat("{{DATE}} O %g, H %g, L %g,
C %g (%.1f%%) ", O, H, L, C ) )
//+"\n"+EncodeColor(colorPink)+"-----------------------------------------"
//+"\n"+EncodeColor(colorOrange)+"The Sultan Foundation v 13.01 Int"
//+"\n"+EncodeColor(colorLightOrange)+"by Sultanji "
//+"\n"+EncodeColor(colorPink)+"-----------------------------------------"


//+"\n"+EncodeColor(colorOrange)+"If bright green candle BUY and If red candle SELL" )
//+"\n"+EncodeColor(colorLightOrange)+"by Sultanji "
;

_SECTION_END();







 
Last edited:

Similar threads