Skip to main content

Amibroker AFL Tutorial Series: Part 2

Welcome to Part 2 of our Amibroker AFL tutorial series. If you missed Part 1, catch up here to stay on track.

Introducing Parameterized AFL Code

				
					//------------------------------------------------------
//  Formula Name:    Parameterized AFL code
//  Website: https://zerobrokerageclub.com/        
//------------------------------------------------------

_SECTION_BEGIN("Parameters");
Plot(Close,"Price",ParamColor("Color",colorBlue),styleLine);
_SECTION_END();
				
			
Ami_Parameters Recommended Reading: Mastering Amibroker – A Comprehensive Guide

Crafting a Simple EMA Indicator

				
					//------------------------------------------------------
//  Formula Name:    Parameterized AFL code
//  Website: https://zerobrokerageclub.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, SelectedValue( ROC( C, 1 ) ) ));


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

Creating a Parameterized EMA Chart

				
					//------------------------------------------------------
//  Formula Name:    Parameterized AFL code
//  Website: https://zerobrokerageclub.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, SelectedValue( ROC( C, 1 ) ) ));


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_Param_EMA

Designing a Heikin Ashi Chart in AFL

				
					//------------------------------------------------------
//  Formula Name:    Parameterized AFL code
//  Website: https://zerobrokerageclub.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, SelectedValue( ROC( C, 1 ) ) ));

 
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_Heikin_Ashi

Adding Commentary to Your Charts

				
					//------------------------------------------------------
//  Formula Name:    Parameterized AFL code
//  Website: https://zerobrokerageclub.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, SelectedValue( ROC( C, 1 ) ) ));

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_Commentary

2 Comments

Leave a Reply