All indicators

MACD Divergence [ALERTSETUP]

Jul 4, 2019

Static chart image
SignalsOscillatorsDivergencesMoving Averages

The MACD Divergence [ALERTSETUP] indicator identifies bullish and bearish divergences between the price and the MACD histogram to help traders spot potential trend reversals. By comparing the peaks and troughs of the histogram against price action, this tool highlights areas where momentum may be fading despite price reaching new extremes.

Usage

The indicator can be used to identify potential reversal points in the market. When the price makes a higher high but the MACD histogram makes a lower high, a bearish divergence occurs, suggesting a possible downward reversal. Conversely, when the price makes a lower low but the MACD histogram makes a higher low, a bullish divergence occurs, suggesting a possible upward reversal.

  • Bearish Divergence: Highlighted with a red background, indicating that upward momentum is weakening.
  • Bullish Divergence: Highlighted with a green background, indicating that downward momentum is weakening.
  • Crossover Signals: Optional dots appear when the MACD line crosses the Signal line, providing additional confirmation for entry or exit.

Details

This script is a refactored version of classical divergence detection logic, optimized for real-time alerts. It calculates the standard Moving Average Convergence Divergence (MACD) using exponential moving averages. A key feature of this implementation is the removal of security-based functions to ensure the signals do not repaint, making it reliable for live trading environments. The divergence logic specifically monitors the relationship between the "Divergence Source" (defaulting to close price) and the peaks/troughs of the MACD histogram.

Settings

  • Show MacD & Signal Line?: Toggles the visibility of the MACD and Signal lines on the oscillator pane.
  • Show Dots When MacD Crosses Signal Line?: Displays circular markers at the point where the MACD crosses the Signal line.
  • Show Histogram?: Toggles the visibility of the MACD histogram.
  • Change MacD Line Color-Signal Line Cross?: If enabled, the MACD line color changes based on whether it is above or below the Signal line.
  • MacD Histogram 4 Colors?: Enables a gradient coloring system for the histogram to show increasing/decreasing momentum strength.
  • Fast Length: The period for the shorter-term EMA used in MACD calculation (default 12).
  • Slow Length: The period for the longer-term EMA used in MACD calculation (default 26).
  • Signal Length: The period for the smoothing SMA of the MACD line (default 9).
  • Divergence Source: The price source used to calculate divergences against the histogram.

FAQ

How do I set up alerts for divergences?

You can create alerts using the TradingView alert menu and selecting "Bearish Divergence" or "Bullish Divergence" from the condition dropdown menu provided by the script.

Does this indicator repaint?

No, the script is designed without security functions or future-looking offsets that cause repainting, ensuring signals remain fixed once the bar closes.

How can I access this tool?

You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.