AmiBroker Backtesting
A backtest is not a measurement. It is a simulation, and every simulation is a stack of assumptions with a number printed on top. The number is the part everyone reads. The stack is the part that decides whether the number means anything.
Part 27 got you as far as a rule set that two people would implement identically. This part
is about the machine that turns that rule set into a simulated account: what AmiBroker does
with your Buy array, which price it fills you at, how many shares it buys, what it charges
you, when it takes you out, and what changes when ninety symbols are competing for one pot
of money instead of one symbol having the pot to itself.
What sits between a rule and a reported return
- Your rulesBuy, Sell, Short, Cover — one value per bar, no timing information
- TimingSetTradeDelays() decides which bar the signal is acted on
- Fill priceBuyPrice and friends decide what you paid, clamped to the bar range
- SizeSetPositionSize() decides how much of the account is at stake
- CostsCommission, slippage, spread — subtracted from every leg
- ExitsRule exits and ApplyStop() compete for the same trade
- The accountOne cash balance, a position limit, and a rank that refuses the surplus
- The reportWhat you were going to read first
Why this part comes before the report
Section titled “Why this part comes before the report”Part 29 reads AmiBroker’s backtest report in AmiBroker’s own vocabulary. It would be an
easier part to write first, and a worse one to learn first, because almost every serious
misreading of a backtest report is really a misunderstanding of something in the stack
above. A spectacular Risk Adjusted Return % usually means the system was barely in the
market. An implausibly smooth equity curve usually means the stops were assumed to fill at
a price nobody had to offer. A system that appears to ignore most of its own entries is
usually running into the documented behaviour of the default backtest mode.
None of those are report problems. They are simulator problems that only become visible in the report.
What this part assumes you have
Section titled “What this part assumes you have”An end-of-day database with a few years of daily bars for a watch list of liquid instruments — twenty to fifty names is plenty. Nothing here needs a real-time feed, a data subscription or the Professional edition; every formula in the part runs on free end-of-day history in the Standard edition. The one place edition matters is throughput: the Standard edition runs two threads per Analysis window against the Professional edition’s thirty-two, so a large optimisation takes longer, not different.
You also need to have read Part 27, or to be willing to accept a rule set you did not write. Several formulas here reuse the trend system from that part’s project so that the subject of the page stays on the simulator rather than drifting into strategy design.
The habit this part is really teaching
Section titled “The habit this part is really teaching”Every formula in this part opens with a block of assumptions: fill price, delays, commissions, slippage, liquidity, financing, data. That block is not decoration and it is not there to satisfy a style rule. It exists because a backtest result is only interpretable next to the assumptions that produced it, and because those assumptions are exactly the things you will forget three weeks later when someone asks you what the number meant.
What changes by the end
Section titled “What changes by the end”You will be able to write a portfolio backtest whose every material assumption is visible in the formula rather than buried in a settings dialog; to explain why the same rules produce a different answer at portfolio level than symbol by symbol; to say precisely which stop configurations award your simulation a fill that no order book had to provide; and to take the single most repeated claim in technical analysis, test it properly, and describe the result without deciding in advance what you wanted it to be.
0 / 8 lessons in this part completed
Progress tracking needs browser storage, which is unavailable here. The course works exactly the same without it.
- LessonBacktester Basics: Signals and Trade Prices30 min
- LessonPosition Sizing with SetPositionSize()30 min
- LessonCosts: Commissions, Slippage and the Spread28 min
- LessonStops with ApplyStop()32 min
- LessonPortfolio Backtesting: Many Symbols, One Account32 min
- LessonSingle-Symbol Thinking versus Portfolio Reality28 min
- ProjectProject: A Realistic Portfolio Backtest65 min
- Reality checkReality Check: Is the Golden Cross Worth Anything?45 min
Sources for this lesson
2 verified · checked 2026-08-31
- 01AmiBroker User's Guide — Back-testing your trading ideasamibroker.com/guide/h_backtest.html2026-08-31
- 02AmiBroker User's Guide — Portfolio-level backtestingamibroker.com/guide/h_portfolio.html2026-08-31
Every technical claim on this page was checked against the official AmiBroker documentation on the date shown. Where the course disagrees with folklore, the source is how you can tell which one to trust.