Your first backtest
Every strategy, from a hobbyist's to a hedge fund's, is the same four parts: a signal, an entry, an exit, and a size. We'll snap them together into the classic beginner strategy — a moving-average crossover — and watch it run.
- The four parts of any strategy: signal, entry, exit, size
- A worked moving-average crossover, step by step
- Why position sizing matters as much as the signal
- Vectorized vs. event-driven backtests, in plain terms
Every strategy is four parts
Strip away the jargon and a trading strategy answers four questions, in order:
Signal
What condition am I watching for?
Entry
When the signal fires, how do I get in?
Exit
What makes me get out — win or lose?
Size
How much do I put on this trade?
Miss any one and you don't have a strategy yet. Beginners obsess over the signal and forget the other three — but as you'll see, exit and size decide your fate at least as much as the entry does.
A worked example: the moving-average crossover
The "hello world" of backtests. A moving average (MA) is just the average price over the last N days, recomputed each day — it smooths the noise so you can see the trend. We use two: a fast one (say 10 days) that reacts quickly, and a slow one (say 50 days) that moves ponderously.
- Signal: the fast MA is above the slow MA → the recent trend is up.
- Entry: buy the moment the fast MA crosses above the slow MA (the "golden cross").
- Exit: sell the moment it crosses back below (the "death cross").
- Size: risk a fixed slice of the account on the position.
Run that rule over years of history, tally the trades, and you have a backtest. Feed the trade results into Module 2's scoreboard — CAGR, Sharpe, drawdown — and you can finally answer "would this have worked?"
Size is not an afterthought
Two traders run the identical crossover signal. One risks 2% of the account per trade; the other risks 30%. Same entries, same exits — wildly different fates. The reckless one can be wiped out by a normal losing streak the careful one shrugs off. Position sizing turns a signal into a survivable strategy, and it's the difference between a backtest that compounds and one that goes to zero on trade 14.
This is its own discipline, and we built a calculator for it: the Position Size & Risk of Ruin tool runs a Monte Carlo of your edge to show how sizing changes your odds of survival. Module 6 goes deep on it.
Vectorized vs. event-driven
Two ways to actually compute a backtest, and it's worth knowing the words:
- Vectorized: calculate all the signals across the whole history at once, in one sweep. Fast, simple, and what nearly every beginner tool (and most of our teardowns) uses. The risk: it's easy to accidentally let future data leak in (hello, look-ahead bias).
- Event-driven: step through time one bar at a time, as if live, only ever seeing the past. Slower and more code, but far more realistic — it's how serious systems are validated before real money.
- Signal
- The condition a strategy watches for.
- Moving average
- The average price over the last N periods, recomputed each step.
- Backtest
- Running a strategy's rules over historical data to tally how it would have done.
- Position sizing
- How much capital to commit per trade — the survival dial.
- Vectorized / event-driven
- Computing all signals at once vs. stepping bar-by-bar like live trading.
Where to go next
You can build a backtest now — which means you can also fool yourself with one. Module 5 is the most important in this course: the validation gauntlet that separates a real edge from a lucky-looking curve.
Size your first strategy properly
ToolPosition Size & Risk of Ruin — see how 2% vs 30% per trade changes your odds of survival