PROTECTED SOURCE SCRIPT
Ks MACD Divergence Visualizer

MACD Divergence Visualizer (v6) Documentation
This indicator is a powerful technical analysis tool designed for TradingView (Pine Script v6). It automatically detects and visualizes Divergence—a discrepancy between price action and the MACD (Moving Average Convergence Divergence) oscillator—to identify potential trend reversals or continuations.
1. Core Functionality
4 Types of Detected Divergence
The script identifies and distinguishes between four specific market patterns:
Type
Name
Condition
Market Sentiment
Regular Bullish
Regular Bull
Price makes a lower low, but MACD makes a higher low.
Potential Reversal (Bullish)
Regular Bearish
Regular Bear
Price makes a higher high, but MACD makes a lower high.
Potential Reversal (Bearish)
Hidden Bullish
Hidden Bull
Price makes a higher low, but MACD makes a lower low.
Trend Continuation (Buy Dip)
Hidden Bearish
Hidden Bear
Price makes a lower high, but MACD makes a higher high.
Trend Continuation (Sell Rally)
2. How the Logic Works
Pivot Point Detection
The indicator uses ta.pivothigh and ta.pivotlow to identify significant peaks and troughs in the MACD line.
Left Lookback: Number of bars to the left required to confirm a local peak/trough (Default: 5).
Right Lookback: Number of bars to the right required to confirm the point (Default: 3).
Note: Signals will appear with a delay equal to the "Right Lookback" value to ensure the pivot point is historically valid.
Visual Encoding
Solid Line: Represents Regular Divergence (Reversal). Marked with an "R" label.
Dashed Line: Represents Hidden Divergence (Continuation). Marked with an "H" label.
Color Coding: Green/Teal for Bullish signals, Red/Orange for Bearish signals.
3. Configuration (Input Parameters)
MACD Settings
Fast / Slow / Signal Length: Standard settings are 12, 26, 9. Shorten these for faster response in scalping or lengthen them for swing trading.
Divergence Settings
Pivot Lookback Right: Increasing this improves signal reliability but increases the display delay.
Show Regular / Hidden: Toggle specific types of divergence on/off to declutter your chart.
4. Trading Strategy Tips
Regular (R) = Warning: If a Regular Bearish (R) divergence appears at the end of an uptrend, it suggests the momentum is fading—consider tightening stop losses or taking profits.
Hidden (H) = Confluence: Hidden Bullish (H) divergence during an established uptrend is a strong signal that the trend is healthy and the current dip is a buying opportunity.
Multi-Timeframe Confirmation: Divergences are most effective when confirmed by higher timeframe trends or key Support/Resistance levels.
This indicator is a powerful technical analysis tool designed for TradingView (Pine Script v6). It automatically detects and visualizes Divergence—a discrepancy between price action and the MACD (Moving Average Convergence Divergence) oscillator—to identify potential trend reversals or continuations.
1. Core Functionality
4 Types of Detected Divergence
The script identifies and distinguishes between four specific market patterns:
Type
Name
Condition
Market Sentiment
Regular Bullish
Regular Bull
Price makes a lower low, but MACD makes a higher low.
Potential Reversal (Bullish)
Regular Bearish
Regular Bear
Price makes a higher high, but MACD makes a lower high.
Potential Reversal (Bearish)
Hidden Bullish
Hidden Bull
Price makes a higher low, but MACD makes a lower low.
Trend Continuation (Buy Dip)
Hidden Bearish
Hidden Bear
Price makes a lower high, but MACD makes a higher high.
Trend Continuation (Sell Rally)
2. How the Logic Works
Pivot Point Detection
The indicator uses ta.pivothigh and ta.pivotlow to identify significant peaks and troughs in the MACD line.
Left Lookback: Number of bars to the left required to confirm a local peak/trough (Default: 5).
Right Lookback: Number of bars to the right required to confirm the point (Default: 3).
Note: Signals will appear with a delay equal to the "Right Lookback" value to ensure the pivot point is historically valid.
Visual Encoding
Solid Line: Represents Regular Divergence (Reversal). Marked with an "R" label.
Dashed Line: Represents Hidden Divergence (Continuation). Marked with an "H" label.
Color Coding: Green/Teal for Bullish signals, Red/Orange for Bearish signals.
3. Configuration (Input Parameters)
MACD Settings
Fast / Slow / Signal Length: Standard settings are 12, 26, 9. Shorten these for faster response in scalping or lengthen them for swing trading.
Divergence Settings
Pivot Lookback Right: Increasing this improves signal reliability but increases the display delay.
Show Regular / Hidden: Toggle specific types of divergence on/off to declutter your chart.
4. Trading Strategy Tips
Regular (R) = Warning: If a Regular Bearish (R) divergence appears at the end of an uptrend, it suggests the momentum is fading—consider tightening stop losses or taking profits.
Hidden (H) = Confluence: Hidden Bullish (H) divergence during an established uptrend is a strong signal that the trend is healthy and the current dip is a buying opportunity.
Multi-Timeframe Confirmation: Divergences are most effective when confirmed by higher timeframe trends or key Support/Resistance levels.
Protected script
This script is published as closed-source. However, you can use it freely and without any limitations – learn more here.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Protected script
This script is published as closed-source. However, you can use it freely and without any limitations – learn more here.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.