MACD Divergence all in one
Feb 25, 2025

The MACD Divergence all in one indicator identifies bullish and bearish divergences between price action and the MACD oscillator to help traders spot potential trend reversals and hidden momentum shifts.
Usage
The MACD Divergence all in one indicator can be used to detect potential exhaustion in a trend. When price continues to make new lows while the MACD begins to rise, a bullish divergence is identified, suggesting a possible upward reversal. Conversely, when price makes higher highs but the MACD creates lower highs, a bearish divergence is signaled, suggesting a potential downward reversal.
The indicator provides clear visual cues on the oscillator pane:
- Bullish Divergences: Displayed as green connecting lines and labeled "Bull Div" at the bottom of the MACD peaks.
- Bearish Divergences: Displayed as red connecting lines and labeled "Bear Div" at the top of the MACD peaks.
Traders often look for these signals near established support or resistance zones or use them as confirmation alongside other trend-following tools.
Details
The script utilizes a pivot-based algorithm to identify peaks and troughs in both price and the MACD line. It stores these pivot points in arrays and calculates the relative change between consecutive pivots. By comparing the slope of price movement against the slope of the MACD movement, it detects discrepancies (divergences).
A "Strength Filter" is implemented to ensure that only significant divergences are plotted, helping to reduce noise from minor price fluctuations. The script also includes a spacing mechanism to prevent overlapping labels and excessive signaling during choppy market conditions.
Settings
MACD Parameters
- Fast Length: Sets the period for the fast Exponential Moving Average (EMA) used in the MACD calculation.
- Slow Length: Sets the period for the slow EMA used in the MACD calculation.
- Signal Length: Sets the smoothing period for the MACD Signal line.
Divergence Detection
- Left Pivot Bars: Number of bars required to the left of a high or low to confirm a pivot.
- Right Pivot Bars: Number of bars required to the right of a high or low to confirm a pivot.
- Divergence Lookback: The number of recent pivots the script stores for analysis.
- Minimum Divergence Length: The minimum distance in bars allowed between two points to qualify as a divergence.
- Maximum Divergence Length: The maximum distance in bars allowed between two points to qualify as a divergence.
- Minimum Divergence Strength: A filter threshold that requires a specific level of discrepancy between price and MACD to trigger a signal.
FAQ
How do I access MACD Divergence all in one?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Can I use this on any timeframe?
Yes, the indicator is compatible with all timeframes, though it is often considered more reliable on higher timeframes like the 1H, 4H, or Daily charts to filter out market noise.
Are the signals repainting?
The indicator uses a pivot-based approach which requires a "Right Pivot Bars" confirmation. Signals will appear once the specified number of bars to the right of a pivot has closed, ensuring the pivot is confirmed.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.