XAUUSD Harmonic Patterns [MatsukazeAlgo]🇬🇧 ENGLISH
An automatic harmonic pattern detector optimized for Gold (XAUUSD). Identifies Bat, Gartley, Butterfly, Crab, Shark, and ABCD patterns, then tracks whether each pattern's D-point reversal actually succeeded. Session-aware success rate statistics reveal that not all harmonic completions are equal on Gold.
Concepts
Harmonic Patterns — Harmonic patterns are XABCD price structures where the ratios between legs match specific Fibonacci relationships. When the ratios align within tolerance, point D becomes a Potential Reversal Zone (PRZ). The premise is that markets retrace and extend in proportions that repeat across instruments and timeframes. This indicator detects five classical 5-point patterns (Bat, Gartley, Butterfly, Crab, Shark) and one 4-point pattern (ABCD).
Success Rate Tracking — Most harmonic indicators stop at detection. They show you a pattern but never tell you if it worked. This indicator tracks every detected pattern after point D completes. A pattern is marked as "Win" if price retraces 38.2% of the CD leg from D in the expected direction. It is marked as "Fail" if price moves 20% of the CD leg against the expected direction, or if 200 bars pass without resolution. The stats table shows win rates broken down by session.
Session Reliability — On Gold, harmonic patterns completing during London and NY sessions have higher success rates than those completing during Asia. This happens because institutional volume during London/NY backs the reversal at point D. Asia completions often fail due to thin liquidity. The indicator communicates this through session-coloured XABCD lines and a per-session win rate table.
Fibonacci Overlay — When a pattern completes, Fibonacci retracement levels (0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.0) are drawn from point C to point D, providing take-profit reference zones.
How It Works
1. Pivot Detection: The indicator scans for pivot highs and lows using a configurable lookback window. Pivots are stored in rolling arrays.
2. Pattern Matching: All valid XABCD combinations are tested against each pattern's Fibonacci ratio requirements with early-exit optimization. AB/XA and BC/AB are range-checked first before expensive ratio comparisons.
3. Session Tagging: Each detected pattern is tagged with the session it completed in (Asia / London / NY) and drawn in the corresponding session colour.
4. Success Tracking: Each pattern's D-point is registered with a target (38.2% CD retracement) and invalidation (20% CD adverse move). On every confirmed bar, all pending patterns are checked. Win/fail counts are accumulated per session.
5. Cleanup: Resolved patterns older than 300 bars are removed from tracking. Unresolved patterns expire after 200 bars.
Pattern Ratio Reference
Bat: AB/XA=0.382, BC/AB=0.886, CD/BC=1.618, AD/XA=0.886
Gartley: AB/XA=0.618, BC/AB=0.618, CD/BC=1.272, AD/XA=0.786
Butterfly: AB/XA=0.786, BC/AB=0.618, CD/BC=1.618, AD/XA=1.270
Crab: AB/XA=0.618, BC/AB=0.886, CD/BC=2.240, AD/XA=1.618
Shark: AB/XA=0.618, BC/AB=1.130, CD/BC=1.618, AD/XA=0.886
ABCD: BC/AB=0.382–0.886, CD/BC=1.13–2.618
Gold-Specific Features
Session Success Rate Table — The core analytical feature. Tracks win rates per session (Asia / London / NY) with pattern counts. London/NY completions consistently outperform Asia on Gold. Use this to weight your conviction when a pattern completes.
Session Colouring — XABCD lines and labels are drawn in the session colour where the pattern completed: Asia (rose), London (teal), NY (sky). At a glance, you know the session context.
Psychological PRZ Confluence — When point D lands near a $50 or $100 round number, the pattern marker turns gold. Gold respects round numbers as institutional order clusters. A harmonic PRZ at a psychological level carries higher probability.
DXY Alignment — When a bullish pattern completes while DXY is falling (or bearish while DXY is rising), the pattern aligns with the macro Gold/Dollar inverse correlation. Shown in the stats table.
Minimal Pattern Marker — Each pattern completion is marked with a subtle ▲ or ▼ in the session colour (or gold for psych confluence). No cluttered text labels.
Alerts
4 alert types: Pattern Detected, Psych Confluence, DXY Aligned, Bullish Pattern.
Input Reference
Patterns — Individual toggles for Bat, Gartley, Butterfly, Crab, Shark, and ABCD. Show Bearish toggles bearish pattern scanning.
Settings — Max Patterns: maximum simultaneous patterns on chart (default 2). Pivot Lookback: bars required to confirm a pivot (default 5, lower = more patterns, higher = stronger pivots). Depth: number of pivots stored in memory (default 20). Tolerance: acceptable deviation from ideal Fibonacci ratios (default 15%). Scan Every N Bars: reduces CPU load on large datasets (default 10).
Display — Show Fibonacci: toggle the C→D retracement levels. Show Lines: toggle the XABCD pattern lines. Show Labels: toggle the X/A/B/C/D point labels.
Gold Settings — Psych PRZ Confluence: detect $50/$100 round numbers near point D. Confluence Colour: colour for the psych marker (default gold). DXY Alignment: show DXY direction in the stats table.
Stats Table — Show Table, Position (9 positions), Text Size, Text Colour, Title Colour. The table auto-populates as patterns form, complete, and resolve throughout the chart's loaded history.
Alerts — Individual toggles for each of the 4 alert conditions. All default to on.
Conclusion
XAUUSD Harmonic Patterns goes beyond detection by tracking actual outcomes. The session win rate table answers the question every harmonic trader asks: "Does this pattern actually work?" On Gold, the answer depends on when it completes. London and NY completions consistently outperform Asia. The psychological level confluence and DXY alignment add institutional context that generic harmonic tools miss.
Recommended timeframe: 15min–1H on XAUUSD.
---
Based on Harmonic Patterns + Fib by venusbtc . This version adds session-based success rate tracking, session-coloured XABCD lines, psychological PRZ confluence, DXY alignment, minimal pattern markers, alert conditions, and MatsukazeAlgo colour palette.
---
🇯🇵 日本語
ゴールド(XAUUSD)に最適化されたハーモニックパターン自動検出ツールです。Bat、Gartley、Butterfly、Crab、Shark、ABCDパターンを検出し、各パターンのD点反転が実際に成功したかを追跡します。セッション別の成功率統計により、ゴールドでは全てのパターン完成が等しくないことが明らかになります。
コンセプト
ハーモニックパターン — XABCDの5点価格構造で、レッグ間の比率が特定のフィボナッチ関係に一致するものです。比率が許容範囲内で一致すると、D点がPotential Reversal Zone(PRZ)になります。市場は繰り返す比率でリトレースと延長を行うという前提に基づいています。5点パターン5種(Bat、Gartley、Butterfly、Crab、Shark)と4点パターン1種(ABCD)を検出します。
成功率追跡 — ほとんどのハーモニックインジケーターは検出で止まります。パターンを表示しますが、それが機能したかは教えてくれません。このインジケーターはD点完成後の全パターンを追跡します。価格がD点から期待方向にCD脚の38.2%戻せば「Win」。逆方向にCD脚の20%動くか、200バー経過で未解決なら「Fail」。統計テーブルにセッション別勝率を表示します。
セッション別信頼性 — ゴールドでは、London/NYセッション中に完成したハーモニックパターンはAsiaより高い成功率を持ちます。London/NYの機関投資家ボリュームがD点の反転を裏付けるためです。Asia完成は薄い流動性により失敗しやすい。セッション色のXABCDラインとセッション別勝率テーブルでこれを伝えます。
フィボナッチオーバーレイ — パターン完成時にC→Dのフィボナッチリトレースメントレベル(0、0.236、0.382、0.5、0.618、0.786、1.0)を描画。利確の参照ゾーンを提供します。
仕組み
1. ピボット検出:設定可能なルックバックでピボット高値/安値を走査。ローリング配列に保存。
2. パターンマッチング:有効なXABCD組み合わせを各パターンのフィボナッチ比率要件に対してテスト。早期exit最適化付き。
3. セッションタグ付け:検出パターンに完成セッション(Asia/London/NY)をタグ付け。対応するセッション色で描画。
4. 成功追跡:各パターンのD点をターゲット(CD 38.2%戻し)と無効化(CD 20%逆行)で登録。確定バーごとに全pending パターンをチェック。セッション別に勝敗を集計。
5. クリーンアップ:解決済みパターンは300バー後に自動削除。未解決パターンは200バーで期限切れ。
パターン比率リファレンス
Bat: AB/XA=0.382, BC/AB=0.886, CD/BC=1.618, AD/XA=0.886
Gartley: AB/XA=0.618, BC/AB=0.618, CD/BC=1.272, AD/XA=0.786
Butterfly: AB/XA=0.786, BC/AB=0.618, CD/BC=1.618, AD/XA=1.270
Crab: AB/XA=0.618, BC/AB=0.886, CD/BC=2.240, AD/XA=1.618
Shark: AB/XA=0.618, BC/AB=1.130, CD/BC=1.618, AD/XA=0.886
ABCD: BC/AB=0.382–0.886, CD/BC=1.13–2.618
ゴールド専用機能
セッション別成功率テーブル — コア分析機能。Asia/London/NYごとのパターン勝率とパターン数を追跡。ゴールドではLondon/NY完成がAsiaを一貫して上回ります。パターン完成時の確信度の重み付けに使用。
セッションカラーリング — XABCDラインとラベルをパターン完成セッション色で描画:Asia(ローズ)、London(ティール)、NY(スカイ)。一目でセッション文脈がわかります。
心理的PRZ合流 — D点が$50/$100のラウンドナンバー付近にある場合、パターンマーカーがゴールド色に。ゴールドはラウンドナンバーを機関投資家の注文クラスターとしてリスペクトします。心理的価格帯のPRZ = 高確率。
DXYアライメント — ブルパターンがDXY下落中に完成(またはベアがDXY上昇中)の場合、ゴールド/ドル逆相関とのマクロ整合を示します。統計テーブルに表示。
ミニマルパターンマーカー — 各パターン完成をセッション色(心理的合流時はゴールド色)の控えめな▲/▼で表示。テキストラベルなし。
アラート
4種類:パターン検出、心理的合流、DXY整合、強気パターン。
入力パラメータ
パターン — Bat、Gartley、Butterfly、Crab、Shark、ABCDの個別トグル。ベアリッシュ表示のトグル。
設定 — 最大パターン数:チャート上の同時表示数(デフォルト2)。ピボット長:ピボット確定に必要なバー数(デフォルト5、低い=多い、高い=強い)。深さ:メモリに保存するピボット数(デフォルト20)。許容範囲:理想的なフィボナッチ比率からの許容偏差(デフォルト15%)。スキャン間隔:大きなデータセットでのCPU負荷軽減(デフォルト10バー)。
表示 — フィボナッチ表示:C→Dリトレースメントレベル。ライン表示:XABCDパターンライン。ラベル表示:X/A/B/C/Dポイントラベル。
ゴールド設定 — 心理的PRZ合流:D点付近の$50/$100検出。合流色:マーカー色(デフォルトゴールド)。DXYアライメント:統計テーブルのDXY方向表示。
統計テーブル — テーブル表示、位置(9か所)、文字サイズ、文字色、タイトル色。チャートの読み込み履歴全体でパターンの形成・完成・解決に応じて自動集計。
アラート — 4種類のアラート条件それぞれに個別トグル。すべてデフォルトON。
まとめ
XAUUSD Harmonic Patternsは検出の先に進み、実際の結果を追跡します。セッション別勝率テーブルは、全てのハーモニックトレーダーが問う「このパターンは本当に機能する?」に答えます。ゴールドでは、答えは完成タイミングによります。London/NY完成がAsiaを一貫して上回ります。心理的価格帯の合流とDXYアライメントは、汎用的なハーモニックツールでは見えない機関投資家の文脈を加えます。
推奨時間足:15分〜1時間(XAUUSD)
---
Based on Harmonic Patterns + Fib by venusbtc . セッション別成功率追跡、セッション色XABCDライン、心理的PRZ合流、DXYアライメント、ミニマルパターンマーカー、アラート、MatsukazeAlgoカラーパレットを追加。
Wskaźnik Pine Script®






















