Beginners Guide To AmiBroker AFL Programming This Book is dedicated to my family members Copyright 2019 by Ajan K K All rights reserved AmiBroker is a Trademark of Amibroker.Com The author has no official partnership with Amibroker.com Contents
Chapter 0 Before Learning AFL Programming
0.1 An Introduction 0.2 What is Amibroker? 0.3 Is AmiBroker easy to Learn? 0.4 The Formula Editor 0.5 The Guru Chart Commentary 0.6 What Next?
Chapter 1 Introduction to AFL
1.1 Language Basics 1.2 Lexical Elements of AFL 1.3 Operator precedence and parentheses 1.4 Variables and Reserved words
Chapter 2 Array Programming
2.1 Why AFL is called an Array Programming Language 2.2 Array Processing in AFL 2.3 Accessing Array Elements. [ ] The subscript operator 2.4 Population of the built-in Arrays 2.5 Creating Arrays Manually
Chapter 3 Functions in AFL
3.1 What are Functions? 3.2 User defined functions 3.3 AmiBroker Built-in functions Chapter 4 Branching and Looping in AFL 4.1 Conditional execution 4.2 Nesting of if statements 4.3 Use of Arrays in if statement 4.4 Looping in AFL 4.5 Switch case statement
Chapter 5 Built-in Functions explored
5.1
Introduction
5.2 The Plot( ) function 5.3 ParamColor( ) function 5.4 ParamStyle( ) function 5.5 Param( ) function 5.6 Ref( ) function 5.7 Indicator Functions 5.8 The Cross( ) function 5.9 HHV Highest High Value 5.10 HHVBars bars since highest high over a period 5.11 Highest highest value 5.12 HighestBars bars since highest value 5.13 HighestSince highest value since condition met 5.14 HighestSinceBars bars since highest value since condition met 5.15 BarsSince 5.16 GapDown 5.17 GapUp 5.18 Inside 5.19 Outside 5.20 BarIndex 5.21 BeginValue 5.22 EndValue 5.23 abs 5.24 ceil 5.25 floor 5.26 int 5.27 frac 5.28 Max and Min 5.29 Round 5.30 Sum 5.31 Cum 5.32 ROC 5.33 ValueWhen 5.34 DayOfWeek 5.35 PlotShapes
Chapter 6 Write Your Own Functions
6.1 User definable functions 6.2 #include Chapter 7 How to make a Watchlist? 7.1 What is a Watchlist? 7.2 Watchlist Creation 7.3 How to add symbols to an existing Watchlist? 7.4 Create a Watchlist by importing from a text file 7.5 A practical example Chapter 8 Create Your Own Exploration 8.1 Explore in AmiBroker 8.2 Customized Report Generation
Chapter 9 Back Testing Trading Strategies
9.1 Introducing Trading Strategies 9.2 Amibroker Environment for Back testing 9.3 Reserved variables used in Back testing 9.4 A Back testing example 9.5 Backtester settings from within AFL code
Chapter 10 Revision Exercises
Chapter 0 Before Learning AFL Programming 0.1 An Introduction Before we start learning AFL Programming, certain clarifications have to be made with regard to whom this course is intended for, the prerequisites and other requirements, if any. The material in this book is intended for the absolute beginner in AFL Programming. Only the most basic aspects of the AFL programming will be dealt with in this book. Experienced AFL programmers may not get anything useful in this book. This Book will not teach anything about Technical Analysis.
No attempt is made in this book to teach Trading Strategies, other than references to it, when coding examples are required to be furnished. To learn AFL, you should have AmiBroker installed in your computer. This book focuses only on the AFL programming part. The reader should know how to load charts, place technical indicators on the chart etc. These are well described in the User Manual of AmiBroker. 0.2 What is AmiBroker? AmiBroker is a complete and advanced trading solution.
It has many tools including Charting, Backtesting, Optimizing etc. You can display Charts, add indicators, create watchlists, create trading strategies and back test these trading strategies, create portfolios etc. It is not a mere Charting tool. Any one showing interest in AmiBroker, means that he is showing interest in learning AFL, or at least should know how to use AFL developed by else body in their trading decisions. 0.3 Is AFL easy to learn? This is a difficult question to answer. The answer is Yes and No.
If you are already proficient in any other programming language, then there should not be any problem. It will be a matter of learning the syntax, keywords, functions etc of the new language. Everything should follow very easily. Otherwise, it should take time there is a learning curve. The fact about AFL is that it is not a general purpose language like C, Pascal, Python etc but only specific to deal with financial quotation values like Close, Open, High, Low, Volume, Open Interest etc. And that AFL is an array programming, will make some confusions to the beginner programmer.
Soon the understanding that an Array is something like the English collective nouns such as a Library of books, a Herd of cattle, a Panel of experts etc. will relieve many of the doubts. An Array is simply a collection of numbers. Anything we do on the Array means, we are intending to do on every member of the Array and not on any single member of the Array. By studying carefully and doing lot of exercises, any beginner can learn AFL and master it. 0.4 The Formula Editor The program statements are entered into an Editor called the Formula Editor.
Like all Windows programs, Amibroker provides multiple ways of launching the Formula Editor. From the Analysis Menu Click the Formula Editor. This will open the Formula Editor as shown below. Fig 0.1 Formula Editor It contains a blank Editor where the formula can be entered. See Fig 0.2 below. 0.2 Editor Options There are three editor options wherein we can check the syntax of the formula, apply the indicator to the chart pane and send the formula to Analysis window. 0.2 Editor Options There are three editor options wherein we can check the syntax of the formula, apply the indicator to the chart pane and send the formula to Analysis window.
After entering the formula to the Editor screen, click the Verify syntax icon. If the formula is violating the syntax of the language, errors will be reported. We can proceed further only after rectifying the errors. An indicator formula or any other formula for plotting can be applied to the charting pane by clicking the Apply to icon. The Analysis window is used for Scanning, Exploration and Back testing etc. See Fig. 0.3 below. 0.3 below.
Fig.0.3 Launch Formula Editor From the Speed Bar buttons displayed, click on the Wrench like icon, to launch the Formula Editor. 0.5 The Guru Chart Commentary This is where we learn and test most of our formulas. There are two ways of launching the Chart Commentary. From Analysis Menu click Commentary or click on the Speed button icon shown in Fig. 0.3 above. Fig. 0.4 Chart Commentary window
Next page