Translating a chart pattern into rules
Lesson 10 · about 11 min
Chart patterns are the hardest thing to backtest, because the pattern lives in the eye of the person drawing it. Two traders will draw a different "flag" on the same chart and be equally sure they are right. The way to test a pattern is to replace the drawing with a definition that a spreadsheet can evaluate, accept that the definition will not match your eye on every chart, and then see whether the defined version has any edge. This lesson walks through that translation for a bull flag.
Step 1: describe what the eye sees
A bull flag, as most people draw it: a sharp move up (the pole), then a few bars of sideways-to-slightly-down drift on lower volume (the flag), then a break above the flag's upper edge (the trigger). The trade is long on the break, stop below the flag, target roughly the height of the pole.
Every phrase in that description needs a number.
Step 2: assign a measurement to each phrase
| Phrase | Measurement | Chosen definition |
|---|---|---|
| "Sharp move up" | Percent gain over N bars, relative to volatility | Close-to-close gain over 5 bars ≥ 4 × ATR(14) |
| "The pole" | Those N bars | The 5-bar window that satisfies the above |
| "A few bars" | Bar count | 3 to 8 bars after the pole ends |
| "Sideways-to-slightly-down drift" | Range of the flag relative to the pole | Flag high − flag low ≤ 40% of pole height; flag low ≥ pole low + 50% of pole height |
| "Lower volume" | Average volume comparison | Mean flag volume < 70% of mean pole volume |
| "Break above the flag's upper edge" | Price crosses a level | Buy stop one tick above the highest high of the flag bars |
| "Stop below the flag" | Level | One tick below the lowest low of the flag bars |
| "Target ≈ pole height" | Distance | Limit at entry + (pole high − pole low) |
Every number in the right-hand column is a choice. Each one is a parameter, and Module 6 will explain why too many of them is dangerous. For now, pick values that match what your eye already does, write them down, and resist the urge to tune them.
Step 3: write the rules in order
- Pole detection. On bar D, compute gain = close(D) − close(D−5). If gain ≥ 4 × ATR(14) through D, mark D as a pole end; pole height = high over D−5 to D minus low over D−5 to D.
- Flag window. For bars D+1 through D+8, compute the running flag high and flag low. The flag is valid on any bar D+k with 3 ≤ k ≤ 8 where flag range ≤ 0.4 × pole height, flag low ≥ pole low + 0.5 × pole height, and mean volume of D+1 through D+k is < 0.7 × mean volume of D−5 through D.
- Trigger. On the first valid flag bar, place a buy stop at flag high + 1 tick, valid for the next bar only. If the flag remains valid on the next bar, re-place the order with the updated flag high.
- Stop. Flag low − 1 tick.
- Target. Entry + pole height.
- Time stop. Exit at the close of the 15th bar after entry.
- Precedence. Stop before target on a bar touching both.
- Sizing. 1% of account ÷ (entry − stop), capped at 25% of account.
- Filter. Long only; close on D above the 50-day moving average.
Step 4: check it against your eye
Run the rules on a year of data for one instrument and mark every trade on the chart. Then mark the flags you would have drawn by hand. Three things will be true:
- Some of your hand-drawn flags will not be detected (the pole was 3.5 ATR, not 4).
- Some detected flags will look ugly to you (the definition is satisfied but the shape is wrong).
- The overlap will be somewhere around half to two thirds.
This is normal and not a failure. The question is not whether the rules match your eye; it is whether the rules have an edge. If they do, you have a testable strategy. If the rules have no edge but your eye "would have" done better, you are back to a discretionary strategy and the veto log from the previous lesson.
Key idea: Translating a pattern into rules means replacing every adjective with a measurement. The result will disagree with your eye on some charts. That is the price of being able to test it at all.
A worked signal
| Bar | Close | High | Low | Volume | Note |
|---|---|---|---|---|---|
| D−5 | 50.0 | 50.4 | 49.6 | 1.0M | |
| D | 54.2 | 54.5 | 53.8 | 1.6M | Gain 4.2; ATR 1.0; pole valid. Pole height 54.5 − 49.6 = 4.9 |
| D+1 | 53.9 | 54.3 | 53.5 | 0.8M | Flag range 0.8 (≤ 1.96 OK); flag low 53.5 ≥ 52.05 OK |
| D+2 | 53.6 | 54.0 | 53.3 | 0.7M | Range 1.0 OK; volume mean 0.75M < 0.91M OK |
| D+3 | 53.8 | 54.1 | 53.4 | 0.6M | k = 3, valid; buy stop at 54.31 for D+4 |
| D+4 | 54.9 | 55.0 | 53.7 | 1.2M | Filled at 54.31 (+ slippage). Stop 53.29. Target 54.31 + 4.9 = 59.21 |
Risk per share is 54.31 − 53.29 = 1.02. Target is 4.9 away: 4.8R planned. Whether it gets there is what the backtest measures.
Try it: Pick any pattern you trade by eye. Write the table from Step 2 for it: every phrase, the measurement, and your chosen number. Count the parameters. If there are more than about six, look for phrases that can share a definition or be dropped.
Recap
- Patterns are testable only after every descriptive phrase becomes a measurement.
- Each measurement is a parameter; choose values that match your eye and do not tune them yet.
- Write the rules in execution order with explicit order types, levels and precedence.
- Expect the rules to match your hand-drawn patterns only partly; that is normal.
- The test is whether the defined version has an edge, not whether it looks right.
See it drawn
Original diagrams for the ideas on this page. Illustrative, not real market data.