MACD Divergences by @DaviddTech

Aug 25, 2021

Static chart image
Signals
Oscillators
Divergences
Moving Averages
Pivot Based (Retrospective)

The MACD Divergences indicator identifies regular and hidden divergences between price action and the Moving Average Convergence Divergence (MACD) oscillator to highlight potential trend reversals or continuations.

Usage

The Usage section focuses on identifying price-oscillator discrepancies to gauge market momentum. Users can apply this tool to spot two primary types of signals:

  • Regular Divergences: These occur when price makes a new extreme (higher high or lower low) that is not confirmed by the MACD line, often signaling a potential trend reversal.
  • Hidden Divergences: These occur when the MACD makes a new extreme while price does not, often suggesting a continuation of the prevailing trend.

The indicator plots labels and connecting lines directly on the oscillator pane. Labels are offset by the "Pivot Lookback Right" value to ensure the pivot point is confirmed before a signal is displayed.

Details

The script calculates the MACD line based on the difference between two moving averages (Fast and Slow) and a Signal line representing a smoothed average of the MACD. Divergence detection is based on pivot points found within a user-defined lookback window.

To ensure higher signal quality, the "Don't touch the zero line" setting filters regular bullish divergences to only appear when the MACD is below zero, and regular bearish divergences only when the MACD is above zero. This ensures that the momentum shift is occurring at an extreme rather than near the baseline.

Settings

  • Fast Length: The period for the shorter-term moving average.
  • Slow Length: The period for the longer-term moving average.
  • Source: The price data used for MACD calculations (e.g., Close, Open, HL2).
  • Signal Smoothing: The period for the Signal line moving average.
  • Oscillator MA Type: Choose between SMA or EMA for the MACD line components.
  • Signal Line MA Type: Choose between SMA or EMA for the Signal line smoothing.
  • Don't touch the zero line?: When enabled, regular divergences are filtered based on their position relative to the zero level.
  • Pivot Lookback Right/Left: The number of bars required to the right and left of a point to confirm it as a pivot high or low.
  • Max/Min Lookback Range: Defines the window of bars searched to find a previous pivot for comparison.
  • Plot Bullish/Bearish: Toggles the visibility of regular bullish and bearish divergence labels.
  • Plot Hidden Bullish/Bearish: Toggles the visibility of hidden trend continuation signals.

FAQ

How do I interpret the "H Bull" and "H Bear" labels? These represent "Hidden" divergences. An "H Bull" suggests bullish trend continuation, while an "H Bear" suggests bearish trend continuation.

Why do labels appear several bars after a peak or trough? The script uses pivot lookbacks to confirm a high or low. The labels are plotted once the "Pivot Lookback Right" requirement is met, ensuring the point is a confirmed local extreme.

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

Free access on the following platforms
tradingviewSymbolTradingView
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

ninjatraderNinjaTrader
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

metatrader4MetaTrader 4/5
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

thinkorswimThinkorswim
Open in your browser

This in-app browser is not compatible with Get Access from the library.

Tap the menu (...) at the top of your screen and select "Open in Browser", "Open in Safari", or "Open in Chrome" to continue.

Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.

Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.

As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.

Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.

Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.

This does not represent our full Disclaimer. Please read our full disclaimer.

© 2026 LuxAlgo Global, LLC.