OPEN-SOURCE SCRIPT
RSI Signals Multi-Layer RSI System with Classical Divergence

**DrFX RSI Signals Fixed** is an advanced RSI-based trading system that combines duration-filtered extreme conditions with classical divergence detection and momentum confirmation. This enhanced version addresses common RSI false signals through multi-layer filtering while adding proper divergence analysis for identifying high-probability reversal points.
**Core Innovation & Originality**
This indicator uniquely integrates five analytical layers:
1. **Duration-Validated Extreme Zones** - Confirms RSI has remained overbought/oversold for minimum bars within lookback period
2. **Classical Divergence Detection** - Proper implementation comparing swing highs/lows in both price and RSI
3. **Momentum Confirmation Signals** - RSI crossing 50-line after extreme conditions for trend confirmation
4. **Multi-Signal Classification** - Four distinct signal types (Buy, Sell, Strong Buy, Strong Sell, Momentum)
5. **Visual Zone Highlighting** - Background coloring for instant extreme zone identification
**Technical Implementation & Improvements**
**Enhanced Duration Filter:**
Unlike the previous version, this system uses a refined approach:
```
for i = 0 to lookback_bars - 1
if rsi > overbought
barsInOverbought := barsInOverbought + 1
```
This counts actual bars within the lookback period (default 20 bars) where RSI was extreme, requiring minimum duration (default 4 bars) for signal validation.
**Classical Divergence Detection:**
The system implements proper divergence analysis, a significant improvement over simple delta comparison:
**Bullish Divergence Logic:**
- Price makes lower low: `low < prevPriceLow`
- RSI makes higher low: `rsi > prevRsiLow`
- Indicates weakening downward momentum despite lower prices
**Bearish Divergence Logic:**
- Price makes higher high: `high > prevPriceHigh`
- RSI makes lower high: `rsi < prevRsiHigh`
- Indicates weakening upward momentum despite higher prices
**Signal Generation Framework:**
**Primary Signals:**
- **Buy Signal**: RSI crosses above oversold (30) after meeting duration requirements
- **Sell Signal**: RSI crosses below overbought (70) after meeting duration requirements
**Strong Signals:**
- **Strong Buy**: Buy signal + bullish divergence confirmation
- **Strong Sell**: Sell signal + bearish divergence confirmation
**Momentum Signals:**
- **Momentum Buy (M+)**: RSI crosses above 50 after recent oversold conditions
- **Momentum Sell (M-)**: RSI crosses below 50 after recent overbought conditions
**What Makes This Version Superior**
**Compared to Standard RSI:**
1. **Duration Requirement**: Prevents signals on brief RSI spikes
2. **Lookback Validation**: Ensures extreme conditions actually occurred recently
3. **Proper Divergence**: Uses swing high/low comparison, not just bar-to-bar deltas
4. **Momentum Layer**: Adds trend confirmation via 50-line crosses
**Compared to Previous Version:**
1. **Pine Script v5**: Modern syntax with improved performance
2. **Configurable Parameters**: All values adjustable via inputs
3. **Better Divergence**: Classical divergence logic replaces simplified delta method
4. **Additional Signals**: Momentum confirmations for trend following
5. **Visual Enhancements**: Background coloring and improved signal differentiation
6. **Alert System**: Built-in alert conditions for all signal types
**Parameter Configuration**
**Customizable Inputs:**
- **Overbought Level** (70): Upper threshold, range 50-90
- **Oversold Level** (30): Lower threshold, range 10-50
- **RSI Period** (14): Calculation period, range 2-50
- **Minimum Duration** (4): Required bars in extreme zone, range 1-20
- **Lookback Bars** (20): Period to check for extreme conditions, range 5-100
- **Divergence Lookback** (5): Period for divergence swing comparison, range 2-20
**Optimization Guidelines:**
- **Shorter Duration** (2-3): More frequent signals, higher noise
- **Longer Duration** (5-7): Fewer signals, better quality
- **Smaller Lookback** (10-15): Faster response, may miss context
- **Larger Lookback** (30-50): More context, potentially delayed signals
**Signal Interpretation Guide**
**Visual Signal Hierarchy:**
**Light Green Triangle (Buy):**
- RSI recovered from oversold
- Duration requirements met
- Entry on reversal from oversold territory
**Light Red Triangle (Sell):**
- RSI declined from overbought
- Duration requirements met
- Entry on reversal from overbought territory
**Blue Triangle (Strong Buy):**
- Buy signal with bullish divergence
- Highest probability long setup
- Price made lower low, RSI made higher low
**Magenta Triangle (Strong Sell):**
- Sell signal with bearish divergence
- Highest probability short setup
- Price made higher high, RSI made lower high
**Tiny Green Circle (M+):**
- RSI crossed above 50 after oversold
- Momentum confirmation for uptrend
- Secondary entry or trend confirmation
**Tiny Red Circle (M-):**
- RSI crossed below 50 after overbought
- Momentum confirmation for downtrend
- Secondary entry or trend confirmation
**Background Coloring:**
- **Light Red Background**: RSI > 70 (overbought zone)
- **Light Green Background**: RSI < 30 (oversold zone)
**Trading Strategy Application**
**Conservative Approach (Strong Signals Only):**
1. Wait for blue/magenta triangles (divergence confirmed)
2. Enter on signal bar close or next bar open
3. Stop loss beyond recent swing high/low
4. Target minimum 2:1 risk/reward ratio
**Aggressive Approach (All Signals):**
1. Take light green/red triangles for earlier entries
2. Use momentum circles as confirmation
3. Tighter stops with partial profit taking
4. Scale positions based on signal strength
**Momentum Trading:**
1. Use momentum signals (M+/M-) as trend filters
2. Take primary signals aligned with momentum direction
3. Avoid counter-momentum signals in strong trends
4. Exit when opposing momentum signal appears
**Multi-Timeframe Strategy:**
1. Check higher timeframe for strong signals
2. Execute on lower timeframe primary signals
3. Use momentum signals for position management
4. Align all timeframe signals for best probability
**Optimal Market Conditions**
**Best Performance:**
- Mean-reverting markets with clear RSI extremes
- Range-bound or consolidating conditions
- Markets respecting support/resistance levels
- Timeframes: 15min to 4H for active trading
**Strong Signal Advantages:**
- Divergence signals often mark major turning points
- Work well at market structure levels
- Effective in both trending and ranging markets
- Higher success rate justifies waiting for setup
**Momentum Signal Benefits:**
- Confirms trend direction after extreme readings
- Useful for adding to positions
- Helps avoid counter-trend trades
- Works well in trending markets where reversals fail
**Technical Advantages**
**Divergence Accuracy:**
The improved divergence detection uses proper swing analysis rather than simple bar-to-bar comparison. This identifies genuine momentum shifts where price action diverges from oscillator movement over a meaningful period.
**Duration Logic:**
The for-loop counting method ensures the system checks actual RSI values within the lookback period, not just whether RSI touched levels. This distinguishes between sustained conditions and brief spikes.
**Momentum Filter:**
The 50-line crosses after extreme conditions provide an additional confirmation layer, helping traders distinguish between failed reversals (no momentum follow-through) and sustained moves (momentum confirmation).
**Risk Management Integration**
**Signal Priority:**
1. **Highest**: Strong signals with divergence (blue/magenta triangles)
2. **Medium**: Primary signals without divergence (light green/red triangles)
3. **Confirmation**: Momentum signals (tiny circles)
**Position Sizing:**
- Larger positions on strong signals (divergence present)
- Standard positions on primary signals
- Smaller positions or adds on momentum signals
**Stop Placement:**
- Beyond recent swing structure
- Below/above divergence swing low/high for strong signals
- Trail stops when momentum signals align with position
**Alert System**
Built-in alert conditions for:
- Buy Signal: RSI buy without divergence
- Sell Signal: RSI sell without divergence
- Strong Buy Alert: Buy with bullish divergence
- Strong Sell Alert: Sell with bearish divergence
Configure alerts via TradingView's alert system to receive notifications for chosen signal types.
**Important Considerations**
**Strengths:**
- Multiple confirmation layers reduce false signals
- Classical divergence improves reversal detection
- Momentum signals add trend-following capability
- Highly customizable for different trading styles
- No repainting - all signals fixed at bar close
**Limitations:**
- Duration requirements may cause missed quick reversals
- Divergence lookback period affects sensitivity
- Not suitable as standalone system
- Requires understanding of RSI principles and divergence concepts
**Best Practices:**
- Combine with price action and support/resistance
- Use higher timeframe context for directional bias
- Respect overall market trend and structure
- Implement proper position sizing based on signal type
- Test parameters on your specific instrument and timeframe
**Comparison Summary**
This enhanced version represents a significant upgrade:
- Upgraded to Pine Script v5 modern standards
- Proper classical divergence detection (not simplified)
- Added momentum confirmation signals
- Fully customizable parameters via inputs
- Visual background zone highlighting
- Comprehensive alert system
- Better signal differentiation through color coding
The system transforms basic RSI analysis into a multi-dimensional trading tool suitable for various market conditions and trading styles.
**Disclaimer**: This indicator is designed for educational and analytical purposes. While the multi-layer filtering and classical divergence detection improve upon standard RSI implementations, no indicator guarantees profitable trades. The duration filtering reduces false signals but may delay entries. Divergence signals, while statistically favorable, can fail in strong trending conditions. Always use proper risk management, position sizing, and stop-loss orders. Consider multiple confirmation methods and market context before making trading decisions. Past performance does not guarantee future results.
**Core Innovation & Originality**
This indicator uniquely integrates five analytical layers:
1. **Duration-Validated Extreme Zones** - Confirms RSI has remained overbought/oversold for minimum bars within lookback period
2. **Classical Divergence Detection** - Proper implementation comparing swing highs/lows in both price and RSI
3. **Momentum Confirmation Signals** - RSI crossing 50-line after extreme conditions for trend confirmation
4. **Multi-Signal Classification** - Four distinct signal types (Buy, Sell, Strong Buy, Strong Sell, Momentum)
5. **Visual Zone Highlighting** - Background coloring for instant extreme zone identification
**Technical Implementation & Improvements**
**Enhanced Duration Filter:**
Unlike the previous version, this system uses a refined approach:
```
for i = 0 to lookback_bars - 1
if rsi > overbought
barsInOverbought := barsInOverbought + 1
```
This counts actual bars within the lookback period (default 20 bars) where RSI was extreme, requiring minimum duration (default 4 bars) for signal validation.
**Classical Divergence Detection:**
The system implements proper divergence analysis, a significant improvement over simple delta comparison:
**Bullish Divergence Logic:**
- Price makes lower low: `low < prevPriceLow`
- RSI makes higher low: `rsi > prevRsiLow`
- Indicates weakening downward momentum despite lower prices
**Bearish Divergence Logic:**
- Price makes higher high: `high > prevPriceHigh`
- RSI makes lower high: `rsi < prevRsiHigh`
- Indicates weakening upward momentum despite higher prices
**Signal Generation Framework:**
**Primary Signals:**
- **Buy Signal**: RSI crosses above oversold (30) after meeting duration requirements
- **Sell Signal**: RSI crosses below overbought (70) after meeting duration requirements
**Strong Signals:**
- **Strong Buy**: Buy signal + bullish divergence confirmation
- **Strong Sell**: Sell signal + bearish divergence confirmation
**Momentum Signals:**
- **Momentum Buy (M+)**: RSI crosses above 50 after recent oversold conditions
- **Momentum Sell (M-)**: RSI crosses below 50 after recent overbought conditions
**What Makes This Version Superior**
**Compared to Standard RSI:**
1. **Duration Requirement**: Prevents signals on brief RSI spikes
2. **Lookback Validation**: Ensures extreme conditions actually occurred recently
3. **Proper Divergence**: Uses swing high/low comparison, not just bar-to-bar deltas
4. **Momentum Layer**: Adds trend confirmation via 50-line crosses
**Compared to Previous Version:**
1. **Pine Script v5**: Modern syntax with improved performance
2. **Configurable Parameters**: All values adjustable via inputs
3. **Better Divergence**: Classical divergence logic replaces simplified delta method
4. **Additional Signals**: Momentum confirmations for trend following
5. **Visual Enhancements**: Background coloring and improved signal differentiation
6. **Alert System**: Built-in alert conditions for all signal types
**Parameter Configuration**
**Customizable Inputs:**
- **Overbought Level** (70): Upper threshold, range 50-90
- **Oversold Level** (30): Lower threshold, range 10-50
- **RSI Period** (14): Calculation period, range 2-50
- **Minimum Duration** (4): Required bars in extreme zone, range 1-20
- **Lookback Bars** (20): Period to check for extreme conditions, range 5-100
- **Divergence Lookback** (5): Period for divergence swing comparison, range 2-20
**Optimization Guidelines:**
- **Shorter Duration** (2-3): More frequent signals, higher noise
- **Longer Duration** (5-7): Fewer signals, better quality
- **Smaller Lookback** (10-15): Faster response, may miss context
- **Larger Lookback** (30-50): More context, potentially delayed signals
**Signal Interpretation Guide**
**Visual Signal Hierarchy:**
**Light Green Triangle (Buy):**
- RSI recovered from oversold
- Duration requirements met
- Entry on reversal from oversold territory
**Light Red Triangle (Sell):**
- RSI declined from overbought
- Duration requirements met
- Entry on reversal from overbought territory
**Blue Triangle (Strong Buy):**
- Buy signal with bullish divergence
- Highest probability long setup
- Price made lower low, RSI made higher low
**Magenta Triangle (Strong Sell):**
- Sell signal with bearish divergence
- Highest probability short setup
- Price made higher high, RSI made lower high
**Tiny Green Circle (M+):**
- RSI crossed above 50 after oversold
- Momentum confirmation for uptrend
- Secondary entry or trend confirmation
**Tiny Red Circle (M-):**
- RSI crossed below 50 after overbought
- Momentum confirmation for downtrend
- Secondary entry or trend confirmation
**Background Coloring:**
- **Light Red Background**: RSI > 70 (overbought zone)
- **Light Green Background**: RSI < 30 (oversold zone)
**Trading Strategy Application**
**Conservative Approach (Strong Signals Only):**
1. Wait for blue/magenta triangles (divergence confirmed)
2. Enter on signal bar close or next bar open
3. Stop loss beyond recent swing high/low
4. Target minimum 2:1 risk/reward ratio
**Aggressive Approach (All Signals):**
1. Take light green/red triangles for earlier entries
2. Use momentum circles as confirmation
3. Tighter stops with partial profit taking
4. Scale positions based on signal strength
**Momentum Trading:**
1. Use momentum signals (M+/M-) as trend filters
2. Take primary signals aligned with momentum direction
3. Avoid counter-momentum signals in strong trends
4. Exit when opposing momentum signal appears
**Multi-Timeframe Strategy:**
1. Check higher timeframe for strong signals
2. Execute on lower timeframe primary signals
3. Use momentum signals for position management
4. Align all timeframe signals for best probability
**Optimal Market Conditions**
**Best Performance:**
- Mean-reverting markets with clear RSI extremes
- Range-bound or consolidating conditions
- Markets respecting support/resistance levels
- Timeframes: 15min to 4H for active trading
**Strong Signal Advantages:**
- Divergence signals often mark major turning points
- Work well at market structure levels
- Effective in both trending and ranging markets
- Higher success rate justifies waiting for setup
**Momentum Signal Benefits:**
- Confirms trend direction after extreme readings
- Useful for adding to positions
- Helps avoid counter-trend trades
- Works well in trending markets where reversals fail
**Technical Advantages**
**Divergence Accuracy:**
The improved divergence detection uses proper swing analysis rather than simple bar-to-bar comparison. This identifies genuine momentum shifts where price action diverges from oscillator movement over a meaningful period.
**Duration Logic:**
The for-loop counting method ensures the system checks actual RSI values within the lookback period, not just whether RSI touched levels. This distinguishes between sustained conditions and brief spikes.
**Momentum Filter:**
The 50-line crosses after extreme conditions provide an additional confirmation layer, helping traders distinguish between failed reversals (no momentum follow-through) and sustained moves (momentum confirmation).
**Risk Management Integration**
**Signal Priority:**
1. **Highest**: Strong signals with divergence (blue/magenta triangles)
2. **Medium**: Primary signals without divergence (light green/red triangles)
3. **Confirmation**: Momentum signals (tiny circles)
**Position Sizing:**
- Larger positions on strong signals (divergence present)
- Standard positions on primary signals
- Smaller positions or adds on momentum signals
**Stop Placement:**
- Beyond recent swing structure
- Below/above divergence swing low/high for strong signals
- Trail stops when momentum signals align with position
**Alert System**
Built-in alert conditions for:
- Buy Signal: RSI buy without divergence
- Sell Signal: RSI sell without divergence
- Strong Buy Alert: Buy with bullish divergence
- Strong Sell Alert: Sell with bearish divergence
Configure alerts via TradingView's alert system to receive notifications for chosen signal types.
**Important Considerations**
**Strengths:**
- Multiple confirmation layers reduce false signals
- Classical divergence improves reversal detection
- Momentum signals add trend-following capability
- Highly customizable for different trading styles
- No repainting - all signals fixed at bar close
**Limitations:**
- Duration requirements may cause missed quick reversals
- Divergence lookback period affects sensitivity
- Not suitable as standalone system
- Requires understanding of RSI principles and divergence concepts
**Best Practices:**
- Combine with price action and support/resistance
- Use higher timeframe context for directional bias
- Respect overall market trend and structure
- Implement proper position sizing based on signal type
- Test parameters on your specific instrument and timeframe
**Comparison Summary**
This enhanced version represents a significant upgrade:
- Upgraded to Pine Script v5 modern standards
- Proper classical divergence detection (not simplified)
- Added momentum confirmation signals
- Fully customizable parameters via inputs
- Visual background zone highlighting
- Comprehensive alert system
- Better signal differentiation through color coding
The system transforms basic RSI analysis into a multi-dimensional trading tool suitable for various market conditions and trading styles.
**Disclaimer**: This indicator is designed for educational and analytical purposes. While the multi-layer filtering and classical divergence detection improve upon standard RSI implementations, no indicator guarantees profitable trades. The duration filtering reduces false signals but may delay entries. Divergence signals, while statistically favorable, can fail in strong trending conditions. Always use proper risk management, position sizing, and stop-loss orders. Consider multiple confirmation methods and market context before making trading decisions. Past performance does not guarantee future results.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.