PROTECTED SOURCE SCRIPT
Güncellendi Harmonic Pattern Detector [The_lurker]

📊 Harmonic Pattern Detector
An advanced indicator designed to automatically detect and visualize harmonic patterns on price charts with high accuracy. It is based on Fibonacci ratios, ZigZag structures, and pivot points, offering traders precise identification of potential reversal zones.
The indicator supports detection of 13 major harmonic patterns: Gartley, Butterfly, Bat, Crab, Deep Crab, AB=CD, Cypher, Shark, Three Drives, Wolfe Waves, 5-0, Black Swan, and Anti-Gartley.
Each pattern is matched using ideal Fibonacci ratios with a customizable error margin. Patterns are validated only if the similarity score (accuracy) is greater than or equal to 80%, ensuring reliable signals.
🔎 How It Works:
1️⃣ Pivot Point Detection
The indicator uses a function to find major swing highs and lows (`findPivots`), based on a configurable pattern length (default is 18 candles). These pivots are stored in arrays: `pivotPrices`, `pivotBars`, and `pivotDirections`.
2️⃣ ZigZag Construction
With the pivots detected, the indicator constructs a ZigZag structure by connecting the relevant price points using `buildZigZag`. These lines represent the fundamental price movements forming harmonic shapes.
3️⃣ Fibonacci Ratio Calculation
From the ZigZag, the indicator extracts points labeled X, A, B, C, and D, then calculates key Fibonacci ratios:
* XAB = |B-A| / |X-A|
* ABC = |C-B| / |A-B|
* XAD = |D-A| / |X-A|
4️⃣ Pattern Matching Algorithm
Each pattern has its ideal Fibonacci ranges. The ratios are compared with these ranges using adjustable error margins:
ERROR_MARGIN_MIN = (100 - DETECT_ERROR_MARGIN_PERCENT) / 100
ERROR_MARGIN_MAX = (100 + DETECT_ERROR_MARGIN_PERCENT) / 100
If all required ratios for a pattern fall within these bounds, the pattern is considered a potential match.
5️⃣ Similarity Score Calculation
To evaluate accuracy, each pattern gets a similarity score by comparing actual vs. ideal ratios. For example:
simXAB = min(xabRatio / idealXAB, idealXAB / xabRatio)
simABC = min(abcRatio / idealABC, idealABC / abcRatio)
simXAD = min(xadRatio / idealXAD, idealXAD / xadRatio)
similarity = (simXAB + simABC + simXAD) / 3
Only patterns with a similarity ≥ MIN\_RATING\_PERCENT (default 80%) are shown.
6️⃣ Visual Output
When a pattern is detected, it is displayed by connecting the points X→A→B→C→D. A label is drawn at point D showing:
* Pattern Name
* Emoji (e.g., 🦋 for Gartley)
* Similarity percentage (e.g., "92%")
Patterns are color-coded:
🟢 Green for Bullish
🔴 Red for Bearish
⚙️ Configurable Settings:
* ENABLE_PATTERN_DETECTION`: Toggle to enable or disable pattern detection
* PATTERN_LENGTH_INPUT`: Number of candles to consider for structure
* DETECT_ERROR_MARGIN_PERCENT`: Controls allowed deviation from ideal Fibonacci ratios
* MIN_RATING_PERCENT`: Minimum similarity percentage to display a pattern (e.g., 80%)
🎨 Display Customization:
* Customize ZigZag lines (solid, dotted, dashed)
* Control thickness, color, and style of lines
* Adjust label font size, position, and visibility
* Enable or disable specific pattern types
* Modify Fibonacci levels used per pattern
Labels include emojis for easier recognition:
🦋 Gartley | 🐝 Butterfly | 🦈 Shark | 🐺 Wolfe Waves | 🦢 Black Swan | ⚡ Anti-Gartley
📚 Pattern Definitions:
Gartley: XAB ≈ 0.618, ABC ≈ 0.382–0.886, XAD ≈ 0.786
Butterfly: XAB ≈ 0.786, XAD ≈ 1.272
Bat: XAB ≈ 0.382–0.50, XAD ≈ 0.886
Crab / Deep Crab: XAD ≈ 1.618–1.902
AB=CD: AB equals CD (symmetrical moves)
Cypher: ABC ≈ 1.13–1.414, XAD ≈ 0.786
Shark: XAD ≈ 1.0–1.13
Three Drives: Three legs with Fibonacci extensions
Wolfe Waves: Geometrically aligned points, XAD ≈ 1.272–1.618
5-0: CD retraces 50% of previous wave
Black Swan: Rare, sharp pattern, XAD ≈ 3.618–4.236
Anti-Gartley: Reverse Gartley with custom ratios
📈 Target Markets:
This indicator is effective for analyzing:
✔ Forex
✔ Stocks
✔ Crypto
✔ Commodities (Gold, Oil, etc.)
Suitable for multiple trading styles:
* Scalping
* Swing Trading
* Position Trading
✨ Key Features:
✅ 13 harmonic patterns supported
✅ Automatic detection with accuracy scoring
✅ Adjustable error margins
✅ Fully customizable display
✅ Pattern-specific toggles
✅ Bullish/Bearish color-coded output
✅ Informative labels with pattern name, emoji, and similarity
⚠️ Disclaimer:
This indicator is for educational and analytical purposes only. It does not constitute financial, investment, or trading advice. Use it in conjunction with your own strategy and risk management. Neither TradingView nor the developer is liable for any financial decisions or losses.
كاشف الأنماط التوافقية 📊
مؤشر متطور مصمم للكشف التلقائي عن الأنماط التوافقية على مخططات الأسعار وتصورها بدقة عالية. يعتمد على نسب فيبوناتشي، وهياكل الزجزاج، ونقاط الارتكاز، مما يوفر للمتداولين تحديدًا دقيقًا لمناطق الانعكاس المحتملة.
يدعم المؤشر الكشف عن 13 نمطًا توافقيًا رئيسيًا: جارتلي، الفراشة، الخفاش، السلطعون، السلطعون العميق، AB=CD، السايفر، القرش، ثلاثة محركات، موجات وولف، 5-0، البجعة السوداء، ومضاد جارتلي.
يتم مطابقة كل نمط باستخدام نسب فيبوناتشي مثالية مع هامش خطأ قابل للتخصيص. لا يتم التحقق من صحة الأنماط إلا إذا كانت درجة التشابه (الدقة) أكبر من أو تساوي 80%، مما يضمن إشارات موثوقة.
🔎 كيفية العمل:
1️⃣ اكتشاف نقاط الارتكاز
يستخدم المؤشر دالة للعثور على قمم وقيعان التأرجح الرئيسية (`findPivots`)، بناءً على طول نمط قابل للتخصيص (الطول الافتراضي هو 18 شمعة). تُخزّن هذه النقاط المحورية في مصفوفات: `pivotPrices`، `pivotBars`، `pivotDirections`.
2️⃣ بناء ZigZag
بعد اكتشاف النقاط المحورية، يُنشئ المؤشر بنية ZigZag بربط نقاط السعر ذات الصلة باستخدام `buildZigZag`. تُمثل هذه الخطوط تحركات الأسعار الأساسية مُشكّلةً أشكالًا توافقية.
3️⃣ حساب نسبة فيبوناتشي
من ZigZag، يستخرج المؤشر النقاط المُسمّاة X، A، B، C، وD، ثم يحسب نسب فيبوناتشي الرئيسية:
* XAB = |B-A| / |X-A|
* ABC = |C-B| / |A-B|
* XAD = |D-A| / |X-A|
4️⃣ خوارزمية مطابقة الأنماط
لكل نمط نطاقات فيبوناتشي مثالية. تُقارن النسب بهذه النطاقات باستخدام هوامش خطأ قابلة للتعديل:
ERROR_MARGIN_MIN = (100 - DETECT_ERROR_MARGIN_PERCENT) / 100
ERROR_MARGIN_MAX = (100 + DETECT_ERROR_MARGIN_PERCENT) / 100
إذا وقعت جميع النسب المطلوبة للنمط ضمن هذه الحدود، يُعتبر النمط مطابقًا محتملًا.
5️⃣ حساب درجة التشابه
لتقييم الدقة، يحصل كل نمط على درجة تشابه بمقارنة النسب الفعلية بالنسب المثالية. على سبيل المثال:
simXAB = min(xabRatio / idealXAB, idealXAB / xabRatio)
simABC = min(abcRatio / idealABC, idealABC / abcRatio)
simXAD = min(xadRatio / idealXAD, idealXAD / xadRatio)
التشابه = (simXAB + simABC + simXAD) / 3
يتم عرض الأنماط التي يكون تشابهها ≥ MIN\_RATING\_PERCENT (الافتراضي 80%) فقط.
6️⃣ المخرجات المرئية
عند اكتشاف نمط، يتم عرضه بتوصيل النقاط X→A→B→C→D. يتم رسم علامة عند النقطة D تُظهر:
* اسم النمط
* رمز تعبيري (مثل 🦋 لنمط جارتلي)
* نسبة التشابه (مثل "92%))
الأنماط مُرمَّزة بالألوان:
🟢 أخضر للارتفاع
🔴 أحمر للانخفاض
⚙️ إعدادات قابلة للتخصيص:
* تمكين كشف النمط: تفعيل أو تعطيل كشف النمط
* إدخال طول النمط: عدد الشموع المُراد حسابها للهيكل
* كشف الخطأ: نسبة الهامش: يتحكم في الانحراف المسموح به عن نسب فيبوناتشي المثالية
* الحد الأدنى لنسبة التشابه لعرض النمط (مثل 80%)
🎨 تخصيص العرض:
* تخصيص خطوط متعرجة (متصلة، منقطة، متقطعة)
* التحكم في السُمك واللون ونمط الخطوط
* ضبط حجم خط التسمية وموضعه ووضوحه
* تفعيل أو تعطيل أنواع أنماط محددة
* تعديل مستويات فيبوناتشي المستخدمة لكل نمط
تتضمن التسميات رموزًا تعبيرية لتسهيل التعرف عليها:
🦋 جارتلي | 🐝 فراشة | 🦈 سمكة قرش | 🐺 موجات وولف | 🦢 بجعة سوداء | ⚡ نمط مضاد لـ غارتلي
📚 تعريفات الأنماط:
غارتلي: XAB ≈ 0.618، ABC ≈ 0.382–0.886، XAD ≈ 0.786
فراشة: XAB ≈ 0.786، XAD ≈ 1.272
خفاش: XAB ≈ 0.382–0.50، XAD ≈ 0.886
سرطان البحر/سرطان البحر العميق: XAD ≈ 1.618–1.902
AB=CD: AB يساوي CD (حركات متماثلة)
سايفر: ABC ≈ 1.13–1.414، XAD ≈ 0.786
شارك: XAD ≈ 1.0–1.13
ثلاثة أرجل: ثلاثة أرجل مع فيبوناتشي امتدادات
موجات وولف: نقاط متوازية هندسيًا، XAD ≈ 1.272–1.618
5-0: تصحيح CD بنسبة 50% من الموجة السابقة
البجعة السوداء: نمط نادر وحاد، XAD ≈ 3.618–4.236
مضاد جارتلي: جارتلي معكوس بنسب مخصصة
📈 الأسواق المستهدفة:
هذا المؤشر فعال لتحليل:
✔ الفوركس
✔ الأسهم
✔ العملات المشفرة
✔ السلع (الذهب، النفط، إلخ)
مناسب لأنماط تداول متعددة:
* المضاربة السريعة
* تداول التأرجح
* تداول المراكز
✨ الميزات الرئيسية:
✅ دعم 13 نمطًا توافقيًا
✅ كشف تلقائي مع تسجيل الدقة
✅ هوامش خطأ قابلة للتعديل
✅ شاشة قابلة للتخصيص بالكامل
✅ مفاتيح تبديل خاصة بالأنماط
✅ مخرجات مرمزة بالألوان للصعود/الهبوط
✅ تسميات توضيحية مع النمط الاسم، والرموز التعبيرية، والتشابه
⚠️ إخلاء مسؤولية:
هذا المؤشر لأغراض تعليمية وتحليلية فقط. لا يُمثل نصيحة مالية أو استثمارية أو تداولية. استخدمه بالتزامن مع استراتيجيتك الخاصة وإدارة المخاطر. لا يتحمل TradingView ولا المطور مسؤولية أي قرارات مالية أو خسائر.
Sürüm Notları
Harmonic Pattern Detector [The_lurker]A sophisticated, fully automated indicator designed to accurately detect and visualize 13 major harmonic patterns using Fibonacci ratios, pivot analysis, and zigzag price structure detection.
This indicator helps traders identify high-probability reversal zones by detecting precise geometric patterns such as the Gartley, Butterfly, Bat, Crab, Deep Crab, AB=CD, Cypher, Shark, Three Drive, Wolfe Waves, 5-0, Black Swan, and Anti-Gartley.
Each pattern is validated using strict Fibonacci convergence rules, similarity scoring, and customizable error margins, ensuring only reliable signals are displayed.
How It Works
1. Pivot Point Detection
The script identifies significant swing highs and lows based on a user-defined reference look-ahead length (pattern length). These pivot points form the basis of all harmonic structures (denoted X, A, B, C, D).
2. ZigZag Construction
The dynamic zigzag line connects confirmed pivot points to represent the primary impulse and corrective waves in price action. This precise structural framework enables accurate identification of zigzag legs.
3. Fibonacci Analysis
For each potential five-point structure (XABCD), the script calculates key Fibonacci retracement and extension ratios:
XAB = |B - A| / |X - A|
ABC = |C - B| / |A - B|
XAD = |D - A| / |X - A|
Additional ratios such as BCD, XAC, A1, A2, etc. are used for complex patterns (such as Three Drives, 5-0, and Shark).
These values are compared to the ideal harmonic ratios defined for each pattern type.
4. Pattern Matching and Validation
Each detected structure is tested against predefined Fibonacci ranges (customizable in the settings). The matching process includes:
Error Tolerance: Allows deviation from the ideal ratios (adjustable via margin of error percentage).
Minimum Similarity Score: Only patterns with a similarity score of ≥ 80% are displayed (default).
The similarity score is calculated as follows:
1.
Similarity = Average (Minimum (Actual/Ideal, Ideal/Actual)) across the relevant ratios.
This ensures that only high-quality, near-ideal patterns trigger visual alerts.
5. Multi-Pattern Support
Supports the detection of 13 distinct harmonic patterns, including rare and advanced patterns such as:
Black Swan (extreme extensions)
Shark and 5-0 (modern harmonic patterns)
Three Drivers and Wolf Waves (symmetric wave structures)
Anti-Gartley (inverse Gartley setup)
All patterns can be individually enabled/disabled for selective filtering.
🎨 Visual Outputs and Features
Color-coded Patterns: Each pattern has a unique color (customizable).
Directional Markers at Point D:
Green markers indicate bullish reversals
Red markers indicate bearish reversals
Emojis for Quick Recognition:
🦋 Gartley | 🐝 Butterfly | 🦇 Bat | 🦀 Crab | 🦈 Shark | 🌊 Wolf Waves | 🦢 Black Swan | ⚔️ Anti-Gartley
Label includes:
Pattern name
Emoji
Accuracy percentage (e.g., "92%)
Customizable display:
Line width and style (solid, dashed, dotted)
Label size and text color
Rising/Downing label colors
⚙️ Key settings
General
✅ Pattern detection activation: On/Off
🔢 Pattern length: Number of bars used to detect pivot points (default: 18)
📏 Margin of error (%): Acceptable deviation from ideal Fibonacci levels (recommended: 10-20%)
⭐ Minimum rating (%): Minimum similarity score for display (minimum 80%, default: 80%)
Controls per pattern
Individual toggles and color settings for all 13 patterns
Adjustable Fibonacci thresholds (e.g., XAB, ABC, XAD) for fine-tuning sensitivity
Display options
Customizable line width and style
Label font size and color
Coloring Trend-Based Naming (Up/Down)
💡 Trading Apps
Ideal for identifying potential reversal zones (PRZs) across multiple timeframes and markets:
Markets: Forex, Stocks, Cryptocurrencies, Commodities
Timeframes: From 1-minute scalping to daily swing trading
Strategies:
Reversal entry after pattern completion at Point D
Confluence with support/resistance, RSI divergence, or volume spikes
Place a stop-loss order after Point D; take profit on measured moves
Works well with manual confirmation or integration into systematic strategies.
🛠️ Technical Notes
Integrated with Pine Script version 6
Uses efficient array management to store and verify pivot trading history
Includes anti-duplication logic to avoid duplicate signals
Supports instant alerts when a valid pattern forms
📢 Example alert message:
Harmonic alert {{ticker}} - Triggers when any qualifying pattern completes.
✅ What's unique about this script:
Unlike A basic harmonic detector, this script combines:
Comprehensive support for multiple patterns
Accurate mathematical validation via similarity scoring
Highly customizable without compromising ease of use
Clear and informative classification for quick decision-making
Designed for both novice traders learning harmonic trading and experienced users seeking accuracy and reliability.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.