// Execution prices: next bar open after signal BuyPrice = Open; SellPrice = Open;
ATRval = ATR(Lookback); UpperBand = Ref(H, -1) + (Mult * ATRval); LowerBand = Ref(L, -1) - (Mult * ATRval);
// --- 3. Strategy logic (verified no look-ahead) --- period = Optimize("Period", 14, 5, 30, 1 ); RSIval = RSI( period ); Buy = Cross( RSIval, 30 ); Sell = Cross( 70, RSIval );
: Use Edit -> Prettify Selection to format your code, making indentation errors and logical structures easier to spot. 2. Logic & Performance Debugging
One of the biggest pitfalls in AFL is the "look-ahead" bias (using future data to predict the past). Verified code is audited to ensure it only uses information available at the time of the trade.
// Calculate the moving average MA = MA(C, Length);
// --- 1. Static configuration --- SetBarsRequired( 100000, 0 ); SetOption("UseCustomBacktestProc", False ); SetTradeDelays( 1, 1, 1, 1 ); SetOption("InitialEquity", 100000 ); SetOption("AllowSameBarExit", False ); SetPositionSize( 100, spsShares );