Amibroker Afl Code
The Formula Editor is your primary workspace for writing AFL code. You can access it through the Tools menu or by right-clicking on any chart pane and selecting "Edit Formula". The Automatic Analysis window is where you'll run scans, backtests, and explorations.
Plot( Close, "Price", colorBlack, styleCandle ); Plot( MA( Close, 20 ), "20-day MA", colorBlue, styleLine );
AFL is used across multiple parts of the AmiBroker environment:
Yet, in the hands of a disciplined mind, AFL becomes poetry. Consider a mean-reversion system on a 1-minute chart:
That is the deep piece on Amibroker AFL — a language that trades not just instruments, but the soul of the trader. amibroker afl code
AmiBroker Formula Language (AFL) is a high-performance scripting language used for technical analysis, backtesting, and automated trading within the AmiBroker platform. It is widely regarded in the trading community for its array-based processing, which allows it to handle large datasets significantly faster than many competitors.
Show you (like RSI or Super Trend) into your AFL code.
SetOption("InitialEquity", 10000); // Starting Capital SetOption("MinShares", 1); // Minimum shares per trade PositionSize = 10; // Invest 10% of current equity // PositionSize = -20; // Invest 20% of equity (negative sign defines %)
AFL syntax is similar to C, using variables, functions, and logical operators. For example, a simple trend-following signal might be written as: The Formula Editor is your primary workspace for
// Define EMAs FastEMA = EMA(Close, 10); SlowEMA = EMA(Close, 20);
// Larry Connors' 2-period RSI system (simplified) RSI2 = RSI(2); Buy = RSI2 < 10 AND Close < MA(Close, 200); Sell = RSI2 > 70;
In traditional programming (like Python with loops), a programmer might write a loop to check a condition for every single day in a chart. In AFL, operations are performed on entire arrays (columns of data) simultaneously.
This creates an array AvgPrice containing the mid-point of each bar's price range. For individual element access, use square brackets: Plot( Close, "Price", colorBlack, styleCandle ); Plot( MA(
// --- Plot indicators --- Plot(C, "Price", colorBlack, styleCandle); Plot(FastMA, "Fast MA", colorBlue, styleLine); Plot(SlowMA, "Slow MA", colorRed, styleLine);
: For truly "deep" features (neural networks), users often export AFL data to Python or R using Amibroker ADK AFL to Python COM links to monitor the values of your features in the Log window or AddColumn() Exploration to see raw numerical outputs for each bar. Performance : AFL is designed for fast array and matrix processing , so avoid
// 4. Plotting SetChartOptions(0, chartShowArrows|chartShowDates); Plot(Close, "C", colorDefault, styleCandle); Plot(MidLine, "BB Mid", colorYellow, styleDashed); Plot(TopBand, "BB Top", colorBlue, styleLine); Plot(BotBand, "BB Bot", colorBlue, styleLine);
A scan returns symbols that meet your conditions: