Alpha AcademyTeam Alpha Trading

Level 2 — The Advanced Course · Lesson 14 of 20

Building & Backtesting a System

Prove it before you trade it — expectancy, overfitting, and honest testing.

PDF

In Level 1 you learned what the market is, how orders work, and how to protect yourself with position sizing and stops. This module teaches the next step: turning a trading idea into a system — a complete set of written rules — and testing that system on old data before a single real dollar rides on it.

By the end, you will be able to write a rule set with no wiggle room, test it by hand or with software, read the numbers that tell you whether it works, and spot the traps that make bad systems look brilliant on paper.

What a System Is

A system is a complete set of written rules that makes every decision in a trade before the trade happens. A hunch says "this stock looks strong, I think I'll buy some." A system says exactly what to buy, when, how much, where to get out if you are wrong, and where to get out if you are right. If any part is left to how you feel that morning, it is not a system yet — it is a guess wearing a suit.

Every system needs five parts, and each part must be so specific that two different people following the sheet would take the same trades:

  • Setup — the situation you are waiting for. What must the chart look like before you even consider a trade?
  • Entry — the exact trigger that says "buy now." Not "around here." A price, a close, an event — something a computer could check.
  • Stop — the exact point where you admit you are wrong and exit with a small, planned loss. A stop loss is an order (or a firm rule) that gets you out when price reaches that point.
  • Target — the exact rule for taking profit. A price, a percentage, or an event that says "sell now," decided in advance.
  • Size — how much you buy, calculated from your risk, never from excitement. You learned the 1% rule in Level 1: on a $10,000 account, a single trade should not be able to lose more than about $100.

From a Vague Idea to Testable Rules

Most systems start as a sentence like "I like buying strong stocks when they dip a little." That sentence contains a real idea, but it cannot be tested, because "strong," "dip," and "a little" mean different things on different days. Building a system means turning every fuzzy word into a number.

Here is that sentence turned into a complete, testable rule set. It uses moving averages, which you met in Level 1: a moving average is the average price over the last so-many days, drawn as a line on the chart. A 20-day moving average is just the average closing price of the last 20 days.

The Moving-Average Pullback System (an example, not a recommendation)

  • Market: U.S. stocks and ETFs, judged on the daily chart.
  • Trend filter (part of the setup): Only trade when the price is above its 200-day moving average. That line separates "generally rising" from everything else. Above it, we play. Below it, we sit out.
  • Setup: The price pulls back — dips down — until it touches the 20-day moving average.
  • Entry: If the day after the touch closes back above the 20-day moving average, buy at the next morning's open.
  • Stop: If the price closes below the lowest low of the pullback, sell the next morning. That low is the line that proves the dip failed.
  • Target: Sell when the price has risen 10% from your entry price. If the stop rule triggers first, you are already out.
  • Size: Risk 1% of the account. Divide $100 (on a $10,000 account) by the distance from entry to stop to get your share count.

Watch the size rule work. Say you buy at $50 and the pullback low is $46. Your risk per share is $50 − $46 = $4. Your allowed risk is $100. So you buy $100 ÷ $4 = 25 shares, costing 25 × $50 = $1,250. If the stop triggers, you lose about 25 × $4 = $100 — painful, planned, and survivable. If the target hits at $55, you gain 25 × $5 = $125.

Notice what this rule set leaves out: news, opinions, and your mood. That is the point. Now the idea can be tested, because every trade it would ever take is fully specified in advance.

Backtesting: Replaying History With Your Rules

Backtesting means applying your finished rule set to old price data, trade by trade, exactly as if you had been there — and recording what would have happened. You are asking one question: "If I had followed these rules, with real discipline, over the last several years, what would the results have been?" There are two honest ways to do it.

By hand, on charts

Open a chart, scroll back a few years, and move forward one candle at a time, covering up what comes next. Every time your setup and entry trigger appear, write the trade down: date, entry price, stop, target, which one was hit first, and the profit or loss. This is slow — a few hours for fifty trades — but it teaches you things software never will. You see every ugly loss your system takes. You feel how boring the quiet stretches are.

With software

Charting platforms and backtesting tools can run your rules over thousands of trades in seconds. That speed is a gift and a danger. The gift is a big sample: results from 500 trades mean far more than results from 15. The danger is that software makes it effortless to tweak the rules again and again until the past looks perfect — a trap covered below. Either way, one rule applies to both methods:

