AmiBroker AFL
Learn to code in AFL - the language behind one of the fastest backtesting engines a trader or investor can own. Built for traders and investors alike, it starts from your very first plotted line and builds up to scanners, complete trading systems, backtests and live order automation. No heavy programming - if you can read a chart, you can do this.
Why learn AmiBroker?
AmiBroker is a native C++ analysis platform built for speed. It was the world's first 64-bit technical-analysis program for Windows, its formula engine runs across every core of your CPU, and its charting renders up to forty times faster than before. In practice that means you can scan thousands of symbols or backtest a system over years of history and a basket of stocks in seconds - and that fast feedback is exactly what lets you iterate on an idea. AFL is the small, friendly language that drives all of it: one formula can be an indicator, a market-wide scan, or a full backtested system.
Meet AmiBroker
What AmiBroker is, how the Formula Editor works, and the one idea - arrays - that makes AFL click.
What is AmiBroker & AFL
The big picture - charts, the Analysis window, and the four things AFL can do: indicate, explore, scan and backtest.
The Formula Editor & Your First Indicator
Write, apply and save your first AFL - a one-line RSI plot - and learn the editor habits that save hours.
How AFL Thinks: Arrays & Bars
The single most important idea in AFL - every variable is a whole array of values, one per bar. Get this and everything else is easy.
Price Arrays, Variables & Operators
Meet O, H, L, C, V and Volume, store results in variables, and do maths across an entire chart at once.
The AFL Language
The grammar of AFL - plotting, parameters, built-in functions, logic, looking back, and writing your own functions.
Plotting & Chart Styles
Draw lines, candles, histograms and bands - and control colour, thickness and style like a pro.
Parameters: Interactive Controls
Turn hard-coded numbers into sliders, colour pickers and dropdowns with Param, ParamColor, ParamList and friends.
Built-in Functions & Indicators
A guided tour of the functions you will use every day - MA, EMA, RSI, MACD, ATR, BBands and how to read the function reference.
Conditions, Logic & IIf
Build true/false arrays with comparisons and AND/OR, then choose values bar-by-bar with the all-important IIf.
Looking Back: Ref, Cross & BarsSince
Reach into earlier (and later) bars with Ref, detect crossovers with Cross, and count bars since an event.
Dates, Times & the Trading Session
Read the calendar and the clock - Day, Month, time-of-day - and answer the question every intraday system asks: has a new day started?
Arrays vs Loops: the for-loop
Most AFL needs no loops - but some logic (like a trailing stop) does. Learn when and how to write a clean for-loop.
Custom Functions & Procedures
Package logic you reuse into your own functions and procedures, with local and global scope.
Charting & Visualisation
Make charts that communicate - arrows, colour-coded candles, dynamic titles, multi-pane layouts and GFX dashboards.
Arrows, Shapes & Text
Mark signals on the chart with PlotShapes and PlotText - up arrows, down arrows, stars and labels.
Colours, Ribbons & Conditional Candles
Colour candles by trend, paint background ribbons and build at-a-glance visual context.
The Title Bar & StrFormat
Build a rich, dynamic chart header - name, OHLC, percent change - with Title, StrFormat and WriteIf.
Multiple Panes & Comparing Symbols
Stack indicator panes, and pull in another symbol's data with Foreign and PlotForeign for relative strength.
GFX Dashboards
Draw your own panels - boxes, gradients and text - with the low-level GFX functions for a polished dashboard.
Exploration & Scanning
Screen the whole market at once - the Analysis window, AddColumn, filters and ranking.
Exploration: the Analysis Window
Turn AFL into a spreadsheet over your whole watchlist with Filter and AddColumn.
Building a Signal Scanner
Scan dozens of symbols for a real setup - MACD crosses, RSI extremes and breakouts - and list only the hits.
Filtering, Sorting & Ranking
Sort the results, colour the cells, and rank your universe by strength or volume.
Building Trading Systems
The mechanics of a tradable system - signals, clean entries and exits, stops, targets and sizing.
Buy, Sell, Short & Cover
The four reserved arrays that turn an idea into a system - and how AmiBroker reads them.
Clean Signals: ExRem, Flip & No Repainting
Remove duplicate signals with ExRem, hold state with Flip, and delay one bar so your system never repaints.
Stops, Targets & ApplyStop
Add a stop-loss and profit target - both as visual chart levels and as real backtest exits with ApplyStop.
Position Sizing & Trade Delays
Control how much you trade with SetPositionSize, and when fills happen with SetTradeDelays and SetOption.
Backtesting & Optimisation
Prove an edge before risking capital - run a backtest, read the report, and optimise without fooling yourself.
Your First Backtest
Run a full backtest in the Analysis window, set the date range and settings, and see your equity curve.
Reading the Backtest Report
Make sense of the numbers - net profit, CAR, drawdown, win rate, payoff and the risk-adjusted ratios.
Optimisation & Robustness
Sweep parameters with Optimize(), read the results, and choose robust settings - not just the curve-fit peak.
Strategy Playbook
Five complete, explained systems - each one ready for you to backtest and drop your own report images into.
Strategy: EMA Crossover System
The classic trend system, built end-to-end - signals, arrows, delays and a backtest you can run yourself.
Strategy: Supertrend System
Build the popular ATR-based Supertrend from scratch with a for-loop, plot the trailing stop, and trade it.
Strategy: VWAP Intraday System
An intraday mean-reversion / trend system around VWAP, with time-based entries and a session reset.
Strategy: Donchian / Opening-Range Breakout
Two breakout classics - the Donchian channel and the opening-range breakout - coded and ready to test.
Strategy: RSI Pullback & Mean Reversion
A counter-trend pullback system using RSI with a trend filter - buying dips in an uptrend.
Real-Time, Alerts & Automation
Take a system live - multiple time frames, alerts to your phone, and order automation through OpenAlgo.
Multiple Time Frames
Read a higher time frame on a lower-time-frame chart with TimeFrameSet, TimeFrameGetPrice and friends.
Alerts: Telegram & Voice
Fire alerts the moment a signal triggers - on-chart AlertIf, a Telegram message, and a spoken voice alert.
Automating Orders with OpenAlgo
Send your AFL signals to OpenAlgo to place real orders - button and signal-based automation, in sandbox first.
Where to Go Next
A map of what you have learned, the parts of AFL still to explore, and how to keep getting better.
For education only - not investment advice. Practise in sandbox trading (analyzer mode in OpenAlgo). 36 chapters of AFL, beginner to intermediate.