Run the AFL on a radar screen (e.g., All S&P 500 stocks) for the last 3 months.
This is the most common killer of trading strategies. Look-ahead bias occurs when your AFL code uses future data to make a past decision. For example:
// DANGEROUS (Unverified)
Buy = Ref(Close, -1) > EMA(Close, 20);
A verified code ensures that signals are calculated using only bars up to the current index. Professionals use Ref(..., -1) carefully and validate through ExRem and trade list reviews.
Run Backtest with SetOption("AllowSameBarExit", False) initially to avoid unrealistic trades.
Check:
When you download a script claiming to be "AmiBroker AFL code verified," run it through this forensic checklist.
SetOption("FuturesMode", 1);
SetOption("CommissionMode", 3); // per share
SetOption("CommissionAmount", 0.01);
SetTradeDelays( 1, 1, 1, 1 ); // enter next bar, exit next bar
Verification: Log every trade’s assumed fill price vs. actual bar OHLC.
To verify a backtest matches your intended capital, force the settings in the code rather than relying on the Analysis Window UI settings.
SetOption("InitialEquity", 10000);
SetOption("MinShares", 1);
SetPositionSize(100, spsPercentOfEquity); // Verify you are using 100% equity
Run the AFL on a radar screen (e.g., All S&P 500 stocks) for the last 3 months.
This is the most common killer of trading strategies. Look-ahead bias occurs when your AFL code uses future data to make a past decision. For example:
// DANGEROUS (Unverified)
Buy = Ref(Close, -1) > EMA(Close, 20);
A verified code ensures that signals are calculated using only bars up to the current index. Professionals use Ref(..., -1) carefully and validate through ExRem and trade list reviews.
Run Backtest with SetOption("AllowSameBarExit", False) initially to avoid unrealistic trades.
Check:
When you download a script claiming to be "AmiBroker AFL code verified," run it through this forensic checklist.
SetOption("FuturesMode", 1);
SetOption("CommissionMode", 3); // per share
SetOption("CommissionAmount", 0.01);
SetTradeDelays( 1, 1, 1, 1 ); // enter next bar, exit next bar
Verification: Log every trade’s assumed fill price vs. actual bar OHLC.
To verify a backtest matches your intended capital, force the settings in the code rather than relying on the Analysis Window UI settings.
SetOption("InitialEquity", 10000);
SetOption("MinShares", 1);
SetPositionSize(100, spsPercentOfEquity); // Verify you are using 100% equity