The Numbers That Matter

A backtest produces a pile of trades. Four numbers turn that pile into a verdict.

  • Win rate — the percentage of trades that made money. If 40 of 100 trades won, the win rate is 40%.
  • Average win — the typical profit on a winning trade.
  • Average loss — the typical loss on a losing trade, written as a positive number for the math below.
  • Expectancy — the average amount you expect to make per trade over the long run, after wins and losses are both counted. This is the single most important number in this module.

The formula is:

Expectancy = (win rate × average win) − (loss rate × average loss)

Work it with real numbers. Suppose your backtest of 100 trades shows a 40% win rate, an average win of $300, and an average loss of $150. Most beginners see "40%" and walk away. Watch what the math says:

  • Win side: 0.40 × $300 = $120 expected from the winning trades.
  • Loss side: 0.60 × $150 = $90 expected to be given back on the losing trades.
  • Expectancy: $120 − $90 = +$30 per trade.

Check it the long way. Out of 100 trades, 40 winners × $300 = $12,000 gained. 60 losers × $150 = $9,000 lost. Net result: $12,000 − $9,000 = +$3,000 over 100 trades, which is $3,000 ÷ 100 = +$30 per trade. Same answer.

Read that again, because it changes how you think about trading: this system loses more often than it wins, and it still makes money — because its wins are twice as big as its losses. A positive expectancy, after costs, over a large sample, is the closest thing trading has to an edge. A negative expectancy means the system loses money by design, no matter how confident it feels.

The Traps That Make Bad Systems Look Great

Backtesting has four failure modes that fool smart people.

Overfitting: memorizing the past

Overfitting (also called curve-fitting) means adjusting your rules again and again until they fit the old data beautifully — so specifically that they describe that one stretch of history instead of anything repeatable.

Meet Marcus. He backtests a stock over two years and his simple system makes a modest profit. Not good enough, he thinks. He adds a filter: only buy on Tuesdays. Better. Only when a certain indicator sits between 41 and 43. Better still. Skip the first week of every month. Each change is small, and each one "improves" the result, until his final backtest shows an 88% win rate and huge returns. Marcus puts real money in — and the system falls apart within two months. Nothing broke. The system never worked. His filters had quietly memorized two years of one stock's history, the way a student who memorizes last year's exam answers "aces" last year's exam and fails this year's. The market never repeats exactly, so rules carved to fit one exact past fit nothing else.

The defense is suspicion: the more rules and the more precise the numbers (why 41 to 43? why Tuesdays?), the more likely you are looking at a memory, not an edge. Simple systems with few rules are harder to fool yourself with.

Survivorship bias: testing only on the survivors

Survivorship bias means your test data quietly leaves out the losers. If you backtest "stocks in the S&P 500" using today's list, you only test companies healthy enough to still be in the index. The ones that failed, shrank, and got removed — the ones your system might have bought on the way down — are missing. The test looks better than real life because the graveyard was edited out. Watch for it whenever you test on a list of stocks chosen today.

Look-ahead bias: accidentally using the future

Look-ahead bias means your test used information that was not available at the moment of the trade. The classic version: a rule that says "buy at today's close if today closes above the average" — in real life you cannot know the closing price until the close happens, so that fill was impossible. Another version is trading on earnings numbers before the company announced them, because the database shows the final, later-corrected figures. Any backtest that looks impossibly good deserves the question: "Did I cheat with the future somewhere?"

Tiny samples: small numbers lie

Ten trades prove almost nothing. Flip a fair coin ten times and getting seven heads is completely ordinary — it does not mean the coin is rigged, and forty flips later the count usually evens out. A system that won 7 of its first 10 trades may be great, average, or bad; the sample is too small to say. Treat anything under about 30 trades as a rumor, and 100 or more as the start of real evidence.

Forward Testing: Paper First, on Purpose

Even a clean backtest only proves the system fit the past. Forward testing means running the system live, in real time, with a paper account — a practice account with pretend money, which you used in Level 1 — to see whether you and the system can actually execute it in the present.

Do it with a commitment made in advance: "I will paper-trade this system for its next 30 trades, exactly by the rules, and journal every one." No skipping the boring setups. No quietly widening a stop "just this once." The forward test examines two things at once — whether the edge still shows up in current markets, and whether you can follow rules when trades lose three times in a row. When the 30 trades are done, compare the paper results to the backtest: similar win rate? similar average win and loss? Roughly similar is a pass. Wildly worse is information — find out why before real money is involved.

