Skip to main content

Amibroker is considered as one of the most important tool for Traders. It’s widely popular across the globe and aids both discretionary and system traders. It comes bundled with a highly powerful backtesting and optimization engine, apart from the usual charting features. One can code custom indicators and also build a fully automated trading system out of Amibroker. In order to build a trading system through Amibroker you need to be acquainted with Amibroker formula language (Amibroker AFL). It’s a high-level programming language and very easy to understand if you start from basics. Even a person from non-programming background can learn AFL and avoid spending unnecessary on expensive ready-made AFL’s.

Also Read: Getting Started with Amibroker – Features, Pros-Cons & Learning Resources

In this post, we’ll try to learn Amibroker AFL from the scratch with proper examples and downloadable code. I assume that you have already setup Amibroker in your machine and subscribed to live or Historical data feed. Also a basic understanding to Technical analysis and trading terminologies is a pre-requisite for Amibroker coding.

The codes in this and subsequent posts are copy-paste enabled. These are pretty straightforward and complexity will gradually increase. Feel free to comment if you are stuck at any point.

My First Amibroker AFL: Plotting a line chart

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

_SECTION_BEGIN("Basic Line Chart");
Plot(Close,"Price",color=colorBlue,style=styleLine);
_SECTION_END();

Plotting a Candlestick chart

//------------------------------------------------------
//  Formula Name:    Basic Candlestick Chart
//  Author/Uploader: Trading Tuitions
//  E-mail: support@tradingtuitions.com
//  Website:
//------------------------------------------------------

_SECTION_BEGIN("Basic Candlestick Chart");
Plot(Close,"Price",style=styleCandle);
_SECTION_END();

Plotting a Bar Chart

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

_SECTION_BEGIN("Basic Bar Chart");
Plot(Close,"Price",color=colorBlue,style=styleBar);
_SECTION_END();

Plotting price with volume

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

_SECTION_BEGIN("Price");
Plot( C, "Close", colorDefault,styleCandle ); 
_SECTION_END();

_SECTION_BEGIN("Volume");
Plot( Volume, "Volume", color=colorGrey40, ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram  ) );
_SECTION_END();

Customizing chart title

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

_SECTION_BEGIN("Chart with Title");
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);
_SECTION_END();

Leave a Reply