OPEN-SOURCE SCRIPT

Classic Pattern Engine

533
Is a chart-pattern detection tool built around confirmed swing pivots.

The script identifies selected classic chart-pattern structures and draws them directly on the chart. It is designed as a visual pattern-mapping tool, not as an automated trading system.

What the script detects

Reversal patterns:
- Double Top
- Double Bottom
- Triple Top
- Triple Bottom
- Head and Shoulders
- Inverted Head and Shoulders

Continuation / structure patterns:
- Rectangles
- Ascending Triangle
- Descending Triangle
- Symmetrical Triangle
- Rising Wedge
- Falling Wedge
- Bull Flag
- Bear Flag
- Bullish Pennant
- Bearish Pennant

How it works

The script uses confirmed pivot highs and pivot lows to build a swing structure. It then compares the most recent confirmed swings against geometric conditions such as:

- Similarity of highs or lows
- Pattern height relative to ATR
- Slope of upper and lower boundaries
- Convergence or parallel behavior
- Pattern duration
- Flag or pennant context when applicable

Each detected pattern receives a quality score. This score is based on the geometry of the pattern, such as symmetry, height, similarity of key swing points, slope behavior, and structure fit. The score is intended to help users filter weaker shapes from cleaner structures.

Entry, Stop, and Target levels

The script can display Entry, Stop, and Target reference levels for detected patterns.

These levels are geometric references derived from the detected pattern structure. They are not trade recommendations.

The script can also track the state of the detected setup:

- Pending: the pattern is detected but entry has not been triggered
- Active: entry level has been reached
- Target Hit: price reached the target reference level
- Stop Hit: price reached the stop reference level
- Expired: the setup remained unresolved beyond the selected time window

The Entry label can also show an estimated R:R value based on the distance between Entry, Stop, and Target.

Main settings

Detection:
- Pivot strength
- Equality tolerance in ATR
- Minimum pattern height
- Minimum pattern quality
- Maximum pattern length

Display:
- Show only latest pattern
- Show pattern lines
- Show entry / stop / target levels
- Show R:R in entry label
- Fade inactive levels after result
- Entry / stop / target projection length
- Pattern line width
- Entry / stop / target line width
- Entry / stop / target label size

Colors:
- Pattern colors
- Entry line color
- Stop line color
- Target line color
- Entry text color
- Stop text color
- Target text color
- Resolved / inactive level styling

How to use

Use the indicator as a visual assistant for identifying and reviewing chart-pattern structures.

A detected pattern means the required swing geometry has formed. It does not mean that the pattern will complete successfully or that price will reach the target.

Users can choose to display only the latest pattern for a clean chart, or keep more visual history by changing the display settings.

Repainting note

This script uses confirmed pivot highs and confirmed pivot lows. A pattern can only be detected after the required pivot confirmation bars have passed.

For this reason, pattern drawings may appear on earlier swing points after confirmation. This is a normal confirmation delay caused by pivot-based detection.

The script does not use lookahead. Entry, stop, target, and state labels update only as new bars develop after a pattern has been detected.

Limitations

Chart patterns are geometric interpretations of price structure. Different traders may classify the same structure differently.

The displayed Entry, Stop, Target, and R:R values are reference levels calculated from the pattern geometry. They should not be treated as financial advice, trading instructions, or guaranteed outcomes.

The indicator is intended for chart analysis, education, and visual pattern review.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.