PROTECTED SOURCE SCRIPT

Smart MACD Divergence Detector [Auto]

64

This indicator automates one of the most powerful concepts in technical analysis: MACD Divergences.

Spotting divergences manually is tedious, prone to subjective errors, and often clutters your main chart with lines. This tool solves that problem by automatically detecting and visualizing momentum shifts directly within the oscillator panel.

It is designed to keep your price chart clean while providing high-probability reversal warnings based on pure math.

snapshot

🎯 Key Features

1. Automated Divergence Detection
The script uses a pivot-based algorithm to compare price action with MACD momentum.
  • 🟢 BULLISH DIVERGENCE: Detected when Price makes a Lower Low, but the MACD Histogram/Line makes a Higher Low. This indicates selling pressure is exhausted.
  • 🔴 BEARISH DIVERGENCE: Detected when Price makes a Higher High, but the MACD Histogram/Line makes a Lower High. This indicates buying power is fading.

2. Smart Visualization
  • Clean & Precise: Divergence lines are drawn directly connecting the pivot points on the MACD, ensuring you see exactly why the signal was generated.
  • 4-Color Histogram: Includes a modern color-coded histogram to visualize momentum growth and decay at a glance.
  • Zero Clutter: All visuals remain in the indicator pane. Your main chart stays clean for your EMAs or price action drawings.

snapshot

⚙️ How it Works & Settings
You can customize the "brain" of the detector to fit your trading style (Scalping vs. Swing Trading).

Pivot Sensitivity (Left/Right):
  • This controls how strictly the script defines a "Top" or "Bottom".
  • Lower values (e.g., 2-3): Faster signals, good for Scalping, but more noise.
  • Higher values (e.g., 8-10): Slower confirmation, strictly for Swing Trading, filters out small corrections.

Max Lookback Range:
  • Defines how far back (in bars) the script checks for the previous peak. Default is 60 bars.


⚠️ Trading Tips
Divergences are reversal warnings, not immediate entry signals.
  • Don't catch a falling knife: Wait for the divergence line to appear and for the candle to close.
  • Combine with Trend: A bullish divergence is most powerful when it happens at a key support level or the EMA 200.
  • Risk Management: Always use a Stop Loss. Momentum can stay divergent for a long time in strong parabolic moves.

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.