Technical analysis automation

Automated chart pattern detection explained

By the PatternX team · Published

Short answer

Automated chart pattern detection turns raw candles into patterns in steps: find swing highs and lows, test them against a pattern's tolerances, fit the lines that define it, then require a breakout and confirmation such as above-average volume. Every parameter trades missed patterns for false ones, and the lookback window decides how large a formation the software can see at all.

From candles to a pattern

A detector never sees a chart. It receives a list of candles, with the open, high, low, close and volume of each bar, and must decide with arithmetic alone whether the recent bars contain a specific chart pattern that has just broken out. Most rule-based detectors work through the same steps:

  1. Load a window of recent bars.
  2. Find swing points, the local highs and lows that give a pattern its shape.
  3. Match the shape by testing those swings against tolerances.
  4. Fit the lines: necklines, trendlines or box edges.
  5. Apply a breakout rule to decide whether price has left the pattern.
  6. Confirm with extra conditions such as volume.
  7. Derive levels: entry, stop and target.

Every step has parameters, and every parameter is a trade-off between missing real patterns and reporting false ones.

Swing points

A common definition: a bar is a swing high if its high is the highest of all bars from w bars before it to w bars after it, where w is the number of bars checked on each side. A swing low is the mirror image (see swing highs and lows).

  • A small w (1 or 2) finds many swings, including minor wiggles. Patterns assemble themselves from noise and false positives rise.
  • A large w (5 or more) keeps only significant turns, but no swing can be confirmed until w bars have printed after it.

That lag can't be engineered away: you can't know a high was a high until later bars fail to exceed it. Detectors that confirm pivots late are being honest; tools that mark pivots instantly are guessing or will repaint.

Tolerances: how equal is "equal"?

Textbooks say "two roughly equal lows" or "a flat top". Software has to turn "roughly" into a number, for example lows within 2.5% of each other.

  • Tight tolerances produce clean patterns but miss shapes many traders would accept.
  • Loose tolerances catch more shapes, and more coincidences.

The same percentage means different things in different markets. Within a 90-bar window, 2.5% is a generous allowance on a 1-minute chart of a large, liquid stock and a strict one on a daily chart of a volatile small token.

Fitting lines

Triangles, wedges and channels are defined by lines, and there are two common ways to draw them:

  • Two-point lines through the two most significant swings: easy to verify by eye, but one outlier can tilt the whole line.
  • Least-squares fits through several swings: more robust to a single bad point, but the line may not touch any actual swing, so it can differ from the one you'd draw.

Slope rules then classify the shape. Both lines falling with the upper one steeper describes a falling wedge; a flat top above rising lows describes an ascending triangle. A convergence rule, such as requiring the latest range to be no more than about two-thirds of the opening range, separates a triangle from a parallel channel.

Breakout rules

A pattern becomes actionable only when price leaves it. Three choices define a breakout:

  • Close or wick? Requiring a close beyond the line ignores intrabar spikes; accepting a wick reacts sooner but triggers more false breakouts.
  • Buffer. Requiring price to clear the line by a margin, say 0.1%, filters marginal crosses at the cost of a slightly worse entry.
  • Freshness. Requiring the cross to happen on the latest bar stops the detector reporting a breakout from ten bars ago, after the entry has gone.

Timing is a further choice. Evaluating the bar that is still forming reacts sooner, but its "close" is only the latest price and the bar can finish back inside the pattern. Waiting for the bar to complete is cleaner, and slower.

Confirmation

Confirmation rules ask for evidence that the breakout is real: volume above its recent average, a breakout bar that closes in the breakout's direction, acceptable spread and liquidity. Each condition removes some false signals and some genuine ones, so a stricter detector is quieter, not automatically better.

Why lookback windows matter

A detector searches only a fixed number of recent bars. If a double bottom's first low sits 120 bars back and the window is 90 bars, the pattern doesn't exist as far as the detector is concerned, however clear it looks on a zoomed-out chart. Because windows are counted in bars, the same 90-bar window spans 7.5 hours on a 5-minute chart, 3.75 days of round-the-clock crypto trading on a 1-hour chart and three to four months on a daily chart. Longer windows find bigger formations but let stale structure in; shorter windows stay current but cap the size of what can be found.

Worked example: a double bottom

