How-to · Technical Analysis
How to Backtest a Moving Average Strategy by Hand, Trade by Trade
Backtesting a moving average strategy by hand means replaying the chart one bar at a time and logging every trade your written rules would have taken, in units of risk.
Short answer
Write the entry, stop and exit rules exactly, choose the chart and test period in advance, then scroll forward one bar at a time and record each trade in R, with costs included. Keep going until you have a meaningful number of trades, then forward test with small size before trading it fully.
Rules first, chart second. A moving average strategy that exists only as a feeling about “buying when it bounces off the 50-day” cannot be tested, because every bounce will look different depending on how much you want the trade.
Manual backtesting forces the rules into writing and then holds you to them. It is slow. It also shows you, bar by bar, how a system behaves on a real chart: the whipsaws, the gaps through the stop, the dull stretches with no signal at all.
Steps to backtest by hand
- Write the rules exactly. State the moving average type and length, the entry trigger, the stop and the exit, precisely enough that someone else would take the same trades from your notes. For example: buy at the close when price closes above the 50-day simple moving average after at least five closes below it; stop below the lowest low of those five days; exit at the close when price closes back below the 50-day.
- Pick the chart and the period before you look. Choose the stock or ETF and the start and end dates first. Write them down.
- Hide the future. Scroll so the right edge sits at the start date. Then advance one bar at a time. Many charting tools have a replay mode. If yours does not, cover the right side of the screen.
- Record every trade the rules produce, in R. R is the distance from entry to stop. A trade that gains three times that distance is +3R.
- Include costs. Commissions, the bid-ask spread and slippage all come out of each trade, and a gap past your stop fills at the open, which can make a loss bigger than 1R.
- Keep going until the sample means something. Ten trades is a start, and far too few to judge the rules on.
- Forward test small. Trade the rules live with a fraction of your normal size and keep logging, since a live market adds hesitation and fills that no replay reproduces.
What goes on the record sheet?
Keep the sheet short.
| Date | Entry | Stop | Exit | R | Note |
|---|---|---|---|---|---|
| (signal date) | 50.00 | 48.00 | 54.00 | +2 | Held above 50-day for three weeks |
| (signal date) | 52.00 | 50.00 | 50.00 | -1 | Closed back below within two days |
R for each row is (exit - entry) / (entry - stop). In the first row that is (54 - 50) / (50 - 48) = 4 / 2 = +2R.
The note column matters more than it looks. Write down anything the rules did not cover: an earnings gap, a signal you almost skipped, a trade where the stop placement felt wrong. Those notes are where rule changes come from, later, after the test.
A worked sample run
Here is a hypothetical run of ten trades from the rules above.
Six losers out of ten feel like failure while you scroll. Don’t quit at trade five. The winners were larger than the losers, and that paid for the losing streak. Trend-following systems built on moving averages often look like this, with more small losses than wins and a few large gains carrying the total. The strategy page on using moving averages goes deeper into why.
Now add costs. If spread, commission and slippage together cost 0.1R a trade, ten trades lose 1R to costs, the total drops from +3R to +2R and expectancy falls to +0.2R. A system with a thin edge can go negative this way.
What ten trades cannot tell you
They cannot say whether the edge is real.
Ten results can come out positive by chance even when a system has no edge at all, and a single +3R winner removed from the list above would take the total to zero. You need many more trades, across more than one stock and through both trending and choppy periods, before the expectancy figure deserves trust, and how many depends on how large the edge is and how widely results vary from trade to trade. There is no count that makes a small sample reliable.
Traps that spoil a manual test
Hindsight in choosing the stock
Remembering that a stock trended beautifully is a reason to skip it. The test would be rigged before it starts. Choose the instrument by a rule, such as the first names on a watchlist you already follow.
Changing the rules mid-test
You take four losses in a row. A longer average would have dodged them, so you switch. Now you have two half-tests and no answer. Finish the test as written. Test the new version separately, on fresh data.
Ignoring gaps and slippage
A stop is an order. Its fill depends on the next bar. A stock that closes above your stop and opens far below it fills at the open, which turns a planned -1R into something worse. Record the gap fill honestly, even when it hurts the total.
The moving average calculator helps you check average values at specific bars if your chart’s readout is hard to see, and the technical analysis topic page has the related strategies.
Questions traders ask next
What does R mean in backtesting?
R is the amount you risk on a trade, the distance from entry to stop. A trade that makes twice that distance is +2R, and one that hits the stop is -1R. Recording results in R lets you compare trades on stocks of different prices and add them up without worrying about share counts.
Is manual backtesting better than using software?
Each has a use. Software can test thousands of bars fast, but only if the rules can be coded exactly. Scrolling by hand is slower and limited in sample size, and it trains your eye to see the setup the way you will see it live, including the messy cases a coded rule might skip.