OPEN-SOURCE SCRIPT
Harmonic Ratio Scanner [forexobroker]

Harmonic Ratio Scanner detects simple harmonic ratios between consecutive price swings. Instead of waiting for rare full XABCD patterns, this indicator finds individual Fibonacci retracement ratios that occur frequently and provide actionable trade setups.
🔶 WHAT MAKES THIS UNIQUE
Traditional harmonic scanners require complete 5-point patterns (Gartley, Butterfly, Bat, Crab). These are complex, rare, and often subjective. The Harmonic Ratio Scanner takes a fundamentally different approach: it measures the ratio between any two consecutive swings.
If swing B retraces 61.8% of swing A, that single ratio represents natural market rhythm at a Fibonacci level. These individual ratios occur far more frequently than full patterns, giving traders more opportunities while still capturing the core principle of harmonic trading.
🔶 HOW IT WORKS
1. The indicator detects swing highs and lows using pivot logic
2. It stores the most recent swings in memory
3. For each pair of consecutive swings, it calculates the retracement ratio
4. If the ratio matches a known harmonic value (within configurable tolerance), a harmonic ratio is detected
5. The swing direction determines if the ratio is bullish or bearish
🔶 DETECTABLE RATIOS
- 38.2% - Shallow retracement (continuation likely)
- 50.0% - Half retracement (optional, disabled by default)
- 61.8% - Golden ratio (highest probability)
- 78.6% - Deep retracement (strong reversal zone)
Each ratio can be individually enabled or disabled.
🔶 SIGNAL LOGIC
BUY signals fire when:
- A bullish harmonic ratio is detected (swing low forming after swing high)
- Volume confirms the setup (above 20-period SMA)
- Bar is confirmed (no repainting)
SELL signals fire under inverse conditions.
A 15-bar cooldown prevents signal clustering.
🔶 VISUAL GUIDE
- Colored lines connect the detected harmonic swings
- Ratio percentage labels appear at swing midpoints
- Green lines and arrows for bullish ratios
- Pink lines and arrows for bearish ratios
- Info table displays the last detected ratio, direction, and active filters
🔶 RECOMMENDED SETTINGS
- Swing trading (1H-4H): Default settings work well
- Scalping (5m-15m): Reduce swing lookback to 3, increase tolerance to 5%
- Position trading (Daily): Increase swing lookback to 8-10
- For more signals: Enable the 50% ratio
- For higher quality: Disable 38.2%, keep only 61.8% and 78.6%
🔶 ALERTS
9 alert conditions available including buy/sell signals, ratio detection, bullish/bearish ratio alerts, and volume surge notifications. JSON-formatted alerts supported for webhook integration.
🔶 LIMITATIONS
- Swing detection requires lookback bars to confirm. There is an inherent delay equal to the swing lookback setting.
- Not all harmonic ratios lead to reversals. The ratio identifies a zone of interest, not a guaranteed outcome.
- On very low timeframes, swing noise may produce false ratios. Increase the minimum swing size filter.
- This indicator does not repaint. Swings are confirmed only after the lookback period completes.
- Past performance does not guarantee future results. Always use proper risk management.
🔶 WHAT MAKES THIS UNIQUE
Traditional harmonic scanners require complete 5-point patterns (Gartley, Butterfly, Bat, Crab). These are complex, rare, and often subjective. The Harmonic Ratio Scanner takes a fundamentally different approach: it measures the ratio between any two consecutive swings.
If swing B retraces 61.8% of swing A, that single ratio represents natural market rhythm at a Fibonacci level. These individual ratios occur far more frequently than full patterns, giving traders more opportunities while still capturing the core principle of harmonic trading.
🔶 HOW IT WORKS
1. The indicator detects swing highs and lows using pivot logic
2. It stores the most recent swings in memory
3. For each pair of consecutive swings, it calculates the retracement ratio
4. If the ratio matches a known harmonic value (within configurable tolerance), a harmonic ratio is detected
5. The swing direction determines if the ratio is bullish or bearish
🔶 DETECTABLE RATIOS
- 38.2% - Shallow retracement (continuation likely)
- 50.0% - Half retracement (optional, disabled by default)
- 61.8% - Golden ratio (highest probability)
- 78.6% - Deep retracement (strong reversal zone)
Each ratio can be individually enabled or disabled.
🔶 SIGNAL LOGIC
BUY signals fire when:
- A bullish harmonic ratio is detected (swing low forming after swing high)
- Volume confirms the setup (above 20-period SMA)
- Bar is confirmed (no repainting)
SELL signals fire under inverse conditions.
A 15-bar cooldown prevents signal clustering.
🔶 VISUAL GUIDE
- Colored lines connect the detected harmonic swings
- Ratio percentage labels appear at swing midpoints
- Green lines and arrows for bullish ratios
- Pink lines and arrows for bearish ratios
- Info table displays the last detected ratio, direction, and active filters
🔶 RECOMMENDED SETTINGS
- Swing trading (1H-4H): Default settings work well
- Scalping (5m-15m): Reduce swing lookback to 3, increase tolerance to 5%
- Position trading (Daily): Increase swing lookback to 8-10
- For more signals: Enable the 50% ratio
- For higher quality: Disable 38.2%, keep only 61.8% and 78.6%
🔶 ALERTS
9 alert conditions available including buy/sell signals, ratio detection, bullish/bearish ratio alerts, and volume surge notifications. JSON-formatted alerts supported for webhook integration.
🔶 LIMITATIONS
- Swing detection requires lookback bars to confirm. There is an inherent delay equal to the swing lookback setting.
- Not all harmonic ratios lead to reversals. The ratio identifies a zone of interest, not a guaranteed outcome.
- On very low timeframes, swing noise may produce false ratios. Increase the minimum swing size filter.
- This indicator does not repaint. Swings are confirmed only after the lookback period completes.
- Past performance does not guarantee future results. Always use proper risk management.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.