Мы на Workspace

Mastering AmiBroker AFL Code: The Ultimate Guide to Automated Trading Systems

Introduction: Why AFL is the Backbone of AmiBroker

In the world of retail trading, speed, accuracy, and backtesting reliability separate the winners from the spectators. AmiBroker has stood as a titan in the technical analysis space for nearly two decades. Its secret weapon? AFL (AmiBroker Formula Language) .

This article is a deep dive into AFL. We will cover everything from basic syntax to advanced optimization techniques, realistic code examples, and the hidden "gotchas" that destroy inexperienced coders.

// 1. Parameters period = Param("RSI Period", 14, 2, 50, 1); overbought = Param("Overbought Level", 70, 50, 90, 1); oversold = Param("Oversold Level", 30, 10, 50, 1); // 2. Indicator Logic rsiValue = RSI(period); // 3. Trading Rules Buy = Cross(rsiValue, oversold); // Enter when RSI crosses above oversold Sell = Cross(rsiValue, overbought); // Exit when RSI crosses above overbought // Prevent multiple consecutive signals Buy = ExRem(Buy, Sell); Sell = ExRem(Sell, Buy); // 4. Visuals Plot(rsiValue, "RSI", colorBlue, styleLine); Plot(overbought, "OB", colorRed, styleDashed); Plot(oversold, "OS", colorGreen, styleDashed); PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, Low, -15); PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorRed, 0, High, -15); // 5. Backtest Settings SetPositionSize(10, spsPercentOfEquity); // Risk 10% of equity per trade Use code with caution. Copied to clipboard Installation and Usage

// --- Real-time Position Tracker ---
staticVar = Nz(StaticVarGet("MyPosition"), 0);
currentPos = staticVar;

// Built-in price arrays Open, High, Low, Close, Volume, OpenInt

Уважаемые клиенты!

В связи с майскими праздничными днями информируем вас об изменениях в графике работы: