Skip to content

Free MT5 indicator

MACD Divergence

MACD line, signal and four-colour histogram for MT5 that marks regular and hidden divergences with arrows and lines.

Momentumv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Alerts

What it does

MACD Divergence shows the MACD line, its signal line and a histogram in a separate window, and looks for disagreements between price and momentum. When it finds one it draws a line between the two oscillator pivots, places an arrow on the newer pivot and, if you like, draws a matching line on the price chart.

It detects four patterns: regular bullish, hidden bullish, regular bearish and hidden bearish. Regular divergences are drawn with solid lines and hidden ones with dashed lines.

How it works

  1. MACD = EMA(12) − EMA(26) of the close. Signal = EMA(9) of MACD. Histogram = MACD − signal.
  2. The histogram uses four colours: strong green when positive and rising, light green when positive and falling, strong red when negative and falling, light pink when negative and rising.
  3. A pivot low is a bar whose oscillator value is lower than the 5 bars before it and not higher than the 3 bars after it. A pivot high is the mirror image. A pivot is only confirmed once those 3 later bars have closed.
  4. Each new pivot is compared with the previous pivot of the same type if they are between 5 and 60 bars apart:
    • Regular bullish: price makes a lower low, MACD makes a higher low.
    • Hidden bullish: price makes a higher low, MACD makes a lower low.
    • Regular bearish: price makes a higher high, MACD makes a lower high.
    • Hidden bearish: price makes a lower high, MACD makes a higher high.

How to use it

  • Regular divergence suggests momentum is fading in the current move and is often studied near the end of a trend.
  • Hidden divergence suggests a pullback has stretched momentum without breaking price structure, and is often studied as trend continuation.
  • Divergence describes momentum, not timing. Many traders wait for a trigger after the mark, such as a histogram colour change or a break of a minor swing.
  • Divergences that form at clear support and resistance levels deserve more attention than those in open space.
  • Learn the underlying indicator in MACD Indicator.

Settings

InputDefaultWhat it changes
Fast / slow / signal EMA12 / 26 / 9The MACD itself
Oscillator used for pivotsMACD lineHistogram pivots are more frequent and more sensitive
Pivot bars left / right5 / 3Pivot strictness; more right bars means later but steadier marks
Minimum / maximum bars between pivots5 / 60Which pivot pairs are compared
Show regular / hidden divergencestrue / trueToggle each family
Draw lines on the price charttrueMirrors the divergence on price
Pop-up alert / Push notificationfalse / falseOne alert when a new divergence is confirmed

Limitations

  • Marks are delayed. A divergence can only be confirmed after the pivot's right-hand bars close, so the arrow appears 3 bars (by default) after the bar it is drawn on. Once drawn it does not move or disappear.
  • Divergence can persist through a strong trend, producing several marks before any reversal, or none at all.
  • Results depend heavily on the pivot settings; there is no universally correct value.
  • The MACD values on the live bar change with every tick.
  • Treat every mark as a prompt for analysis, not an instruction to trade. Trading involves substantial risk of loss.

Key inputs

Key inputs of MACD Divergence
InputDefaultDescription
Fast EMA length12Faster EMA of the MACD calculation.
Slow EMA length26Slower EMA of the MACD calculation.
Signal EMA length9EMA of the MACD line used as the signal line.
Oscillator used for pivotsMACD lineLook for divergence on the MACD line or on the histogram.
Pivot bars to the left5Bars before a pivot that must be less extreme.
Pivot bars to the right (confirmation delay)3Bars after a pivot that must be less extreme before it is confirmed.
Minimum / maximum bars between pivots5 / 60Allowed distance between the two pivots being compared.
Also draw divergence lines on the price charttrueMirrors each divergence line on the main chart.

Educational tools, not advice. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 indicators