: Includes SetChartOptions and SetTradeDelays to define environment rules.
If you've developed a strategy, follow this checklist to verify it:
The interface is often described as looking like it’s from the 1990s. amibroker afl code verified
By integrating the tools and processes described in this article—including the AFL Editor’s verification button, the debugger, the profiler, walk‑forward testing, and Bar Replay—you can transform your AFL scripts from untested code into verified, trustworthy trading systems. In the competitive world of algorithmic trading, verification is not merely a best practice; it is the foundation upon which all successful automated strategies are built.
| 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. | | | Array arguments in if statements |
Use the AFL Editor’s "Check" tool to identify syntax errors immediately.
Verified AFL code is not optional for serious automated trading. This paper provides a : static analysis, runtime assertions, repaint testing, and execution fidelity checks. By applying these methods, a developer can eliminate the most common sources of backtest overfitting and live-market failure. or check if(BarCount >
| Mode | Execution Style | Use case | |------|----------------|----------| | | Entire array processed at once | Indicators, scans, exploration | | Iterative (bar-by-bar) | for() loop over BarCount | Custom trailing stops, complex state machines |
AmiBroker processes data as arrays (a series of numbers over time). Trying to use an array directly inside a standard conditional if statement causes the infamous "Condition click expects a numeric or boolean expression" error. You must use functions like IIf() for array-based conditions. 3. Step-by-Step Process to Verify AFL Code
What are you trading on (e.g., 5-minute, hourly, daily)?