OPEN-SOURCE SCRIPT
MACD Divergence auto displayed on chart, with alerts

MACD Pivot Divergence Detector
This tool identifies MACD histogram divergences based on confirmed pivot highs and lows.
Instead of comparing swing points on the MACD line, this script focuses specifically on the histogram, which measures momentum shifts between MACD and Signal.
How it works
The script detects confirmed pivots using a two-bar swing structure.
When price breaks above a previous pivot high, the script compares the MACD histogram value at that pivot to the current histogram value:
• If price makes a higher high while the histogram makes a lower high, a potential bearish divergence is marked.
The reverse logic is applied for bullish divergence when price breaks below a pivot low.
What makes this script unique
It uses pivot-confirmed histogram values, not lookback-based divergence.
It evaluates divergence only at actual highs/lows, reducing false positives.
It marks divergence directly on the candles for visual clarity.
Alert conditions are included for automated detection.
How to use
Bullish signals may highlight potential momentum loss in downtrends; bearish signals may highlight momentum loss near highs. Divergence does not guarantee reversal and should be combined with broader context, structure, or trend analysis.
This tool identifies MACD histogram divergences based on confirmed pivot highs and lows.
Instead of comparing swing points on the MACD line, this script focuses specifically on the histogram, which measures momentum shifts between MACD and Signal.
How it works
The script detects confirmed pivots using a two-bar swing structure.
When price breaks above a previous pivot high, the script compares the MACD histogram value at that pivot to the current histogram value:
• If price makes a higher high while the histogram makes a lower high, a potential bearish divergence is marked.
The reverse logic is applied for bullish divergence when price breaks below a pivot low.
What makes this script unique
It uses pivot-confirmed histogram values, not lookback-based divergence.
It evaluates divergence only at actual highs/lows, reducing false positives.
It marks divergence directly on the candles for visual clarity.
Alert conditions are included for automated detection.
How to use
Bullish signals may highlight potential momentum loss in downtrends; bearish signals may highlight momentum loss near highs. Divergence does not guarantee reversal and should be combined with broader context, structure, or trend analysis.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.