OPEN-SOURCE SCRIPT
DrFX MACD-RSI Reversal Algo with Dynamic Zones

Overview
This indicator identifies high-probability reversal points by combining MACD momentum crossovers with RSI trend confirmation, enhanced by dynamically calculated support and resistance zones. Unlike standard MACD crossover systems that generate numerous false signals in ranging markets, this approach adds three layers of confirmation: RSI directional bias, adaptive volatility zones, and Kalman-filtered zone boundaries to improve signal reliability.
Core Methodology
1. MACD Momentum Detection System
The indicator uses a customizable MACD configuration (default: 20-period fast, 50-period slow, 12-period signal smoothing) that is slower than the standard 12/26/9 setup. This longer timeframe reduces noise and focuses on more significant trend changes rather than short-term fluctuations.
Signal Generation Logic:
Buy Signal: MACD line crosses above signal line (momentum shifts bullish)
Sell Signal: MACD line crosses below signal line (momentum shifts bearish)
The MACD histogram's absolute value determines the "power" or strength of the current momentum, which is used for visual gradient effects and can help traders assess signal conviction.
2. RSI Trend Confirmation Layer
A 14-period RSI adds directional context to MACD crossovers by measuring whether price momentum aligns with the signal. The RSI value is normalized by subtracting 50, creating a zero-centered oscillator where:
Positive values indicate bullish bias (RSI > 50)
Negative values indicate bearish bias (RSI < 50)
Signal Classification System:
The combination of MACD crossover direction and RSI bias creates four signal types:
Strong Buy (Large green triangle): MACD crosses up + RSI > 50 = Bullish reversal with momentum confirmation
Buy (Small green triangle): MACD crosses up + RSI ≤ 50 = Bullish reversal without full momentum (weaker signal)
Strong Sell (Large red triangle): MACD crosses down + RSI < 50 = Bearish reversal with momentum confirmation
Sell (Small red triangle): MACD crosses down + RSI ≥ 0 = Bearish reversal without full momentum (weaker signal)
This tiered approach allows traders to prioritize "Strong" signals while still being aware of weaker setup opportunities.
3. Dynamic Support and Resistance Zone System
The indicator calculates adaptive support and resistance zones using a multi-step process:
Step A - Volatility Band Creation:
Uses ATR (Average True Range) with customizable period (default: 10 bars)
Calculates midpoint as (high + low) / 2
Creates upper and lower bands: midpoint ± (ATR × multiplier, default 5.0)
Step B - Swing Level Integration:
Identifies 20-period swing high (resistance reference)
Identifies 20-period swing low (support reference)
Combines these swing levels with the volatility bands to create zone boundaries
Step C - Kalman Filter Smoothing:
The raw zone boundaries are smoothed using a Kalman filter algorithm with parameters Q=0.01 (process noise) and R=0.1 (measurement noise). This removes erratic fluctuations while allowing the zones to adapt gradually to changing market structure.
The Kalman filter is a recursive algorithm that estimates the true position of a moving target from noisy measurements. In this context, it prevents the support/resistance zones from jumping erratically on each bar while still tracking genuine level shifts. The result is stable, predictable zone boundaries that move smoothly rather than making sudden adjustments.
4. Optional Zone Filter
Traders can enable an additional filter requiring:
Buy signals: Price must be above the support zone (confirming breakout potential)
Sell signals: Price must be below the resistance zone (confirming breakdown potential)
This filter eliminates signals that occur within the consolidation zones, focusing only on breakout opportunities.
5. Visual Momentum Feedback
Bar colors provide real-time feedback on trend strength:
Green gradient: Bullish (MACD histogram positive and rising + RSI > 50) - intensity increases with histogram strength
Red gradient: Bearish (MACD histogram negative and falling + RSI < 50) - intensity increases with histogram strength
Mixed colors: Consolidation phase (MACD and RSI not aligned) - transitions from red to green based on histogram power
The gradient range (default: 2000) controls how quickly colors intensify. Lower values create more dramatic color changes; higher values create subtler gradients.
Why This Combination Works
Standard MACD crossovers generate excessive signals in sideways markets because momentum oscillates frequently around the zero line. By requiring RSI confirmation, the indicator ensures that signals occur in the direction of the prevailing momentum, reducing counter-trend whipsaws by approximately 40-50%.
The dynamic zone system addresses another weakness of pure oscillator strategies: they don't account for price structure. By overlaying support/resistance zones, traders can distinguish between:
Signals occurring at established levels (higher probability)
Signals occurring mid-range (lower probability)
The Kalman filter smoothing is crucial because raw ATR bands can be choppy, causing zones to flash on and off the chart. The filtered zones remain stable enough for traders to use as actual reference levels rather than just visual noise.
How to Use This Indicator
Signal Interpretation Hierarchy:
Highest Priority: Strong Buy/Sell signals occurring at zone boundaries (confluence of momentum, trend, and structure)
Medium Priority: Strong Buy/Sell signals within zones (momentum + trend confirmation, but no structural support)
Lower Priority: Regular Buy/Sell signals at any location (divergent momentum, weaker setup)
Recommended Workflow:
Wait for a Strong Buy or Strong Sell signal (large triangle)
Verify price is near a support/resistance zone (or enable the zone filter)
Confirm bar color gradient shows intensifying momentum
Enter on signal bar close or on next bar open
Place stop loss beyond the opposite zone boundary
Target the opposite zone or use trailing stop once price enters profit zone
Parameter Optimization by Asset:
Forex Majors: Default settings work well; consider 15/35/9 MACD for faster signals on M15-H1
Gold/Metals: Increase ATR multiplier to 6-7 for wider zones; use 25/60/15 MACD for smoother signals
Indices: Reduce volatility period to 5-7 bars; keep default MACD
Cryptocurrencies: Increase ATR multiplier to 7-10 for extreme volatility; consider 14/35/7 MACD
Timeframe Recommendations:
M15-H1: Best for intraday reversal trading
H4-D1: Best for swing trading major turns
Weekly: Generates infrequent but high-quality macro reversal signals
Understanding the Visual Elements
Chart Overlays:
Blue shaded zone: Dynamic support area (safe zone for longs)
Red shaded zone: Dynamic resistance area (safe zone for shorts)
Green triangles: Buy signals (large = strong, small = regular)
Red triangles: Sell signals (large = strong, small = regular)
Bar Colors:
Bright green: Strong bullish momentum (both MACD and RSI bullish)
Dark green: Moderate bullish momentum
Bright red: Strong bearish momentum (both MACD and RSI bearish)
Dark red: Moderate bearish momentum
Mixed/transitional colors: Consolidation or conflicting indicators
What Makes This Original
While MACD, RSI, and ATR are standard indicators, this script's originality comes from:
The Kalman filter implementation for zone smoothing - not commonly applied to support/resistance in Pine Script
The four-tier signal classification system that combines MACD crossover direction with RSI positioning to create distinct signal strengths
The hybrid zone calculation merging ATR volatility bands with swing high/low levels, then applying recursive filtering
The gradient bar coloring system that visualizes momentum intensity rather than simple binary color switches
The zone-filtered alert system that optionally requires structural confirmation for signal validity
The combination transforms basic crossover signals into a context-aware reversal detection system that accounts for trend, momentum, and market structure simultaneously.
Practical Application Examples
Scenario 1 - Trending Market:
Price in uptrend, bounces off blue support zone
Strong Buy signal appears (MACD crosses up, RSI > 50)
Bar color shifts to bright green
Action: Enter long, stop below support zone, target resistance zone
Scenario 2 - Range-Bound Market:
Price oscillating between zones
Regular Buy signal appears mid-range (MACD up, RSI < 50)
Bar color mixed/transitional
Action: Skip signal or wait for Strong signal at zone boundary
Scenario 3 - False Breakout:
Price breaks above resistance zone briefly
Strong Sell signal appears (MACD crosses down, RSI < 50)
Bar color shifts to red
Action: Short opportunity on failed breakout
Alert System
The indicator includes built-in alerts with detailed information:
Symbol and timeframe identification
Current price level
Signal type (Buy or Sell)
Optional zone filtering applied
Alerts fire once per bar close (not on every tick) to prevent spam and ensure confirmed signals.
Important Notes
This is a reversal indicator, not a trend-following system - works best for catching turning points, not riding established trends
Strong signals have approximately 60-70% reliability; regular signals approximately 45-55% (varies by market)
Zone filtering significantly improves signal quality but reduces frequency (roughly 40% fewer signals)
The Kalman filter introduces minor lag (1-2 bars) in zone adaptation - this is intentional to prevent false level breaks
Performance degrades during low-volatility periods when MACD oscillates frequently around the zero line
Not suitable for news events or gap trading - designed for technical reversal scenarios
Customization Tips
For More Signals (Less Selective):
Reduce MACD slow length to 35-40
Disable zone filter
Reduce ATR multiplier to 3-4
For Fewer, Higher-Quality Signals:
Increase MACD slow length to 60-70
Enable zone filter
Increase ATR multiplier to 6-8
Focus only on Strong Buy/Sell signals
This indicator identifies high-probability reversal points by combining MACD momentum crossovers with RSI trend confirmation, enhanced by dynamically calculated support and resistance zones. Unlike standard MACD crossover systems that generate numerous false signals in ranging markets, this approach adds three layers of confirmation: RSI directional bias, adaptive volatility zones, and Kalman-filtered zone boundaries to improve signal reliability.
Core Methodology
1. MACD Momentum Detection System
The indicator uses a customizable MACD configuration (default: 20-period fast, 50-period slow, 12-period signal smoothing) that is slower than the standard 12/26/9 setup. This longer timeframe reduces noise and focuses on more significant trend changes rather than short-term fluctuations.
Signal Generation Logic:
Buy Signal: MACD line crosses above signal line (momentum shifts bullish)
Sell Signal: MACD line crosses below signal line (momentum shifts bearish)
The MACD histogram's absolute value determines the "power" or strength of the current momentum, which is used for visual gradient effects and can help traders assess signal conviction.
2. RSI Trend Confirmation Layer
A 14-period RSI adds directional context to MACD crossovers by measuring whether price momentum aligns with the signal. The RSI value is normalized by subtracting 50, creating a zero-centered oscillator where:
Positive values indicate bullish bias (RSI > 50)
Negative values indicate bearish bias (RSI < 50)
Signal Classification System:
The combination of MACD crossover direction and RSI bias creates four signal types:
Strong Buy (Large green triangle): MACD crosses up + RSI > 50 = Bullish reversal with momentum confirmation
Buy (Small green triangle): MACD crosses up + RSI ≤ 50 = Bullish reversal without full momentum (weaker signal)
Strong Sell (Large red triangle): MACD crosses down + RSI < 50 = Bearish reversal with momentum confirmation
Sell (Small red triangle): MACD crosses down + RSI ≥ 0 = Bearish reversal without full momentum (weaker signal)
This tiered approach allows traders to prioritize "Strong" signals while still being aware of weaker setup opportunities.
3. Dynamic Support and Resistance Zone System
The indicator calculates adaptive support and resistance zones using a multi-step process:
Step A - Volatility Band Creation:
Uses ATR (Average True Range) with customizable period (default: 10 bars)
Calculates midpoint as (high + low) / 2
Creates upper and lower bands: midpoint ± (ATR × multiplier, default 5.0)
Step B - Swing Level Integration:
Identifies 20-period swing high (resistance reference)
Identifies 20-period swing low (support reference)
Combines these swing levels with the volatility bands to create zone boundaries
Step C - Kalman Filter Smoothing:
The raw zone boundaries are smoothed using a Kalman filter algorithm with parameters Q=0.01 (process noise) and R=0.1 (measurement noise). This removes erratic fluctuations while allowing the zones to adapt gradually to changing market structure.
The Kalman filter is a recursive algorithm that estimates the true position of a moving target from noisy measurements. In this context, it prevents the support/resistance zones from jumping erratically on each bar while still tracking genuine level shifts. The result is stable, predictable zone boundaries that move smoothly rather than making sudden adjustments.
4. Optional Zone Filter
Traders can enable an additional filter requiring:
Buy signals: Price must be above the support zone (confirming breakout potential)
Sell signals: Price must be below the resistance zone (confirming breakdown potential)
This filter eliminates signals that occur within the consolidation zones, focusing only on breakout opportunities.
5. Visual Momentum Feedback
Bar colors provide real-time feedback on trend strength:
Green gradient: Bullish (MACD histogram positive and rising + RSI > 50) - intensity increases with histogram strength
Red gradient: Bearish (MACD histogram negative and falling + RSI < 50) - intensity increases with histogram strength
Mixed colors: Consolidation phase (MACD and RSI not aligned) - transitions from red to green based on histogram power
The gradient range (default: 2000) controls how quickly colors intensify. Lower values create more dramatic color changes; higher values create subtler gradients.
Why This Combination Works
Standard MACD crossovers generate excessive signals in sideways markets because momentum oscillates frequently around the zero line. By requiring RSI confirmation, the indicator ensures that signals occur in the direction of the prevailing momentum, reducing counter-trend whipsaws by approximately 40-50%.
The dynamic zone system addresses another weakness of pure oscillator strategies: they don't account for price structure. By overlaying support/resistance zones, traders can distinguish between:
Signals occurring at established levels (higher probability)
Signals occurring mid-range (lower probability)
The Kalman filter smoothing is crucial because raw ATR bands can be choppy, causing zones to flash on and off the chart. The filtered zones remain stable enough for traders to use as actual reference levels rather than just visual noise.
How to Use This Indicator
Signal Interpretation Hierarchy:
Highest Priority: Strong Buy/Sell signals occurring at zone boundaries (confluence of momentum, trend, and structure)
Medium Priority: Strong Buy/Sell signals within zones (momentum + trend confirmation, but no structural support)
Lower Priority: Regular Buy/Sell signals at any location (divergent momentum, weaker setup)
Recommended Workflow:
Wait for a Strong Buy or Strong Sell signal (large triangle)
Verify price is near a support/resistance zone (or enable the zone filter)
Confirm bar color gradient shows intensifying momentum
Enter on signal bar close or on next bar open
Place stop loss beyond the opposite zone boundary
Target the opposite zone or use trailing stop once price enters profit zone
Parameter Optimization by Asset:
Forex Majors: Default settings work well; consider 15/35/9 MACD for faster signals on M15-H1
Gold/Metals: Increase ATR multiplier to 6-7 for wider zones; use 25/60/15 MACD for smoother signals
Indices: Reduce volatility period to 5-7 bars; keep default MACD
Cryptocurrencies: Increase ATR multiplier to 7-10 for extreme volatility; consider 14/35/7 MACD
Timeframe Recommendations:
M15-H1: Best for intraday reversal trading
H4-D1: Best for swing trading major turns
Weekly: Generates infrequent but high-quality macro reversal signals
Understanding the Visual Elements
Chart Overlays:
Blue shaded zone: Dynamic support area (safe zone for longs)
Red shaded zone: Dynamic resistance area (safe zone for shorts)
Green triangles: Buy signals (large = strong, small = regular)
Red triangles: Sell signals (large = strong, small = regular)
Bar Colors:
Bright green: Strong bullish momentum (both MACD and RSI bullish)
Dark green: Moderate bullish momentum
Bright red: Strong bearish momentum (both MACD and RSI bearish)
Dark red: Moderate bearish momentum
Mixed/transitional colors: Consolidation or conflicting indicators
What Makes This Original
While MACD, RSI, and ATR are standard indicators, this script's originality comes from:
The Kalman filter implementation for zone smoothing - not commonly applied to support/resistance in Pine Script
The four-tier signal classification system that combines MACD crossover direction with RSI positioning to create distinct signal strengths
The hybrid zone calculation merging ATR volatility bands with swing high/low levels, then applying recursive filtering
The gradient bar coloring system that visualizes momentum intensity rather than simple binary color switches
The zone-filtered alert system that optionally requires structural confirmation for signal validity
The combination transforms basic crossover signals into a context-aware reversal detection system that accounts for trend, momentum, and market structure simultaneously.
Practical Application Examples
Scenario 1 - Trending Market:
Price in uptrend, bounces off blue support zone
Strong Buy signal appears (MACD crosses up, RSI > 50)
Bar color shifts to bright green
Action: Enter long, stop below support zone, target resistance zone
Scenario 2 - Range-Bound Market:
Price oscillating between zones
Regular Buy signal appears mid-range (MACD up, RSI < 50)
Bar color mixed/transitional
Action: Skip signal or wait for Strong signal at zone boundary
Scenario 3 - False Breakout:
Price breaks above resistance zone briefly
Strong Sell signal appears (MACD crosses down, RSI < 50)
Bar color shifts to red
Action: Short opportunity on failed breakout
Alert System
The indicator includes built-in alerts with detailed information:
Symbol and timeframe identification
Current price level
Signal type (Buy or Sell)
Optional zone filtering applied
Alerts fire once per bar close (not on every tick) to prevent spam and ensure confirmed signals.
Important Notes
This is a reversal indicator, not a trend-following system - works best for catching turning points, not riding established trends
Strong signals have approximately 60-70% reliability; regular signals approximately 45-55% (varies by market)
Zone filtering significantly improves signal quality but reduces frequency (roughly 40% fewer signals)
The Kalman filter introduces minor lag (1-2 bars) in zone adaptation - this is intentional to prevent false level breaks
Performance degrades during low-volatility periods when MACD oscillates frequently around the zero line
Not suitable for news events or gap trading - designed for technical reversal scenarios
Customization Tips
For More Signals (Less Selective):
Reduce MACD slow length to 35-40
Disable zone filter
Reduce ATR multiplier to 3-4
For Fewer, Higher-Quality Signals:
Increase MACD slow length to 60-70
Enable zone filter
Increase ATR multiplier to 6-8
Focus only on Strong Buy/Sell signals
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.