// Calculate RSI rsi = RSI(rsiPeriod);
AFL (Analysis Formula Language) is the scripting language used in AmiBroker – a popular technical analysis and backtesting platform. It allows you to create custom indicators, scans, explorations, trading systems, and backtests. 🧠Basic Syntax & Core Concepts 1. Arrays vs Scalars AFL is array-based – most operations work on entire price series. amibroker afl code
// Entry conditions Buy = Cross(macd, signal) AND rsi < rsiOS; Sell = Cross(signal, macd) OR rsi > rsiOB; // Calculate RSI rsi = RSI(rsiPeriod); AFL (Analysis
ApplyStop(stopTypeLoss, stopModePercent, stopLossPct, True); ApplyStop(stopTypeProfit, stopModePercent, targetPct, True); SetPositionSize(2, spsPercentOfEquity); // 2% risk per trade SetOption("MaxOpenPositions", 5); SetOption("CommissionMode", 1); // per share SetOption("CommissionAmount", 0.01); // $0.01 per share 🧪 Complete Example: MACD + RSI Strategy // MACD parameters fastMACD = 12; slowMACD = 26; signalMACD = 9; // RSI parameters rsiPeriod = 14; rsiOB = 70; rsiOS = 30; Arrays vs Scalars AFL is array-based – most
Short = Sell; // optional shorting Cover = Buy;