"Buy when the close breaks a 20-day high." Testing this one sentence from 2016 to 2025 gave 31 trades. A friend given the same sentence runs the same period and gets 42. Who was wrong?
Neither may have made a calculation error. They simply read the same sentence differently. Lessons 474, 475 and 477 showed why survivorship bias, look-ahead information and trading costs inflate past performance. This lesson turns those traps into two documents. One is a rule specification from which someone else can produce the same trade list. The other is a checklist that confirms the data held only what could be known at the time.
1. The same sentence becomes different rules
The rules, stocks and numbers from here on are all hypothetical examples for explanation. Suppose that on some day the highest close of the previous 20 trading days is $51.10, the highest high is $52.40, and today's close is $51.80. If the new high is read on closes, there is a signal; if it is read on highs, there is none.
Whether to include today in the 20 days is also a question. The highest close including today's close cannot be lower than today's close. So the condition "today's close is higher than the highest close" is never true if today is included. Changed to "equal to or higher", it is true on every day that sets a new high.
| Question | One reading | Another reading |
|---|---|---|
| Basis of the new high | Highest close of the previous 20 trading days | Highest high of the previous 20 trading days |
| Is today included? | No (days t−20 to t−1) | Yes (days t−19 to t) |
| When the signal is known | After the regular-session close on day t | The moment it is first crossed during the session |
| Buy price | Open on day t+1 | Close on day t |
| What is tested | That day's index members | Today's index members |
All five rows are plausible readings. Changing just one changes the trade list, and the results split, like 31 and 42 trades. But the right-hand readings in the last two rows are not differences of reading; they are wrong calculations. Buying at that day's close on a signal known only after the close is the look-ahead use of Lesson 475. Using today's members brings in the survivorship bias of Lesson 474 as it is.
2. The specification fills all six fields
A specification is written in sentences that anyone calculates in only one way. The six fields are universe, data, signal time, order, costs and version.
| Field | Hypothetical breakout rule v1.0 |
|---|---|
| Universe | Members of the large-cap index at the time, as of the first trading day of each month, with the previous close at $10 or more and average trading value of $20 million or more over the previous 20 trading days |
| Data | Daily open, high, low, close and volume. Signals use split-adjusted prices only; the $10 condition uses the price actually traded that day; profit and loss uses prices adjusted for splits and dividends. Record the provider and the download date |
| Signal time | Calculated after the regular-session close (4 p.m. US Eastern Time) on day t. A signal if the close on day t is higher than the highest close of days t−20 to t−1 |
| Order | Limit buy at the open on day t+1. The cap is the day-t close × 1.01, dropping fractions of a cent. No order if the open is above the cap. Quantity by Lesson 276's method; exit at the next day's open after the close falls below the lowest close of the previous 10 trading days |
| Costs | 0.15% one way (commission, spread and slippage combined); taxes and exchange rates excluded |
| Version | v1.0, written 2026-10-30. Data file names and download dates; test period 2016 to 2025 |
In the earlier example, the cap is 51.80 × 1.01 = $52.318, and dropping fractions of a cent gives $52.31. The fill lists of two people match only if the specification says whether to round or truncate. Costs are 0.15% one way, so 0.30% round trip is deducted from each trade.
A sentence missing numbers, times or price types, such as "buy at a reasonable price" or "only when the market is good", is not yet a rule. To add a market filter, write down which moving average of which index is judged on which day's close. What the filter actually added is checked as in Lesson 306, by calculating the results with and without the filter side by side on the same data.
3. Testing the past with today's index members inflates results
Suppose this rule was applied to a hypothetical large-cap index. Using each month's members at the time gives 400 trades, with an average return per trade of 0.90%. Running the same rule again with today's member list changes two things.
First, 60 trades in stocks that later left the index disappear. These trades averaged −3.50%. Second, 45 trades that stocks later added to the index made before they joined come in. These are stocks that joined after rising a lot, so they average 4.20%. They were not in the test universe at the time.
400 − 60 + 45 = 385 trades
(400 × 0.90 − 60 × (−3.50) + 45 × 4.20) ÷ 385 = about 1.97%
The rule is the same, but the average per trade more than doubles. Today's list is a list chosen by someone who knows the results.

