OPEN-SOURCE SCRIPT
已更新 Harmonic XABCD Pattern Detector

Overview
This overlay indicator scans the chart for classic XABCD harmonic formations using pivot-based structure detection. When a valid five-point pattern completes at pivot D, it draws the zigzag legs, labels key ratios, and optionally highlights the Potential Reversal Zone (PRZ) near D.
The script is designed for visual pattern recognition and education. It does not place orders, generate trade signals for automation, or guarantee future price behavior.
Supported patterns
Key features
How detection works
The script identifies swing pivots using configurable left/right bar settings, then evaluates consecutive pivot sequences against harmonic ratio rules. A pattern is drawn only after the pivot structure and ratio checks pass the selected mode (Strict or Soft).
Important: Pivot D is confirmed only after the configured Pivot Right Bars have closed. Until then, price action near the projected zone is handled by the See the Future module, not as a completed pattern.
Main settings
Alerts
Three optional alert conditions are available:
Limitations
This overlay indicator scans the chart for classic XABCD harmonic formations using pivot-based structure detection. When a valid five-point pattern completes at pivot D, it draws the zigzag legs, labels key ratios, and optionally highlights the Potential Reversal Zone (PRZ) near D.
The script is designed for visual pattern recognition and education. It does not place orders, generate trade signals for automation, or guarantee future price behavior.
Supported patterns
- Gartley
- Bat
- Butterfly
- Crab
- Deep Crab
- Cypher
- Shark
- AB=CD
- Three Drives (7-point structure)
Key features
- Strict and Soft modes — Strict uses fixed Fibonacci ratio rules. Soft applies a user-defined percentage tolerance around standard harmonic levels.
- PRZ box — Optional orange zone at D showing the projected reversal area.
- Structural stop line — Optional stop reference beyond D based on CD leg size and ATR buffer (visual reference only).
- Pattern score and confluence — Each completed pattern receives a quality score and a confluence count based on nearby pivot density.
- See the Future — When X-A-B-C is complete but D is not yet confirmed, the script can project possible D zones for active setups.
- On-chart table — Summary panel with pivot count, detection mode, pending projection status, average pattern score, and recent pattern history.
- Alerts — Optional alerts for pattern completion, future zone touch, and possible formation in the projected D zone.
How detection works
The script identifies swing pivots using configurable left/right bar settings, then evaluates consecutive pivot sequences against harmonic ratio rules. A pattern is drawn only after the pivot structure and ratio checks pass the selected mode (Strict or Soft).
Important: Pivot D is confirmed only after the configured Pivot Right Bars have closed. Until then, price action near the projected zone is handled by the See the Future module, not as a completed pattern.
Main settings
- Pivot Settings — Pivot left/right bars and maximum stored pivots.
- Filter Settings — Minimum leg size (ATR multiplier) and ATR period.
- Detection Mode — Strict vs Soft ratio control; Soft tolerance (%).
- Pattern Filters — Enable or disable individual harmonic types.
- Visual Settings — Labels, leg ratios, butterfly wings, PRZ, stop line, colors, and history table rows.
- See the Future — Projected D zones, zone merge, touch markers, and extension length.
- Storage — Maximum stored patterns for redraw and history.
- Alerts — Toggle alert conditions for completion and future-zone events.
- Analytics — Confluence ATR multiplier for pivot clustering near PRZ.
Alerts
Three optional alert conditions are available:
- Pattern Completed — a valid XABCD (or Three Drives) formation is detected and drawn.
- Future Zone Touched — price enters a projected D zone while XABC is still active.
- Possible Formation — price reaches an extremum inside a projected D zone before D is confirmed.
Limitations
- Harmonic patterns are subjective geometric models. Different pivot settings, timeframes, and tolerance modes will produce different results.
- Overlapping patterns are filtered, but dense or choppy markets may still produce frequent redraws on setting changes.
- The optional stop line is a structural visual reference, not a validated risk-management rule.
- See the Future projections are hypothetical until pivot D is confirmed by the pivot engine.
- This indicator runs on and is intended for manual chart analysis on TradingView.
Pine Script®
Disclaimer
This script is provided for informational and educational purposes only. It does not constitute investment advice, financial advice, trading advice, or a recommendation to buy or sell any instrument.
Trading involves substantial risk of loss. Past pattern occurrences do not guarantee future results. Always do your own research and consult a qualified financial professional before making trading decisions.
The author makes no warranties about the accuracy, completeness, or suitability of the detected patterns for any particular market or timeframe.
版本注释
Comment lines have been edited.版本注释
Several bugs in replay mode have been fixed.开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
Love for AlgoTrading
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
Love for AlgoTrading
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。