Tool
Chart Patterns
market.chart_patterns
Inputs
An optional stream of pre-computed swing pivots (highs and lows) for the detector to build patterns from. Wire in your own zigzag or swing source to control exactly which turning points count; leave it unconnected and the tool derives pivots internally from zigzag_depth and pivot_sensitivity.
Outputs
A bundle of detected chart patterns. Each match carries its family, the bars it spans, its key boundaries (neckline, rails, support/resistance), whether and where it broke out, and a projected price target sized by measure_factor_mode. Tap the bundle to gate entries on a specific pattern or to drive targets and stops.
Chart Patterns scans price for the classic geometric formations technical traders watch — double tops, head & shoulders, triangles, channels, wedges, flags, the cup and handle, and more. For each pattern it finds, it tells you the shape, where the breakout line sits, and a projected price target.
How it works
It reduces price to a zigzag of swing pivots (using zigzag_depth and pivot_sensitivity, or pivots you supply), then tests the recent pivot sequence against the geometry of every family you enable — equal highs/lows, converging or parallel trendlines, symmetry, and duration. A match is confirmed when price clears the pattern's boundary by breakout_threshold (in percent or ATR), optionally with a volume surge, and the target is projected from the pattern height by measure_factor_mode.
Modes
Families options
Two peaks at roughly the same high with a valley between — a bearish reversal that confirms when price breaks the neckline drawn under the middle trough.
When to use: Spotting a topping market: two failed pushes to the same ceiling, then a break of the swing low between them.
Two troughs at roughly the same low with a peak between — a bullish reversal that confirms when price breaks the neckline drawn over the middle peak.
When to use: Spotting a bottoming market: two failed pushes to the same floor, then a break of the swing high between them.
Price oscillates between a flat support floor and a flat resistance ceiling, building a horizontal range that resolves with a break of either edge.
When to use: Range / consolidation trading, or waiting for the range to break to take the move that follows.
A left shoulder, a higher head, then a lower right shoulder, all sitting on a neckline — the classic bearish reversal, confirmed on a neckline break.
When to use: Calling the end of an uptrend; the right-shoulder failure plus neckline break is the entry.
An inverse head and shoulders — left shoulder, deeper head, higher right shoulder under a neckline — a bullish reversal confirmed when price breaks up through the neckline.
When to use: Calling the end of a downtrend; the right-shoulder higher low plus neckline break is the entry.
Three peaks at roughly the same high separated by two troughs — a stronger bearish reversal than a double top, confirmed on a break below the shared support.
When to use: When price has failed three times at the same ceiling and you want the downside break.
Three troughs at roughly the same low separated by two peaks — a stronger bullish reversal than a double bottom, confirmed on a break above the shared resistance.
When to use: When price has held three times at the same floor and you want the upside break.
A sharp, near-vertical rally that tops in a single spike and reverses just as fast — a fast bearish reversal with no rounding or retest.
When to use: Catching a blow-off top: a parabolic push that snaps back hard the same or next bar.
A sharp, near-vertical sell-off that bottoms in a single spike and reverses just as fast — a fast bullish reversal with no rounding or retest.
When to use: Catching a capitulation low: a panic flush that snaps back up the same or next bar.
A gentle lead-in trend (the lead-in line) is followed by a steep, overextended 'bump', then price breaks back below the lead-in trendline and runs the other way.
When to use: Spotting an unsustainable acceleration that gives back the excess once the lead-in line breaks.
A flat resistance ceiling with a rising support line of higher lows — usually a bullish continuation that resolves with a break above the ceiling.
When to use: Continuation longs: higher lows pressing into a fixed ceiling that eventually gives way.
A flat support floor with a falling resistance line of lower highs — usually a bearish continuation that resolves with a break below the floor.
When to use: Continuation shorts: lower highs pressing into a fixed floor that eventually breaks.
Lower highs and higher lows converge into an apex — a neutral coiling pattern that breaks in the direction of the eventual escape, often the prior trend.
When to use: Volatility-squeeze continuation: trade the break of whichever converging line gives way first.
Price climbs between two parallel up-sloping lines — a rising channel; trend continuation while it holds, reversal warning if the lower rail breaks.
When to use: Trading a clean uptrend: buy the lower rail, watch for a break of it as the trend-change tell.
Price falls between two parallel down-sloping lines — a falling channel; trend continuation while it holds, reversal warning if the upper rail breaks.
When to use: Trading a clean downtrend: sell the upper rail, watch for a break of it as the trend-change tell.
Price ranges sideways between two flat parallel rails — a horizontal channel that trades like a rectangle until one rail breaks.
When to use: Sideways markets: fade the rails or wait for the rail break that starts the next trend.
Both rails slope up but converge, with the lower rail steeper — a tiring rally that usually resolves bearish on a break of the lower line.
When to use: Spotting an exhausting uptrend: a wedge that narrows upward and tends to break down.
Both rails slope down but converge, with the upper rail steeper — a tiring sell-off that usually resolves bullish on a break of the upper line.
When to use: Spotting an exhausting downtrend: a wedge that narrows downward and tends to break up.
A megaphone of higher highs and lower lows widening over time, formed near a high — rising volatility and instability that often resolves bearish.
When to use: Reading a choppy, expanding top where swings get wider instead of tighter.
A megaphone of higher highs and lower lows widening over time, formed near a low — expanding volatility that often resolves bullish out of the base.
When to use: Reading a choppy, expanding bottom where swings get wider before a resolution higher.
A steep rally (the flagpole) followed by a small down-sloping consolidation channel — a bullish continuation that breaks up out of the flag.
When to use: Continuation longs after a strong impulse: buy the break out of the pullback channel.
A steep drop (the flagpole) followed by a small up-sloping consolidation channel — a bearish continuation that breaks down out of the flag.
When to use: Continuation shorts after a strong impulse down: sell the break out of the bounce channel.
A sharp move followed by a small symmetrical-triangle pause that converges to a point — a brief continuation that breaks in the direction of the prior impulse.
When to use: Continuation after a fast move: trade the break of the little coil in the trend's direction.
Price arcs over in a slow, smooth dome — a gradual bearish reversal where the uptrend rolls over into a downtrend without a sharp pivot.
When to use: Reading a slow distribution top where momentum quietly fades and rolls down.
Price arcs through a slow, smooth saucer — a gradual bullish reversal where the downtrend rounds out into an uptrend without a sharp pivot.
When to use: Reading a slow accumulation base where selling quietly dries up and turns up.
A rounded saucer (the cup) followed by a small downward drift (the handle) just under the rim — a bullish continuation that breaks out above the rim.
When to use: Continuation longs from a long base: buy the breakout over the rim after the handle pulls back.
A rounded dome (the inverted cup) followed by a small upward drift (the handle) just above the rim — a bearish continuation that breaks down below the rim.
When to use: Continuation shorts from a topping dome: sell the breakdown under the rim after the handle bounces.
Swings first broaden then contract, tracing a diamond near a high — a bearish reversal that confirms on a break of the lower converging line.
When to use: Reading a top that flares out into a megaphone then coils back in before rolling over.
Swings first broaden then contract, tracing a diamond near a low — a bullish reversal that confirms on a break of the upper converging line.
When to use: Reading a base that flares out into a megaphone then coils back in before turning up.
Two roughly equal up-legs joined by a corrective pullback — the first leg projects the size of the second, so the move 'measures' its own target.
When to use: Projecting an upside target: the AB leg up, a BC pullback, then a CD leg that mirrors AB.
Two roughly equal down-legs joined by a corrective bounce — the first leg projects the size of the second, so the move 'measures' its own downside target.
When to use: Projecting a downside target: the AB leg down, a BC bounce, then a CD leg that mirrors AB.
Breakout mode options
A break counts only once price clears the pattern boundary by breakout_threshold expressed as a percent of price — a scale-free filter that behaves the same on a $1 stock and a $2,000 index.
When to use: The portable default: when you want the same breakout buffer to mean the same thing across symbols of very different price.
A break counts only once price clears the pattern boundary by breakout_threshold multiples of ATR — the buffer auto-widens in volatile conditions and tightens in calm ones.
When to use: When you want the breakout filter to adapt to current volatility instead of a fixed percent, so noisy markets need a bigger push to confirm.
Measure factor mode options
The projected target uses Bulkowski's statistically measured fraction of the pattern height — typically less than the full height, because most patterns historically fall short of the textbook 1:1 projection.
When to use: The realistic default: when you want price targets sized to how far these patterns actually tend to run, not the ideal full measure.
The projected target uses the entire pattern height measured 1:1 from the breakout point — the classic textbook objective, which is more ambitious than the Bulkowski partial.
When to use: When you want the traditional full-height target, accepting that price reaches it less often than the partial measure.
Configuration
Which chart-pattern families the detector scans for. Tick on every pattern you care about — 31 are available, from reversals (double top/bottom, head & shoulders, triple top/bottom) through triangles, channels, wedges, flags, and the cup and handle. Each toggled family contributes its own matches to the output bundle.
The minimum swing depth (in bars) the underlying zigzag must travel before it plants a new pivot. Larger values keep only the bigger swings, so patterns are built from major turns and small wiggles are ignored; smaller values pick up finer structure but admit more noise.
How readily a local high or low is accepted as a pattern pivot. Higher sensitivity registers more turning points (more candidate patterns, more false positives); lower sensitivity demands cleaner, more pronounced swings before counting a pivot.
How close two peaks (or two troughs) must be in price, as a percent, to count as 'equal' — the test that lets a double top, triple top, or rectangle qualify. Larger tolerance accepts rougher matches; tighter tolerance demands near-identical highs or lows.
The minimum number of pivots a trendline must touch before it is treated as a valid pattern boundary (a triangle, channel, or wedge rail). More touches mean a better-confirmed line but fewer patterns; the usual floor is 2-3 touches per line.
How much the slope of a line is allowed to deviate and still count as 'flat' or 'parallel' — this decides whether a near-flat top is a rectangle vs an ascending triangle, or whether two rails are parallel enough to be a channel. Larger tolerance is more forgiving of imperfect geometry.
How balanced the two halves of a symmetric pattern must be — left vs right shoulder height in head & shoulders, or the two converging sides of a symmetrical triangle or diamond. Larger tolerance accepts lopsided shapes; tighter tolerance demands clean symmetry.
The fewest bars a pattern may span and still qualify. Raising it filters out tiny, fast formations that are mostly noise; lowering it lets short patterns through. Sets the floor of the size window together with max_duration_bars.
The most bars a pattern may span and still qualify. Caps how stretched-out a formation can be before the detector stops treating it as one pattern; should be comfortably larger than min_duration_bars.
Which units breakout_threshold is measured in: 'percent' uses a percent of price (scale-free across symbols), 'atr' uses multiples of ATR (adapts to current volatility).
How far price must clear the pattern boundary before the break is confirmed. Its units depend on breakout_mode: a percent of price in 'percent' mode, or a multiple of ATR in 'atr' mode. Larger values demand a more decisive break and cut false breakouts; smaller values confirm sooner.
How much heavier breakout volume must be than the pattern's average for the break to count as volume-confirmed — e.g. 1.5 means 50% above average. Set it to require a volume surge on the break; lower it (or 1.0) to ignore volume.
How many bars after a breakout the detector keeps watching for a retest of the broken boundary (the boundary flipping from resistance to support, or vice versa). A wider window catches slower retests; 0 disables retest tracking.
How the projected price target is sized from the pattern height: 'bulkowski_p' uses Bulkowski's statistically measured partial fraction (realistic), 'full_height' projects the entire height 1:1 (the textbook objective).
Connects to
Examples
- Reversal signal: enable head_shoulders_top and gate short entries to bars where a confirmed neckline break prints.
- Continuation filter: enable flag_bull and triangle_ascending and only take longs when one of them breaks out with volume_confirmation_ratio met.
- Target driver: read the projected target off a detected double_bottom (sized by measure_factor_mode) to place your take-profit.
Common mistakes
- Enabling all 31 families at once on a fast timeframe — you drown in overlapping, low-quality matches; pick the few patterns your strategy actually trades.
- Setting breakout_threshold too small, so every minor poke through a boundary counts as a breakout and you get whipsawed by fake-outs.
- Expecting the full-height target to be hit reliably — most patterns fall short, which is exactly why the Bulkowski partial measure exists.