When to Declare a System Broken

Every system has losing stretches. A system with a 40% win rate can honestly lose six trades in a row; that is arithmetic, not failure. So define "broken" in writing before the losing streak arrives, while you are calm.

The anchor is drawdown — the drop from your account's highest point to its lowest point during a bad stretch. Your backtest tells you the worst drawdown the system suffered in testing. Use it:

  • The drawdown rule: If live (or paper) trading pushes the drawdown clearly beyond the worst in your backtest — say the test's worst was $1,800 and real trading sinks past $2,200 without recovering — stop and review the system. The market may have changed in a way the rules cannot handle. Continuing past that line is no longer "trusting the system"; it is hoping.
  • The rule-break rule: If you find you cannot follow the rules — you keep moving stops, skipping entries, doubling size to win it back — the broken thing is the operator, not the system. Stop, return to paper, and fix the behavior first. A system you cannot follow is useless to you even if its backtest is perfect.
  • The conditions rule: If the thing the system depends on disappears — a pattern built on a market behavior that no longer occurs — the system is done, and loyalty will not revive it.

Stopping a broken system is not quitting. It is the skill. The traders who survive can say "the evidence changed, so I stop," park the system, and go back to testing with small or pretend money.

Common Mistakes at This Level

  • Testing a feeling. "Buy strong stocks on dips" cannot be backtested. If it cannot be written as exact rules, it can be neither proven nor disproven.
  • Tweaking until the past is perfect. Every extra filter raises the odds you have built a memory of history that fails live.
  • Ignoring costs. Commissions, fees, and slippage turn many pretty backtests negative. Always subtract them.
  • Trusting 12 trades. A tiny sample cannot separate skill from luck. Demand dozens of trades, ideally a hundred-plus.
  • Changing the rules mid-test. Adjusting the system halfway through a forward test means you have tested nothing. Finish the test, then change one thing and test again.
  • Confusing a losing streak with a broken system. Losing stretches are built into the math. Declare a system broken by the written drawdown rule — not by frustration.
  • Skipping the forward test. A backtest shows the system fit yesterday. Only real-time paper trading shows it — and you — can perform today.

Chapter Summary

  • A system is five written rules — setup, entry, stop, target, size — specific enough that anyone (or any robot) would take the same trades.
  • Vague ideas become testable by turning every fuzzy word into a number, as in the moving-average pullback example.
  • Backtesting replays your rules over old data, by hand for understanding or with software for sample size.
  • Honest tests include commissions, fees, and slippage.
  • Expectancy — (win rate × average win) − (loss rate × average loss) — is the verdict number. A 40% win rate with $300 average wins and $150 average losses expects +$30 per trade: a system can lose more often than it wins and still make money, if its wins are bigger than its losses.
  • Overfitting, survivorship bias, look-ahead bias, and tiny samples are the four traps that make weak systems look strong.
  • Forward testing on paper for a set number of trades — 30 is a good commitment — proves the system and the trader in real time.
  • Declare a system broken by a rule written in advance: drawdown clearly beyond the backtest's worst, or an operator who cannot follow the rules.

Check Yourself

  1. What are the five parts every trading system must define?
  2. In the pullback example, you buy at $50 with a stop distance of $4 per share and $100 of allowed risk. How many shares do you buy, and what do you lose if the stop triggers?
  3. A system wins 40% of the time, its average win is $300, and its average loss is $150. What is its expectancy per trade?
  4. What is overfitting, and why does it fail when real money is used?
  5. Your backtest's worst drawdown was $1,800, and live trading has now drawn down past $2,200. According to this module, what do you do — and what do you not conclude from a simple six-trade losing streak?
Show answers

Answers: 1) Setup, entry, stop, target, and size — each written exactly, with no wiggle room. 2) $100 ÷ $4 = 25 shares; if the stop triggers you lose about 25 × $4 = $100. 3) (0.40 × $300) − (0.60 × $150) = $120 − $90 = +$30 per trade. 4) Overfitting is tuning rules until they memorize one stretch of past data; live markets never repeat that exact past, so the memorized rules stop working. 5) Stop trading the system and review it — the pre-written drawdown rule has been broken. A six-trade losing streak alone proves nothing, because a 40%-win-rate system can honestly lose six in a row.