Amibroker AFL: Step by Step Tutorial- Part 2

This is Part 2 of Amibroker AFL tutorial series. If you haven’t already gone through Part 1 of this series, please find it in the below link:-

Amibroker AFL: Step by Step Tutorial- Part 1

Parameterized AFL code

//------------------------------------------------------
//  Formula Name:    Parameterized AFL code
//  Author/Uploader: Trading Tuitions
//  E-mail: support@tradingtuitions.com          
//  Website: www.tradingtuitions.com        
//------------------------------------------------------

_SECTION_BEGIN("Parameters");
Plot(Close,"Price",ParamColor("Color",colorBlue),styleLine);
_SECTION_END();

 

Plotting simple EMA Indicator

//------------------------------------------------------
//  Formula Name:    Simple EMA Indicator
//  Author/Uploader: Trading Tuitions
//  E-mail: support@tradingtuitions.com          
//  Website: www.tradingtuitions.com        
//------------------------------------------------------

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

Plot(Close,"Price",color=colorBlue,style=styleCandle);
Plot(EMA(C,50),"EMA50",ParamColor("EMAColor",colorBlue));
_SECTION_END();

Ami_Candle_Chart

 

Plotting parameterized EMA

//------------------------------------------------------
//  Formula Name:    Parameterized EMA
//  Author/Uploader: Trading Tuitions
//  E-mail: support@tradingtuitions.com          
//  Website: www.tradingtuitions.com        
//------------------------------------------------------

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

Plot(Close,"Price",color=colorBlue,style=styleCandle);
EMAPeriod=Param("EMAPeriod",50,1,200,1);
Plot(EMA(C,EMAPeriod),"EMA",ParamColor("EMAColor",colorBlue));
_SECTION_END();

Ami_Bar_Chart

 

Plotting a Heikin Ashi Chart

//------------------------------------------------------
//  Formula Name:    Heikin Ashi Chart
//  Author/Uploader: Trading Tuitions
//  E-mail: support@tradingtuitions.com          
//  Website: www.tradingtuitions.com        
//------------------------------------------------------

_SECTION_BEGIN("Heikin Ashi Chart");
SetChartOptions(0,chartShowArrows | chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));
 
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 ) ); 

barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "HeikinAshi", barcolor, styleCandle );
_SECTION_END();


Ami_Bar_Chart

 

Writing text to Commentary window

//------------------------------------------------------
//  Formula Name:    Commentary
//  Author/Uploader: Trading Tuitions
//  E-mail: support@tradingtuitions.com          
//  Website: www.tradingtuitions.com        
//------------------------------------------------------

_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 ));
Plot( C, "Close", colorDefault,styleCandle ); 
_SECTION_END();

_SECTION_BEGIN("Volume");
Plot( Volume, "Volume", color=colorGrey40, ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram  ) );
writeif( Volume > ma(Volume,5), "The volume is greater than 5 days average. Indicates a good buying opportunity","None");
_SECTION_END();

Ami_Bar_Chart

Leave a Reply

Your email address will not be published. Required fields are marked *