The prices below are hypothetical. Suppose a detector uses these double bottom rules, which are the ones PatternX uses: two consecutive swing lows 8–50 bars apart and within 2.5% of each other; a neckline at the highest swing high between them, at least 2% above the lows' average; the second low no more than 25 bars before the latest bar; a fresh close above the neckline on the latest bar; and breakout volume at least 1.2 times its 20-bar average. On a 1-hour chart, for example:

StepData (for example)Check
First swing low100.00, 52 bars agoLowest low within 3 bars either side
Second swing low101.20, 20 bars ago32 bars after the first (8–50) and within 25 bars of now
Equal lows1.20 apart, about 1.2%Within 2.5%
NecklineSwing high at 106.00 between the lows5.40 above their 100.60 average, about 5.4% (needs 2%)
BreakoutLatest bar at 106.40; the previous close was below 106.00Fresh close above the neckline
DirectionLatest bar trading above its openBreakout bar must close in the trade's direction
Volume1.5 times the 20-bar averageNeeds 1.2 times

The pattern's height is 106.00 − 100.60 = 5.40. The measured move target is 106.40 + 5.40 = 111.80, and the pattern stop sits 55% of the height below the neckline: 106.00 − 2.97 = 103.03. PatternX widens the pattern stop by a 0.2% buffer, to about 102.82, then compares both levels with your own settings, by default a 10% take-profit (about 117.04) and a 5% stop-loss (about 101.08), and keeps the tighter stop and the nearer target. Both pattern levels win here, so the trade risks about 3.58 to make 5.40, roughly 1.5 to 1. A setup below 1 to 1 would be dropped. If the universal market filters pass, the setup still needs a PatternX Score at or above your minimum confidence, 65 by default, to become a signal.

Now the caveat. The latest bar is still forming. If price slips back to 105.50 before it completes, the breakout has failed, but the signal was generated at 106.40. If the trade was taken, the stop is what protects it.

How PatternX implements it

  • Data: 200 candles per exchange, symbol and timeframe, with at least 60 required, on eight timeframes from 1 minute to 1 day.
  • Swing points: w = 3 for cup and handle, head and shoulders, double and triple patterns; w = 2 for triangles, wedges and rectangles. Pivots are therefore confirmed two or three bars late.
  • Windows: from about 41 bars for flags and pennants to 110 bars for triple tops and bottoms. Formations larger than the window aren't seen.
  • Breakout: each of the 20 detectors returns at most one match, and only when the breakout is on the latest bar, which may still be forming.
  • Confirmation: the same universal checks for every pattern: a breakout bar closing in the trade's direction, volume at least 1.2 times the 20-bar average, minimum volatility and liquidity, a spread no wider than 0.25%, an order book not heavily against the trade and, for crypto, at least $3M of 24-hour volume. No pattern has its own extra volume rule, and only rectangles check the trend before the pattern.
  • Context: the next timeframe up is checked for agreement; it changes the score but never rejects a signal.

The per-pattern rules are in the pattern library and the full engine in the pattern detection methodology.

Limitations

Rules can't capture every shape a person would accept, fixed windows miss large formations, and evaluating the latest bar means some breakouts fail before the bar completes. Labels such as "continuation" and "reversal" describe a pattern; they don't change how PatternX trades it. A detected pattern is a probability, not a promise.

Frequently asked questions

How does software identify a chart pattern?

It finds swing highs and lows in recent candles, checks whether they fit a pattern's measurements within set tolerances, then looks for a breakout through the pattern's key line. Confirmation rules, such as above-average volume, decide whether the breakout is reported.

Why does a scanner miss patterns I can see on the chart?

Usually the formation is bigger than the detector's lookback window, or one measurement falls just outside a tolerance. Many detectors also ignore patterns whose breakout isn't happening on the latest bar.

Can automated detection spot a pattern before it breaks out?

Most rule-based detectors, including PatternX's, report a pattern only when price breaks out of it, because an unbroken formation can still fail or change shape. Tools that flag patterns while they are still forming give more warning and more false starts.

Is automated pattern detection more accurate than drawing patterns by hand?

It is more consistent, because the same data always gives the same answer. Whether it is more accurate depends on whether its rules match the patterns you would actually trade.

Does the timeframe change what a pattern detector finds?

Yes. Lower timeframes produce more, noisier patterns; higher timeframes produce fewer, larger ones. Because windows are counted in bars, one detector covers hours on a 5-minute chart and months on a daily chart.

Related reading

Educational content, not financial advice. Chart patterns describe probabilities, not certainties; trading — especially with leverage or outside regular hours — can lose money, including more than you expect. See the risk disclaimer.