Stocks that left cannot all be treated as failures either. A stock removed because it was acquired may have had a high last price. So removed stocks are not thrown away; record their last trading day, last price and the amount received after delisting separately. If the members at the time cannot be obtained, write "today's members, survivorship bias present" next to the result, and do not compare it side by side with other rules' results.
4. Check times and price types with the data checklist
The checklist is a document separate from the specification. Each line has a check question and a pass criterion, and the result is one of pass, fail or not checked. Do not use performance numbers from a test with a failed line left; fix the data and run it again. This is not because the rule is bad but because the test did not run properly, so Lesson 306 calls it a validation failure, separate from a performance failure.
| Check item | Check question | Pass criterion (example) |
|---|---|---|
| Members at the time | Was each date's universe used for that date? | A dated list that includes removed and delisted stocks |
| Filing time | When could that number be known? | Used from the first order time after the acceptance time |
| First-reported values | Were later-revised numbers avoided? | Values as first reported and revised values kept separately |
| Adjusted prices | Were the right prices used for signals and for profit and loss? | Price conditions on prices of the time; profit and loss on prices adjusted for splits and dividends |
| Look-ahead and repainting signals | Do past signals change with later data? | Signals saved each day match recalculated signals |
| Fill assumptions | Were that price and quantity possible? | Next day's open, no fill above the cap, orders at most 1% of that day's volume |
| Costs and slippage | Was the same cost deducted from every trade? | 0.15% one way, with the result at double the cost also recorded |
For filings, look at the time, not the date. The US filing system EDGAR treats most filings, such as quarterly reports, as filed that day if submission begins by 5:30 p.m. US Eastern Time. So a quarterly report accepted at 4:15 p.m. still has that day as its filing date. Calculating as if you bought at that day's close by looking only at the filing date uses information from after the regular-session close at the closing price. Use the acceptance time shown in the filing list, and if it was accepted after the close, use it from the next trading day's open.
Separate the uses of adjusted prices. If a stock that was $36 in 2019 split 4-for-1 in 2022, a price table adjusted backward for the split shows the 2019 price as 36 ÷ 4 = $9. Applying the "$10 or more" condition to this price drops a stock that was in the universe at the time. Prices adjusted for dividends too change slightly in the past every time a new dividend is paid. Rerunning the same specification can give different numbers, so write the download date in the version field.
A repainting signal is a past signal that changes because of data that came in later. The high seen in Lesson 243 is confirmed only after the next trading day's close. Testing with an indicator that marks a signal on the very day the high formed gives a result that used, in advance, a signal that could only be known a day later. So save each day a signal list calculated only with that day's data, and check it against the list recalculated later over the whole period. If even one differs, it fails.
Test costs once more. If an average of 0.90% per trade is after deducting 0.30% round trip, doubling the one-way cost to 0.30% makes it 0.90 − 0.30 = 0.60%. A rule whose average falls to near zero when costs are doubled leans heavily on its fill conditions.
5. Check start years and stress periods separately
With the same specification, change only the start year. Record all four results, starting in 2016, 2017, 2018 and 2019. If it is good only when starting in one year, a few early trades that only that start year includes are likely driving the whole result. Next to the representative value, also write the worst of the four results.
Stress periods are kept only as check items, without guessing the results. One example is the 2008 financial crisis, when the US recession ran from December 2007 to June 2009. Another is the COVID-19 shock, with a recession from February to April 2020. A third is 2022, when the US federal funds target range rose from 0.25-0.50% in March to 4.25-4.50% in December. For each period, record the number of trades, the worst trade, the longest losing streak and the drawdown in that period.
This specification's test period starts in 2016, so it does not include 2008. On that line, write "outside the period, not checked". The checklist's rule is not to count an item that could not be checked as a pass. Until it is tested on longer data, this rule has no evidence that it withstands a fall like the financial crisis.
6. Check that someone else gets the same numbers, and raise the version
A reproduction test hands over only the specification and the data files and compares the results. If there is no one else, you a week later can rebuild it without looking at the earlier code. Compare the number of trades, the signal dates and fill prices of the first 20 trades, and the average per trade.
If even one trade in the list differs, line them up by date and find the first trade that diverges. That trade shows which field was read in two ways. The difference between 31 and 42 trades is found the same way. When the sentence is fixed and the two lists match, the reproduction test is passed.
Versions are split into two kinds. If only the wording is polished and the trade list stays the same, go from v1.0 to v1.1. A change that alters the trade list goes to v2.0 and counts as a new attempt. Lesson 306 records this number of attempts in the performance table. Earlier versions' results are not deleted but kept with their version names.
The record for this lesson is a versioned rule specification and a data and fill checklist. The specification holds the six fields. The checklist holds the seven items and the results of the start-year, stress-period and reproduction tests, with any line that could not be checked left as not checked.
Try it yourself
- The day-t close is $64.20, the highest close of the previous 20 trading days is $63.90, and the highest high is $64.80. Is there a signal under specification v1.0? What is the limit cap, and what do you do if the day-t+1 open is $65.10?
- A quarterly report was accepted at 4:20 p.m. on May 1. When, and at what price, can a rule using these numbers first buy? What is wrong with calculating at the May 1 close?
- In section 3, if the trades in stocks that later left were 100 instead of 60 and averaged −2.00%, what is the average per trade with only those trades removed? Trades in stocks added later are not included.
- Fill in the three stress-period lines for a specification whose test period is 2016 to 2025. What do you write, and what do you leave as not checked?
Answers
First, $64.20 is above the previous 20 trading days' highest close of $63.90, so it is a signal. The highest high of $64.80 is not used in this specification. The cap is 64.20 × 1.01 = $64.842, and dropping fractions of a cent gives $64.84. The open of $65.10 is above the cap, so no order is placed, and the trade list records it as not filled, above the cap.
Second, the acceptance was after the regular-session close, so the earliest order is at the next trading day's open. Calculating at the May 1 close is look-ahead use: numbers made public only at 4:20 p.m. used at the 4 p.m. price. Even if the data's date is May 1, check the acceptance time separately.
Third, 400 × 0.90 = 360, and the removed trades sum to 100 × (−2.00) = −200. Taking out the removed trades gives (360 + 200) ÷ 300 = about 1.87%, more than double the 0.90% on members at the time. Even without the stocks added later, the result is greatly inflated.
Fourth, 2020 and 2022 are inside the period, so fill in each period's number of trades, worst trade, longest losing streak and drawdown from the actual test results. 2008 is outside the period, so leave it as not checked, and do not write that this rule withstands such a fall. If longer data is obtained, fill that line with the same specification and note in the version field that the data changed.
