Exploration allows you to view your variables in a spreadsheet format. This is the standard for verifying backtest logic.
Can integrate with broker APIs via third-party "bridges" for live trading.
| Pitfall | Why It’s Problematic | How to Avoid | | :--- | :--- | :--- | | | Positive arguments reference future bars, introducing look‑ahead bias and invalid backtest results. | Always use a negative argument to refer to past data. | | Array arguments in if statements | if requires a single scalar value. Passing an array is syntactically allowed but logically ambiguous and will not work as expected. | Use LastValue(array) or reference a specific index ( array[index] ) to get a scalar. | | Hard‑coded bar counts in loops | The code will crash with Error 10 if a symbol has fewer bars than the hard‑coded limit. | Loop from 0 to BarCount-1 , or check if(BarCount > 300) first. | | Misusing IIf() for strings | IIf() returns an array, not a string. Using it for text generation will produce unexpected results. | Use WriteIf() for conditional string outputs. | | Forgetting that parameters are not automatically reset | When pasting a new strategy over an existing one, old parameter values can persist and corrupt your test. | Click the "Reset all" button in the Parameters dialog before running a new backtest. | | Using Notepad or external editors | Saving code with Notepad may inadvertently change the file extension to .txt , and external editors may not save changes automatically before a backtest. | Always use the built‑in AFL Editor; the Analysis window automatically saves the current file when you run a scan or backtest. | | Assuming prices are never zero | Writing C == 0 as a signal will never trigger for stocks, rendering your strategy inactive. | Use explicit False or 0 if you want a condition that never fires. |
// ----- 3. Position Sizing (Realistic) ----- SetPositionSize(4, spsPercentOfEquity); // Risk 4% of equity per trade SetOption("MaxOpenPositions", 5); SetOption("WorstRankHeld", 5);
Notice how ensures the breakout level is based on yesterday’s high/low. Unverified code would use H (current high), triggering fake breaks.
, backtests, and explorations [0.2]. To produce a "proper article" with verified code, you must structure your formula to handle data arrays efficiently and include essential AmiBroker functions for signal generation and visualization. 1. Essential Article Structure for AFL
Using BuyPrice = Close when your system actually executes on the next day's open creates unverified results. Your code must match your broker's actual execution capabilities. Template for Verified AmiBroker AFL Code
Verified AFL code means the script has been thoroughly checked and validated across four distinct layers:
// Execution prices: next bar open after signal BuyPrice = Open; SellPrice = Open;
The code runs without errors on standard Amibroker builds. This sounds trivial, but complex code with nested loops, custom indicators, or StaticVar functions often fails across different database settings or timeframes. Verified code includes proper error handling and version compatibility checks.
: The code accounts for slippage, commissions, and liquidity constraints.
Not all AFL is created equal. Here is a trust matrix for the keyword “Amibroker AFL code verified”:
Run your script, then open . If you see a warning, your code is not verified.