Building Custom AFL Indicators
Up to this point every chart you have looked at was drawn by somebody else. AmiBroker’s
built-in indicators are AFL formulas like any other, and the moment you can write
Plot() yourself, the distinction between “the indicators the software has” and “the
indicators you want” disappears.
This part is about the drawing layer: how a value becomes a line, how a line lands in the
right pane on the right scale, how an event becomes a marker, and how a formula becomes a
tool with knobs on it instead of a file you edit every time you change your mind. Four of
the eight pages are projects, and each of them produces a formula worth keeping in your
Formulas\Custom folder.
What you will be able to do
Section titled “What you will be able to do”By the end of this part you should be able to:
- write a
Plot()call with every argument in the right slot, including the ones people usually leave out; - put an indicator on its own scale, on the left axis, behind the grid, or nowhere at all while still feeding the Data window;
- write a chart title that reports the numbers you care about at the bar you have selected, in the colours you choose;
- mark events on a chart without turning it into a dot-to-dot puzzle;
- expose a formula’s settings through the Parameters dialog with the right control type for each one, and explain why those settings behave differently in an Analysis window;
- build a moving-average tool, a trend-regime classifier, a volatility indicator and a three-band analysis panel, and say honestly what each one can and cannot tell you.
The four projects
Section titled “The four projects”The projects are ordered so that each one adds a technique rather than repeating the last.
The configurable moving average is where the parameter family meets a real formula: a user-defined function that switches between six averaging methods, a slope-driven colour array, and a deliberate blanking of the warm-up bars because not every average tells you when it is still warming up.
The trend regime indicator turns a fuzzy word into an objective classification, then spends as much effort on the classification’s weaknesses as on its construction. A regime classifier built from moving averages and confirmation windows carries lag that cannot be engineered away, and the honest response is to display the lag rather than to hide it.
The ATR volatility indicator deals with the problem of comparing volatility across instruments and across time, which needs both a normalisation and a reference distribution. It also carries a validation trace: a line that must be flat at zero if the tool is right, so the reader can check the arithmetic rather than trusting it.
The multi-indicator analysis panel puts trend, momentum and volatility in one pane using the own-scale trick that professional dashboards are built on. It is also the page where the course is most explicit that three transformations of one price series agreeing with each other is a fact about arithmetic, not a fact about the market.
What you need first
Section titled “What you need first”Part 8 and Part 9. You should be comfortable with the idea that an AFL expression produces
one value per bar, with IIf(), Ref(), Cross() and ExRem(), and with the difference
between a state and an event. If any of those is shaky, the code in the projects will look
like magic rather than like arithmetic.
You need AmiBroker itself and any database with a few years of daily bars. Nothing in this part needs the Professional edition, a real-time feed or a paid subscription; every formula here runs on end-of-day data in the free trial.
How to work through it
Section titled “How to work through it”Read the four lessons in order — each one uses the previous one’s vocabulary, and the projects assume all four. Then do the projects with the Formula Editor open and a chart visible. Every project page follows the same shape: what we are building and why, the complete formula as a downloadable file, a walk through its logic, what you should see, a test procedure that would catch it being wrong, the errors people actually make, and an extension to attempt on your own.
Resist the urge to read the projects without typing anything. The Parameters dialog is the fastest teacher in AmiBroker: change a number, watch the chart redraw, decide whether the change made the tool better or merely different.
0 / 8 lessons in this part completed
Progress tracking needs browser storage, which is unavailable here. The course works exactly the same without it.
- LessonPlotting with Plot(): Styles, Colours and Panes30 min
- LessonChart Titles and Dynamic Text26 min
- LessonPlotShapes() and Visual Signals28 min
- LessonParameters: Param, ParamToggle, ParamList and ParamColor30 min
- ProjectProject: Configurable Moving-Average Indicator45 min
- ProjectProject: Trend Regime Indicator50 min
- ProjectProject: ATR Volatility Indicator45 min
- ProjectProject: Multi-Indicator Analysis Panel60 min