Amibroker AFL: Step by Step Tutorial- Part 1

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.

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();

Ami_Candle_Chart

 

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();

Ami_Bar_Chart

 

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();

Ami_Bar_Chart

 

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 ));
Plot(Close,"Price",color=colorBlue,style=styleCandle);
_SECTION_END();

Ami_Bar_Chart

I hope now you are comfortable with the basic AFL syntax. Give it a try yourself in Amibroker, try changing few parameters in AFL functions and see how it would change the chart. We’ll soon come up with Part-2 of this tutorial series.

12 Comments

  1. Hello Sir, I am New to Amibroker,is there a way where we can use amiboker freely using historical data or we have to use it only after paying it.Could you please let me know .

  2. I found your article very good.
    I do not have any knowledge about coding.
    Can you people help in creating strategy ?

  3. I want to start intraday. Which will be the best version of amibroker. What should be the configuration of PC. Thank u.

Leave a Reply

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