OPEN-SOURCE SCRIPT
Auto Chart Patterns- Market Adapted

Auto Chart Patterns [Market Adapted] - Code Description
This Pine Script v5 indicator is a sophisticated automated chart pattern detection system that identifies geometric price patterns using zigzag analysis. Here's a comprehensive breakdown:
🎯 Purpose
Automatically detects and visualizes classic chart patterns (channels, wedges, triangles) on any timeframe by analyzing price pivot points.
📦 Dependencies (Imports)
text
- HeWhoMustNotBeNamed/utils/1 → Utility functions (theme colors)
- Trendoscope/ohlc/1 → OHLC data handling
- Trendoscope/LineWrapper/1 → Line drawing utilities
- Trendoscope/ZigzagLite/2 → Zigzag pivot detection
- Trendoscope/abstractchartpatterns/5 → Pattern definitions
- Trendoscope/basechartpatterns/6 → Pattern recognition logic
⚙️ Input Parameters
1. Source Settings
Custom OHLC sources (default: standard OHLC)
2. Zigzag Settings (4 Independent Zigzags)
Zigzag Enabled Length Depth Purpose
ZZ1 ✅ 8 55 Primary - catches larger swings
ZZ2 ✅ 13 34 Secondary - medium swings
ZZ3 ❌ 21 21 Tertiary - balanced
ZZ4 ❌ 34 13 Quaternary - smaller swings
3. Scanning Parameters
Parameter Default Description
numberOfPivots 5 Points needed for pattern (5 or 6)
errorThreshold 30% Tolerance for trendline validation
flatThreshold 20% Slope ratio for "flat" determination
lastPivotDirection both Filter by final pivot direction
checkBarRatio false Validate time proportionality
avoidOverlap true Prevent overlapping patterns
repaint true Use real-time or confirmed bars
4. Pattern Groups
Geometric Shapes:
✅ Channels
✅ Wedges
✅ Triangles
Direction:
✅ Rising
✅ Falling
✅ Flat/Bi-Directional
Formation Dynamics:
✅ Expanding
✅ Contracting
✅ Parallel
📊 Detected Pattern Types (14 Total)
text
INDEX | PATTERN TYPE | CATEGORY
------|--------------------------------|------------------
1 | Ascending Channel | Parallel/Rising
2 | Descending Channel | Parallel/Falling
3 | Ranging Channel | Parallel/Flat
4 | Rising Expanding Wedge | Expanding/Rising
5 | Falling Expanding Wedge | Expanding/Falling
6 | Diverging Triangle | Expanding/Flat
7 | Ascending Expanding Triangle | Expanding/Rising
8 | Descending Expanding Triangle | Expanding/Falling
9 | Rising Contracting Wedge | Contracting/Rising
10 | Falling Contracting Wedge | Contracting/Falling
11 | Converging Triangle | Contracting/Flat
12 | Descending Contracting Triangle| Contracting/Falling
13 | Ascending Contracting Triangle | Contracting/Rising
🏗️ Core Architecture
Scanner Type (Custom Object)
JavaScript
type Scanner
bool enabled
string ticker
string timeframe
ScanProperties sProperties // Scanning configuration
DrawingProperties dProperties // Visual settings
array<Pattern> patterns // Detected patterns storage
array<Zigzag> zigzags // Zigzag pivots storage
Key Methods
getZigzagAndPattern()
Calculates zigzag pivots from price data
When new pivot detected → scans for patterns
Requires minimum 6 pivots in buffer
Uses multi-level zigzag analysis
Validates patterns against allowed configurations
scan()
Creates OHLC array from sources
Iterates through enabled zigzags (1-4)
Calls pattern detection for each zigzag configuration
🔄 Execution Flow
text
1. Initialize Scanner with all properties
2. On each bar (confirmed or real-time based on 'repaint'):
│
├─→ Build OHLC array
│
├─→ For each enabled Zigzag:
│ ├─→ Calculate pivots
│ ├─→ If new pivot detected:
│ │ ├─→ Scan for valid patterns
│ │ ├─→ Draw pattern if found
│ │ ├─→ Store in patterns array
│ │ ├─→ Trim old patterns (if > maxPatterns)
│ │ └─→ Trigger alert
│ └─→ Move to next zigzag level
│
└─→ Repeat on next bar
🎨 Display Features
Theme: Light/Dark mode
Pattern lines: Customizable width
Labels: Pattern name + pivot labels (with size options)
Zigzag: Optional display with custom color
Pattern limit: Auto-deletes oldest when exceeding max (default: 20)
⚡ Alerts
Triggers 'New Pattern Alert' when any valid pattern is detected.
💡 "Market Adapted" Features
Dual zigzag enabled by default (ZZ1 + ZZ2) for multi-timeframe sensitivity
Higher error threshold (30%) for volatile markets
Flexible pivot direction filtering per pattern type
Overlap avoidance to reduce noise
This Pine Script v5 indicator is a sophisticated automated chart pattern detection system that identifies geometric price patterns using zigzag analysis. Here's a comprehensive breakdown:
🎯 Purpose
Automatically detects and visualizes classic chart patterns (channels, wedges, triangles) on any timeframe by analyzing price pivot points.
📦 Dependencies (Imports)
text
- HeWhoMustNotBeNamed/utils/1 → Utility functions (theme colors)
- Trendoscope/ohlc/1 → OHLC data handling
- Trendoscope/LineWrapper/1 → Line drawing utilities
- Trendoscope/ZigzagLite/2 → Zigzag pivot detection
- Trendoscope/abstractchartpatterns/5 → Pattern definitions
- Trendoscope/basechartpatterns/6 → Pattern recognition logic
⚙️ Input Parameters
1. Source Settings
Custom OHLC sources (default: standard OHLC)
2. Zigzag Settings (4 Independent Zigzags)
Zigzag Enabled Length Depth Purpose
ZZ1 ✅ 8 55 Primary - catches larger swings
ZZ2 ✅ 13 34 Secondary - medium swings
ZZ3 ❌ 21 21 Tertiary - balanced
ZZ4 ❌ 34 13 Quaternary - smaller swings
3. Scanning Parameters
Parameter Default Description
numberOfPivots 5 Points needed for pattern (5 or 6)
errorThreshold 30% Tolerance for trendline validation
flatThreshold 20% Slope ratio for "flat" determination
lastPivotDirection both Filter by final pivot direction
checkBarRatio false Validate time proportionality
avoidOverlap true Prevent overlapping patterns
repaint true Use real-time or confirmed bars
4. Pattern Groups
Geometric Shapes:
✅ Channels
✅ Wedges
✅ Triangles
Direction:
✅ Rising
✅ Falling
✅ Flat/Bi-Directional
Formation Dynamics:
✅ Expanding
✅ Contracting
✅ Parallel
📊 Detected Pattern Types (14 Total)
text
INDEX | PATTERN TYPE | CATEGORY
------|--------------------------------|------------------
1 | Ascending Channel | Parallel/Rising
2 | Descending Channel | Parallel/Falling
3 | Ranging Channel | Parallel/Flat
4 | Rising Expanding Wedge | Expanding/Rising
5 | Falling Expanding Wedge | Expanding/Falling
6 | Diverging Triangle | Expanding/Flat
7 | Ascending Expanding Triangle | Expanding/Rising
8 | Descending Expanding Triangle | Expanding/Falling
9 | Rising Contracting Wedge | Contracting/Rising
10 | Falling Contracting Wedge | Contracting/Falling
11 | Converging Triangle | Contracting/Flat
12 | Descending Contracting Triangle| Contracting/Falling
13 | Ascending Contracting Triangle | Contracting/Rising
🏗️ Core Architecture
Scanner Type (Custom Object)
JavaScript
type Scanner
bool enabled
string ticker
string timeframe
ScanProperties sProperties // Scanning configuration
DrawingProperties dProperties // Visual settings
array<Pattern> patterns // Detected patterns storage
array<Zigzag> zigzags // Zigzag pivots storage
Key Methods
getZigzagAndPattern()
Calculates zigzag pivots from price data
When new pivot detected → scans for patterns
Requires minimum 6 pivots in buffer
Uses multi-level zigzag analysis
Validates patterns against allowed configurations
scan()
Creates OHLC array from sources
Iterates through enabled zigzags (1-4)
Calls pattern detection for each zigzag configuration
🔄 Execution Flow
text
1. Initialize Scanner with all properties
2. On each bar (confirmed or real-time based on 'repaint'):
│
├─→ Build OHLC array
│
├─→ For each enabled Zigzag:
│ ├─→ Calculate pivots
│ ├─→ If new pivot detected:
│ │ ├─→ Scan for valid patterns
│ │ ├─→ Draw pattern if found
│ │ ├─→ Store in patterns array
│ │ ├─→ Trim old patterns (if > maxPatterns)
│ │ └─→ Trigger alert
│ └─→ Move to next zigzag level
│
└─→ Repeat on next bar
🎨 Display Features
Theme: Light/Dark mode
Pattern lines: Customizable width
Labels: Pattern name + pivot labels (with size options)
Zigzag: Optional display with custom color
Pattern limit: Auto-deletes oldest when exceeding max (default: 20)
⚡ Alerts
Triggers 'New Pattern Alert' when any valid pattern is detected.
💡 "Market Adapted" Features
Dual zigzag enabled by default (ZZ1 + ZZ2) for multi-timeframe sensitivity
Higher error threshold (30%) for volatile markets
Flexible pivot direction filtering per pattern type
Overlap avoidance to reduce noise
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.