For 5-minute charts.
For intermittent bugs, store intermediate states:
AFL allows for rigorous testing of historical data to evaluate a system's performance. amibroker afl code
Start simple. Write a moving average crossover. Then add a filter. Then a stop-loss. Gradually incorporate scanning and custom backtesting. Use the debugging techniques shared here. And most importantly, always question your assumptions: Is my code look-ahead free? Am I including realistic costs?
Ref(Array, -1) // previous bar value MA(Array, periods) // moving average HHV(High, 10) // highest high last 10 bars LLV(Low, 10) // lowest low last 10 bars Cross(A, B) // crossover Buy = condition; // trading signal Sell = condition; For 5-minute charts
// --- Backtest Settings --- SetPositionSize(1, spsShares); // Let PositionSize variable handle % SetOption("UseCustomBacktestProc", False);
Open Amibroker, press Insert > Formula . Type this: Write a moving average crossover
// My First AFL Indicator Plot(C, "Price", colorBlack, styleCandle); Plot(MA(C, 20), "20 SMA", colorRed, styleLine); Title = "NAME - Daily Chart";
View output via .
// --- Core Logic --- MA200 = MA(C, LengthMA); RSIval = RSI(RSIPeriod); ATRval = ATR(VolatilityPeriod);