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
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。