MACD + Divergence + Line
Jan 12, 2022

The MACD + Divergence + Line indicator provides a comprehensive trend-following and momentum toolkit by combining a customizable MACD oscillator with automated detection for four types of price-momentum divergences. It serves as a visual aid for identifying trend reversals and continuations through color-coded histograms and signal line analysis.
Usage
The Usage section describes how the script can be used to interpret market momentum and potential exhaustion points.
MACD Histogram and Signal Lines
The indicator calculates the difference between two moving averages (fast and slow) to create the MACD line. Users can toggle the visibility of the MACD and Signal lines to focus purely on the histogram or use them to identify classic crossovers. The histogram features a four-color gradient system:
- Bright Green: Oscillator is above zero and increasing (strong bullish momentum).
- Dull Green: Oscillator is above zero and decreasing (weakening bullish momentum).
- Bright Red: Oscillator is below zero and decreasing (strong bearish momentum).
- Dull Red: Oscillator is below zero and increasing (weakening bearish momentum).
Divergence Detection
The script automatically scans for discrepancies between price action and the MACD oscillator:
- Regular Bullish/Bearish: Indicates potential trend reversals. A regular bullish divergence occurs when price makes a lower low while the MACD makes a higher low.
- Hidden Bullish/Bearish: Indicates potential trend continuation. A hidden bullish divergence occurs when price makes a higher low while the MACD makes a lower low.
Details
The indicator allows for granular control over the calculation methods, offering both Simple Moving Average (SMA) and Exponential Moving Average (EMA) options for both the oscillator and the signal line smoothing. The divergence logic is based on pivot points defined by the lookback settings; a "Pivot Lookback Right" of 5 means a divergence is confirmed 5 bars after the actual peak or trough has occurred to ensure data validity.
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 calculations (default is close).
- Signal Smoothing: The period used to calculate the Signal line from the MACD.
- Oscillator MA Type: Select between SMA or EMA for the MACD calculation.
- Signal Line MA Type: Select between SMA or EMA for the Signal line smoothing.
- Show Sma: Toggles the visibility of the MACD and Signal lines.
- Pivot Lookback Right/Left: Determines the number of bars required to confirm a pivot high or low for divergence detection.
- Max/Min of Lookback Range: Defines the bar range window where the script searches for previous pivots to compare against the current one.
- Plot Bullish/Bearish/Hidden: Toggles the visibility of specific divergence types on the chart.
FAQ
How do I identify a trend reversal using this tool?
Look for Regular Divergence labels (Bull or Bear). When price reaches a new extreme but the MACD histogram fails to follow, it suggests momentum is slowing down, often preceding a reversal.
Can I change the moving average type?
Yes, the settings menu allows you to independently switch both the MACD components and the Signal line between SMA and EMA to suit different trading styles or asset classes.
How do I get access to MACD + Divergence + Line?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
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.

