All indicators

MACD divergence with line drawing

Feb 10, 2020

Static chart image
Support and ResistanceSignalsOscillatorsDivergencesDrawing ToolVolatility

The MACD divergence with line drawing indicator identifies regular divergences between price action and the MACD oscillator, providing automated visual annotations and potential support/resistance levels. It aims to highlight potential reversal zones by detecting discrepancies between market peaks or troughs and the corresponding MACD values.

Usage

The Usage section explains how to interpret the visual outputs of the script:

  • Divergence Lines: When a regular divergence is detected, the script draws a line connecting the relevant price peaks (for short) or troughs (for long).
  • S/R Lines: Users can enable Support and Resistance lines, which are projected from the peak or trough situated between the two points of divergence. These levels often act as horizontal market pivots.
  • SL Lines: The indicator can plot a Stop Loss suggestion based on the last peak/trough +/- 1x ATR.
  • Trend Filtering: By enabling the trend check, the indicator will only signal divergences that align with a higher timeframe trend (calculated via a higher TF EMA). For example, a long divergence will only appear if the price is above the higher timeframe EMA.

Details

The script utilizes a smoothed MACD calculation to identify "peaks" and "valleys" within the histogram. It scans a defined historical range (up to 140 bars) to find previous MACD extremes that correlate with price movement. The detection logic ensures that the price and MACD are moving in opposite directions (e.g., lower low in price but higher low in MACD). To ensure clarity, the script includes logic to prevent duplicate signals within the same swing and uses an ATR-based calculation for dynamic stop-loss positioning.

Settings

MACD Configuration

  • Simple MA (Oscillator/Signal Line): Toggles between SMA and EMA for the MACD and Signal calculations.
  • Source MACD: The price source used for calculation (default is Close).
  • Fast/Slow Length: Periods for the fast and slow moving averages.
  • Signal Smoothing: The period for the MACD signal line.

Visuals

  • Visible SR lines?: Toggles the horizontal support/resistance lines.
  • Visible DIVERGENCE lines?: Toggles the lines connecting price points of divergence.
  • Visible SL lines?: Toggles the ATR-based stop-loss lines.

Trend Filter

  • Divergence with a trend?: Filters signals based on higher timeframe price action.
  • Fast EMA Length: Period for the local trend EMA.
  • Higher TF: The timeframe used for the trend-following EMA.
  • EMA Length: Period for the higher timeframe EMA.

FAQ

How do I use the S/R lines?

The S/R lines are generated from the local extreme between the two divergence points. These levels often serve as areas where price may stall or retest after a divergence-driven move.

What does the "Trend Check" feature do?

When enabled, it filters out counter-trend signals. A long divergence is only shown if the current price is above the higher timeframe EMA, and a short divergence only if it is below.

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.