MACD Divergence (fadi)

This indicator plots a standard MACD and automatically finds divergences between price and MACD. You choose whether divergences are measured on the MACD line or on the histogram. Each divergence is drawn on the MACD pane and, optionally, on the price chart. It also marks a confirmation level for each divergence and removes the ones that price invalidates, so the chart keeps the divergences that are still in play and the ones that played out.
Everything is evaluated on closed candles. Nothing appears, moves or disappears while a candle is still forming.
WHAT IS DIFFERENT ABOUT IT
DIVERGENCE TYPES
CONFIRMATION LEVEL
Each divergence gets a confirmation level taken from the candles that led into its second point.
This follows the order block idea. These are the last candles that pushed price into the extreme, and a candle closing through the far side of them shows that the push has been undone.
The level is drawn on the price chart and extends to the right. When a candle closes through it, the line stops at that candle and the divergence is confirmed.
LIFE OF A DIVERGENCE
HOW TO READ IT
A regular divergence is commonly read as a warning that a move is losing momentum, and a hidden divergence as a sign that the existing trend may continue. Either one is context for a decision, not a trade signal on its own.
SETTINGS
General Settings
MACD
The MACD line, signal line, histogram and zero line colors can be changed in the Style tab.
Divergence Display
ALERTS
To receive alerts, create an alert on this indicator and choose "Any alert() function call" as the condition.
NOTES AND LIMITATIONS
Everything is evaluated on closed candles. Nothing appears, moves or disappears while a candle is still forming.
WHAT IS DIFFERENT ABOUT IT
- Closing prices, not wicks. Price swings are read from candle closes, the same data MACD is calculated from by default, so price and MACD are compared on equal terms.
- MACD line or histogram. One setting switches which MACD series the divergences are measured on.
- A confirmation level for every divergence. Each one gets a level based on the order block idea, and the indicator tracks whether price closes through it.
- Self-cleaning. Divergences that fail are deleted. Divergences that confirmed are kept.
- On the pane and on the chart. The same divergence can be shown on the MACD and on price, so you do not have to line them up by eye.
- No repainting inside a candle. Signals only change when a candle closes.
DIVERGENCE TYPES
- Bearish: price closes at a higher high while MACD makes a lower high.
- Bullish: price closes at a lower low while MACD makes a higher low.
- Hidden bearish (optional): price closes at a lower high while MACD makes a higher high.
- Hidden bullish (optional): price closes at a higher low while MACD makes a lower low.
CONFIRMATION LEVEL
Each divergence gets a confirmation level taken from the candles that led into its second point.
- Bearish: the lowest low of the run of up-close candles that ends at the second high.
- Bullish: the highest high of the run of down-close candles that ends at the second low.
This follows the order block idea. These are the last candles that pushed price into the extreme, and a candle closing through the far side of them shows that the push has been undone.
The level is drawn on the price chart and extends to the right. When a candle closes through it, the line stops at that candle and the divergence is confirmed.
LIFE OF A DIVERGENCE
- It appears when the candle that forms its second point closes, and stays provisional until price has turned at that point (a later candle closes back from it) and MACD has turned too.
- If MACD had already turned before the second point, the MACD end sits at that turn from the start. If MACD is still moving the same way as price, the MACD end of the line follows it candle by candle, with no candle limit, and locks where MACD turns.
- While provisional, it is removed if price closes beyond its second point, or if MACD's move breaks the divergence, for example MACD rising above its first high in a regular bearish divergence.
- It is confirmed when a candle closes through its confirmation level. A confirmed divergence stays on the chart, even if price later closes beyond its second point, so you keep a record of the ones that played out.
- It is deleted if a candle closes beyond its second point before the confirmation level is broken.
HOW TO READ IT
- Red lines and "Bear" labels are bearish divergences. Green lines and "Bull" labels are bullish divergences. "H Bear" and "H Bull" are hidden divergences.
- On the MACD pane, the divergence line connects the two points on the series you chose, the MACD line or the histogram.
- The dotted line on the price chart is the confirmation level. A line that still reaches the latest closed candle is pending. A line that ends at an earlier candle was closed through at that candle.
- A divergence that disappears was invalidated by a close beyond its second point.
A regular divergence is commonly read as a warning that a move is losing momentum, and a hidden divergence as a sign that the existing trend may continue. Either one is context for a decision, not a trade signal on its own.
SETTINGS
General Settings
- Show Last: the maximum number of divergences kept on the chart. Default 100.
- Show hidden divergence: also show hidden divergences.
- Detect one divergence per pivot: shows one divergence per swing point, not several lines from the same point.
- Delete irrelevant divergence: deletes divergences that price closes beyond before they confirm. When this is off, they stay on the chart and only their confirmation level is removed.
- Type of divergence to show: Both, Bullish or Bearish.
- Divergence on: MACD line or Histogram. Default MACD line. The histogram turns more often than the MACD line, so it usually gives more, smaller divergences.
- Lookback depth: how far back the indicator looks for the first point of a divergence. Small, Medium or Large.
MACD
- Fast Length, Slow Length and Source: default 12, 26 and close.
- Signal Smoothing: default 9.
- Oscillator MA Type and Signal Line MA Type: SMA or EMA. Default EMA.
The MACD line, signal line, histogram and zero line colors can be changed in the Style tab.
Divergence Display
- On chart: also draws divergences on the price chart. The colors, width and style on the same row apply to the divergence lines, bearish color first and bullish second.
- Confirmation: shows or hides the confirmation level, with its own bearish and bullish colors, width and style. It is drawn on the price chart, so "On chart" must be enabled.
- Label: shows or hides the labels and sets their size.
- Bearish and Bullish: the text color and the background color of the labels for each direction.
ALERTS
To receive alerts, create an alert on this indicator and choose "Any alert() function call" as the condition.
- An alert is sent when a divergence is detected, which is when price and MACD have both turned at its second point. Provisional divergences do not send alerts.
- The message is "MACD Bullish Divergence Detected", "MACD Bearish Divergence Detected", "MACD Hidden Bullish Divergence Detected" or "MACD Hidden Bearish Divergence Detected".
- If more than one type is detected on the same candle, they arrive together in one alert, one line per type.
- Alerts follow the "Type of divergence to show" and "Show hidden divergence" settings, so you are only alerted to divergences the indicator would draw.
NOTES AND LIMITATIONS
- The newest divergence stays provisional until both price and MACD have turned at its second point, and can be removed during that time.
- Swing points and invalidation use closing prices, so a wick beyond a swing point does not count. The confirmation level is set from candle highs and lows, but it still needs a close through it.
- When a long run of same-color candles leads into the second point, the confirmation level sits at the far end of the whole run and can be a long way from price. When the run is a single candle, the level is close.
- Divergences are shown for the most recent 5000 bars.
- With a high Show Last value, TradingView's drawing limits may remove the oldest lines and labels.
- This indicator does not predict price and makes no claim about performance. It is a tool for reading momentum against price and is not financial advice.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.