Most trading ideas start as a sentence: “strong stocks that dip tend to bounce”, “breakouts on heavy volume tend to keep going”. A sentence cannot be tested. Before a single bar of history is replayed, the idea has to become a set of rules so precise that a computer, or a stranger, would take exactly the same trades you would. This lesson shows how to make that translation and why every vague word left in the rules quietly helps the backtest look better than it should.
From an idea to a hypothesis
A testable hypothesis has three parts:
- A condition that can be measured from data available at the time: “the close is below the lower of the last 20 lows”.
- A predicted response over a stated horizon: “over the next 5 to 20 sessions, the stock does better than the benchmark”.
- A reason why the pattern might exist. Over-reaction to bad news, slow diffusion of information, forced selling, and compensation for carrying risk are the usual candidates. A reason does not prove anything, but a rule without one is much more likely to be a pattern found in noise (lesson 5).
The hypothesis also fixes what would count as failure. Writing “if the rule does not beat holding the same stocks on both return and risk-adjusted return, I drop it” before the test is the single most effective protection against talking yourself into a result afterwards.
The building blocks
Almost every price-based rule for daily bars is assembled from a small set of measurements. Each has an exact definition, and the exact definition is what goes into the rule:
| Block | Definition | Typical use |
|---|---|---|
| Price | The bar’s open, high, low or close | Signals usually use the close, stops the low |
| Simple moving average, SMA(n) | Average of the last n closes | Trend filter: close above SMA(200) |
| Exponential moving average, EMA(n) | Weighted average that reacts faster to recent closes | Crossovers such as EMA(10) above EMA(30) |
| RSI(n) | J. Welles Wilder’s Relative Strength Index, 0 to 100, from average up and down closes | Short-term oversold: RSI(2) below 10 |
| ATR(n) | Wilder’s Average True Range: the typical daily range including gaps | Stops and sizing: entry − 2 × ATR(14) |
| N-day high or low | Highest high or lowest low of the previous n bars (the channel associated with Richard Donchian) | Breakouts: close above the prior 20-day high |
| Average volume | Mean volume of the last n sessions | Confirmation: volume above 1.5 × the 50-day average |
Two details matter more than they seem. First, “previous n bars” must exclude today: a close cannot be above a 20-day high that already includes that close. Second, each indicator needs a warm-up: a 200-day average has no value until 200 bars exist, so a test that starts on 1 January needs data from the year before. The moving averages, RSI and ATR stop articles explain each measure in more depth.
Entry, exit and sizing
A complete rule set answers seven questions. If one is missing, the test will fill the gap with an assumption you never chose.
Exits come in four kinds, and a rule set may use several, with the first one hit closing the trade: a signal exit (close above the 5-day average), a stop (a price that limits the loss), a target (a price or multiple of risk that takes the profit) and a time stop (sell after 10 sessions whatever happens). Some classic timing rules have no stop at all and rely on the signal exit; that is a legitimate choice, but it should be a deliberate one.
Size follows from the risk you accept per trade. With fixed-fractional sizing, the number of shares is the money at risk divided by the distance to the stop:
| Step | Worked example |
|---|---|
| Equity × risk per trade | $100,000 × 1% = $1,000 at risk |
| Stop distance | Entry $50.00, ATR(14) $1.50, stop = 50.00 − 2 × 1.50 = $47.00, so $3.00 a share |
| Shares | 1,000 ÷ 3.00 = 333 shares (rounded down) |
| Position value | 333 × $50.00 = $16,650, or 16.65% of equity, inside a 20% cap per stock |
The cap matters when the stop is tight: a stop only 1% away would call for $100,000 of stock, the whole account. A maximum position size keeps one trade from dominating the test. The position sizing methods article compares fixed-fractional sizing with the alternatives.
Ambiguity is a source of bias
Vague wording does not just make a rule hard to code. It lets hindsight in. When a rule says “sell when the trend turns down”, the person testing it already knows where the trend did turn, and the exits drift towards the tops. The test then measures the tester’s memory, not the rule.
The questions below remove most ambiguity. Each has a conservative default:
- Which price triggers the signal? Default: the close.
- When is the signal known? After the close of the signal day.
- When is the order filled? At the next session’s open. Filling at the signal day’s close is possible in practice only with an order placed just before the close, and it slightly flatters a test.
- What if the open gaps through the stop? The loss is taken at the open, not at the stop price.
- What if two signals compete for the last cash? A fixed tie-break, such as alphabetical order or the larger volume, written down in advance.
- Which data is used? Prices adjusted for splits (lesson 6), and only what was published on that date.
Exact rules also produce exact, and sometimes uncomfortable, dates. A plain “close above or below the 200-day average” rule on SPY changed its mind ten times between August 2015 and March 2016, as the index chopped around its average. Adding a buffer, so that the rule sells only when the close falls 3% below the average, cut that to four orders over the same months: two sells and two buys. Neither version is right in general. The point is that the buffer is a decision, it has to be made before the test, and the test must then live with whatever dates the rule produces.
A complete example
Here is the idea “stay invested in the market only while it is in a long-term uptrend” written out in full, in the spirit of Mebane Faber’s 2007 study of moving-average timing:
| Part | Rule |
|---|---|
| Universe | SPY only |
| Entry | Close above SMA(200); buy at the next open |
| Exit | Close below 0.97 × SMA(200); sell at the next open |
| Stop | None (the exit rule is the protection) |
| Size | All equity in SPY while invested; cash otherwise |
| Costs | 10 basis points per side, slippage included |
| Reason | Large declines have tended to happen below a falling long-term average, when volatility is high |
Faber’s original used month-end closes and a 10-month average; this daily version differs from it, and a fair description says so. Every line could still be argued with. That is fine: arguments belong before the test, and each change creates a new rule to be tested on its own.
How to apply it
Entry
Write the entry condition with exact indicators, lengths, comparison and price field, and state that the order fills at the next open.
Stop
Choose a stop type (ATR multiple, percentage, n-day low or none) and write how a gap through the stop is handled.
Target
Write the exits: signal, target as a multiple of risk, or time stop, and which takes priority if several trigger on the same day.
Invalidation
If any line of the rule set needs judgement to apply, the rule is not finished. Rewrite it until two people would take the same trades.
Common mistakes
- Using words like “strong”, “clear” or “confirmed” without a number behind them.
- Including today’s bar in the “previous n-day high” and so making breakouts impossible or unfair.
- Forgetting the warm-up, so the first months of a test run on half-formed indicators.
- Sizing every trade at the same dollar amount while the stop distance varies, so risk per trade swings widely.
- Choosing the buffer, the stop or the average length after seeing the chart.
Summary
A testable rule set states the universe, the filter, the entry, the stop, the exits, the size and the timing of the fill, each with exact numbers, using only information available at the moment of the decision. Price, moving averages, RSI, ATR, n-day highs and lows and average volume cover most daily rules. Size from risk: shares equal the money at risk divided by the stop distance, within a cap per position. Every vague word is a door for hindsight; close it before the test. The next lesson replays a rule set on history and explains the numbers a backtest reports.
For educational purposes only. Not investment advice.