Divergence Signal Alerts MT4
- Indicatori
-
Allan Aparece Ninal
Sviluppo indicatori ed Expert Advisor per MetaTrader 5.
Come lavoro:
- Ogni indicatore viene controllato contro il repainting: i segnali vengono decisi solo su barre chiuse, e un test su ogni tick conferma che non cambiano in seguito. - Versione: 1.3
- Aggiornato: 4 dicembre 2026
Divergence Signal Alerts MT4 is a free MetaTrader 4 indicator that finds divergences between price and RSI, MACD, Stochastic, CCI, the Awesome Oscillator or Momentum. It draws a line between the two price pivots and puts an arrow on the bar that confirmed the divergence. Arrows appear when a bar closes and never move afterwards. Attach it to a chart, or watch it on history in the Strategy Tester's visual mode.
It draws, marks and alerts. It does not trade.
What's new in 1.3
- Divergence lines: 1.0 kept every line, 1.1 and 1.2 deleted the oldest lines past 2,500 (a long scan could look like it had lost lines). 1.3 keeps every line again by default.
- New input "Lines: Divergence lines kept" (0 = all, or 100 to 20000 newest), at the end of the input list.
- Buffers 4 and 5 (RSI and MACD histogram) are filled on every bar again, even when that source is switched off, as in 1.0.
- Signals are unchanged: with the default inputs the arrows, types and values are identical to 1.2.
In plain words
A divergence is a disagreement. Price makes a lower low, but a momentum line makes a higher low. Many traders read this as selling pressure that is fading.
A momentum line turns price changes into one line. RSI is the best known. This indicator calls each such line a source.
The indicator finds each swing low and high, and compares it with the one before. It does this for every source you switch on. RSI and MACD are on. Stochastic, CCI, the Awesome Oscillator and Momentum are off until you switch them on.
When price and a source disagree, a line joins the two swing points. An arrow marks the bar that confirmed it.
The mark says that price and momentum disagree. It does not say where price goes next.
What you see on the chart
- Price makes a swing low. The indicator waits for 3 more bars to close before it counts it.
- It compares this low with the previous swing low, 5 to 60 bars back, and reads each source at both points.
- Price made a lower low and a source made a higher low. A green line joins the two lows. A green arrow sits under the bar that confirmed it.
- At swing highs the mirror works the same way. The line and the arrow are red, and the arrow is above the bar.
- A solid line is a regular divergence. A dashed line is a hidden one, if you switched it on. Hover over a line to see which sources diverged.
Worked example
XAUUSD H4, all six sources on, taken from the engine test of this indicator (terminal history, bar times in server time). The older swing low was 3852.54 on 12 Nov 2026 at 16:00. The newer one was 3832.36 on 16 Nov at 04:00, a lower low. Three bars later, the bar that opened on 16 Nov at 16:00 confirmed it.
| Source | At the older low (12 Nov 16:00) | At the newer low (16 Nov 04:00) | Result |
|---|---|---|---|
| RSI | 25.11 | 25.52 | higher low: diverges |
| MACD histogram | -20.30 | -6.03 | higher, but a bar crossed its line: not counted |
| Stochastic %K | 6.99 | 9.64 | higher low: diverges |
| CCI | -185.55 | -97.33 | higher low: diverges |
| Awesome Oscillator | -115.66 | -126.38 | lower: no divergence |
| Momentum | 94.78 | 96.24 | higher low: diverges |
Four of six sources diverged: RSI, Stochastic, CCI and Momentum. The line and the arrow carry that count in their tooltip. With "at least this many sources must agree" set to 5, this divergence would not show.
Key facts
| Type | Indicator on the price chart, for MetaTrader 4. |
| Draws | A line between the two price pivots, an arrow on the confirming bar and a tooltip on the line. |
| When a signal is final | When the confirming bar closes. The arrow, the line and the alert never move afterwards. The forming bar is never used. |
| Reload and timeframe change | The indicator scans the last 2000 closed bars again and draws the same arrows, with the same inputs and the same history. No alerts are sent for old signals. |
| Alerts | Pop-up and push are on. Sound and e-mail are off. One alert per new divergence, on the bar that confirms it. Alerts are silent in the Strategy Tester. |
| Trades | No. It places no orders. |
| Sources | Six. RSI and MACD are on. Stochastic, CCI, Awesome Oscillator and Momentum are off. |
| Other products needed | None. |
| Symbols and timeframes | Any symbol and timeframe. Tested on EURUSD, GBPJPY, XAUUSD and BTCUSD at M15, H1 and H4. |
Quick start
- Attach the indicator to any chart and timeframe. It scans the last 2000 closed bars.
- Look for the arrows. Each one sits on a bar that confirmed a divergence, a few bars after the pivot.
- The defaults work without tuning. To try another source, switch it on in the "More sources" inputs (at the end of the list). Raise "at least this many sources must agree" for fewer arrows.
- Pop-up and push alerts are on. Switch on sound or e-mail if you want them. Push needs your MetaQuotes ID under Tools, Options, Notifications.
Who it is for
For traders who use divergence to spot a possible turn or the continuation of a trend, on any symbol and timeframe. Also for those who want to compare several momentum lines on one chart.
Not for you if you want a ready-made trading system. A divergence can be followed by more of the same trend. You decide which arrows matter.
How it works under the hood
Pivots and the divergence rule
Pivots are swing lows and highs of price. A swing low has a lower low than each of the 5 bars before it. None of the 3 bars after it is lower. Both numbers are inputs.
The 3 bars after the pivot are the confirmation delay. The pivot is known only when the third one has closed. That bar gets the mark.
At a new swing low, the indicator looks at the previous swing lows, newest first, 5 to 60 bars back. It tests up to three of them.
- Regular bullish: the new low is lower than the old low, and the source's value is higher.
- Hidden bullish (off by default): the new low is higher, and the source's value is lower.
- Bearish mirrors this at swing highs.
- Clean lines (on by default): no bar between the two pivots may cross the straight line between them, on price or on the source.
The sources
Each source is a line calculated from closed bars. A source that is switched off is not calculated. A divergence needs a value at both pivots, so a source says nothing until it has enough bars.
| Source | Formula | Periods |
|---|---|---|
| RSI | Wilder RSI of the close. The average gain and loss start as a simple average of the first n changes. After that, new = (old x (n - 1) + now) / n. | 14 |
| MACD histogram | EMA(fast) of the close minus EMA(slow), minus the EMA(signal) of that difference. Each EMA starts as a simple average of its first values. | 12, 26, 9 |
| Stochastic %K | Raw %K = 100 x (close - lowest low) / (highest high - lowest low) over the period. It is 50 when the range is zero. The source is the simple average of raw %K over the slowing period. | 14, 3 |
| CCI | (typical price - its simple average) / (0.015 x mean deviation from that average). Typical price = (high + low + close) / 3. | 20 |
| Awesome Oscillator | Simple average of the median price (high + low) / 2 over the fast period, minus the same over the slow period. | 5, 34 |
| Momentum | 100 x close / the close n bars earlier. This is the platform's own Momentum. | 14 |
How many sources must agree
By default one source is enough. "Only when at least two sources agree" asks for two. "At least this many sources must agree" sets any number. It never asks for more than the number of sources that are on. With RSI and MACD on, 1.2 gives the same arrows as 1.1.
When a signal is final
Every value uses closed bars only. The arrow sits on the bar that completes the pivot, so it appears when that bar closes. It never moves, and nothing is drawn into the past after that.
Reload, restart and timeframe change
After a reload, a restart or a timeframe change, the indicator reads the last 2000 closed bars again and redraws every line and arrow. With the same inputs and the same history, they land on the same bars. If your broker corrects old bars, marks on those bars can change.
No alert is sent for a divergence found during that scan. Alerts go out only for a bar that closes while the indicator runs. The chart keeps every line by default. The input "Divergence lines kept" limits it to the newest 100 to 20000 lines. A limit hides older lines only; arrows and buffers are never limited.
MetaTrader 4 difference
MetaTrader 4 cannot shift an arrow by pixels. The arrows sit a fraction of ATR(14) away from the candle. The input is 0.3 by default. MetaTrader 4 also allows only eight indicator buffers, so buffers 6 and 7 hold the source masks and the new sources have no value buffers.
Inputs
| Input | Default | Description |
|---|---|---|
| RSI divergence / RSI period | on / 14 | RSI source. |
| MACD histogram divergence / fast, slow, signal | on / 12, 26, 9 | MACD histogram source. |
| Regular / hidden divergence | on / off | Reversal type and continuation type. |
| Pivot: bars on the left / right | 5 / 3 | The right side is the confirmation delay. |
| Pivots at least / at most this many bars apart | 5 / 60 | Distance between the two pivots. |
| Clean lines | on | No bar between the pivots crosses the line, on price or on the source. |
| Only when at least two sources agree | off | RSI and MACD by default. |
| Closed bars to scan | 2000 | 100 to 20000. |
| Draw the line between the pivots; colours | on | Bullish green, bearish red. |
| Arrow distance from the candle (x ATR) | 0.3 | ATR(14) multiple. |
| Pop-up / push / sound / e-mail | on / on / off / off | Alerts. Push needs your MetaQuotes ID. |
| Debug log for bug reports | off | See Found a problem? |
| Stochastic %K divergence / %K period, slowing | off / 14, 3 | More sources. |
| CCI divergence / CCI period | off / 20 | More sources. |
| Awesome Oscillator divergence / fast, slow SMA | off / 5, 34 | More sources. |
| Momentum divergence / period | off / 14 | More sources. |
| At least this many sources must agree | 1 | 1 means any one source. |
| Divergence lines kept | 0 (all) | 0 keeps every line. Otherwise 100 to 20000: only the newest lines stay. |
Alerts and Expert Advisor use
Alerts. One alert per new divergence, on the bar that confirms it. Pop-up, sound, push and e-mail are switched separately. Nothing is sent while history loads, twice for the same bar, or in the Strategy Tester.
Buffers for Expert Advisors. Read them from the last closed bar (shift 1).
| Buffer | Content |
|---|---|
| 0 and 1 | Bullish arrow (the bar's low) and bearish arrow (the bar's high), moved by the arrow distance |
| 2 and 3 | Their type: 1 regular, 2 hidden |
| 4 and 5 | RSI and MACD histogram, filled on every bar (also when that source is switched off) |
| 6 and 7 | New in 1.2: the sources that diverged on a bullish or bearish arrow bar, as a bit mask. RSI 1, MACD 2, Stochastic 4, CCI 8, Awesome Oscillator 32, Momentum 64 |
How often it signals
Divergences per month per symbol on EURUSD, GBPUSD, USDJPY and XAUUSD, October 2023 to October 2026, closed bars, defaults (RSI and MACD, regular). It is a code count, not a trading result.
| Timeframe | Divergences per month |
|---|---|
| M15 | about 36 to 43 |
| H1 | about 8 to 11 |
| H4 | about 2 to 3 |
| D1 | about 0.2 to 0.4 |
How often each source diverges alone, with the same symbols, period and rules:
| Source alone | H1 | H4 |
|---|---|---|
| RSI | about 3.7 to 5.1 | about 1 to 1.2 |
| MACD histogram | about 6.5 to 9.1 | about 1.9 to 2.1 |
| Stochastic %K | about 4.4 to 5.4 | about 1 to 1.4 |
| CCI | about 5.9 to 7.5 | about 1.4 to 2 |
| Awesome Oscillator | about 3 to 4.1 | about 0.7 to 1 |
| Momentum | about 3.4 to 4 | about 0.9 to 1.3 |
More sources on means more arrows. Raise "at least this many sources must agree" for fewer.
How it was checked
- Calculation: the MetaTrader 4 Strategy Tester produced the arrows, their type, the sources that diverged and the RSI and MACD values. They were compared bar by bar with a Python calculation. It ran on EURUSD, GBPJPY, XAUUSD and BTCUSD at M15, H1 and H4, with six input sets. Four of them used the new sources. All 73 files matched (48,880 arrows).
- Source formulas: The MetaTrader 4 engine file is an exact copy of the MetaTrader 5 one. In MetaTrader 5, a Python calculation matched the engine's values for each of the six sources. It covered 288,000 bars in 96 files, on EURUSD, GBPJPY, XAUUSD and BTCUSD from M15 to D1. A second set of vector formulas matched on 456,000 values. RSI, CCI, Awesome Oscillator and Momentum also match the platform's own indicators, with a largest relative difference of 4.6e-13. The MACD histogram uses an EMA signal line and the Stochastic averages raw %K, so those two differ from the platform's by definition.
- Repaint: an every-tick Strategy Tester run on EURUSD H1, 2026, with the default inputs: 8,417,316 ticks, 4,812 closed bars and 74 arrows. None changed after its bar closed and none showed on the live bar. Across all runs, 1,507,764 closed bars were re-checked with 0 changes. with default inputs, 13 files in the MetaTrader 4 tester: every arrow, type, RSI and MACD value was identical.
- Divergence lines: in the MetaTrader 4 tester on EURUSD M15 with 20000 bars scanned, "Divergence lines kept" at 0 left 882 lines, at 100 exactly 100 and at 250 exactly 250. The arrow count was the same in every run.
- Validator-style runs: ten runs (five symbols and timeframes, deposits of 100 and 1,000) ended with 0 error lines.
- Compile: 0 errors and 0 warnings.
Not tested: alerts on a live chart (the tester is silent for alerts). No profit or accuracy test was made. The indicator shows a pattern and is not a strategy.
Limits
- A divergence is not a turn call. Many are followed by more of the same trend.
- The arrow comes 3 bars after the pivot, so it is never on the low or the high. This is the cost of never repainting.
- It gives no stop loss, target or lot size.
- The arrows depend on your broker's bars. Another broker's history can give slightly different bars and marks.
- It scans the last 2000 closed bars by default. Older divergences are not drawn. Keeping every line on a very long scan puts many objects on the chart; use "Divergence lines kept" or scan fewer bars.
- Every source you add makes more arrows. Many arrows are not better arrows.
- Alerts need the terminal to be running with the chart open.
FAQ
Does it repaint? No. It uses closed bars only. The arrow sits on the bar that confirmed the divergence, a few bars after the pivot, and never moves.
Why is the arrow a few bars after the low or high? A pivot is known only after the next bars have closed. Drawing it earlier would mean redrawing later.
What happens if I change the timeframe or reload the chart? The indicator reads the closed bars again and draws the same arrows, as long as the inputs and the history are the same. It sends no alerts for old signals.
Did 1.3 change my arrows? No. With the default inputs the arrows, their type and the RSI and MACD values are the same as in 1.2. The only differences are the line limit (every line is kept by default again) and buffers 4 and 5 (filled on every bar again).
Why does the chart show more lines than in 1.1 or 1.2? Those versions deleted the oldest lines once there were 2,500. 1.3 keeps every line again, as 1.0 did. If that many lines are a problem on your chart, set "Divergence lines kept" to a number from 100 to 20000, or scan fewer bars.
Which source should I use? I have not found that one is better. The table above shows how often each one diverges. Start with the defaults, add one source and compare.
What is the difference between regular and hidden? Regular divergence points to a reversal. Hidden divergence points to a continuation. Hidden is off by default.
Does it work on gold and crypto? Yes, on any symbol with history.
Can an Expert Advisor read it? Yes. Read the buffers listed above, from shift 1.
Will I get alerts on my phone? Yes, push is on by default. Set your MetaQuotes ID in the terminal options. The terminal must be running.
Is there a MetaTrader 5 version? Yes, Divergence Signal Alerts, with the same inputs and the same arrows.
Try it first
It is free. Attach it to a chart on a demo account, or run it in the Strategy Tester in visual mode on history. Check each arrow against its bar and its two pivots. History shows when each arrow appeared, not what price did next.
Works well with
These are workflow suggestions. I have not found that any pair gives better trading results. You do not need any of them.
| Product | How to use them together | Why |
|---|---|---|
| Session Levels MT4 | Add it to the same chart. | It draws the Asia, London and New York sessions and killzones, the previous day and week levels and a time panel as context. It is not a signal. |
| SMC Zones MT4 | Add it to the same chart. | It draws order blocks, fair value gaps and structure breaks as context. It describes past bars. |
| Risk Position Tool MT4 | Pick the trade from the chart, then drag the entry and stop lines. The tool gives the lot for your risk. | It separates where you enter from how much you risk. The tool places no orders. |
| Repaint and Signal Scorecard MT4 | Name this indicator and its buy and sell buffers. The scorecard checks whether its signals repaint and how they did on the chart history. | It measures the signals and places no trades. A good score on history is not a forecast. |
| Indicator Arrow Trader MT4 | Name this indicator and its arrow buffers. The EA reads the arrow of each closed bar and sends the order with a stop loss and a fixed 0.01 lot. | It turns the arrows into orders for you. It promises no profit; test it on a demo account first. |
Related products
- Divergence Signal Alerts: the same indicator for MetaTrader 5.
- Candlestick Signal Alerts MT4 - a free indicator with the same closed-bar approach and the same alert options, for candlestick patterns.
- WaveTrend Signals MT4 - a free indicator with the same closed-bar approach and alert options, for WaveTrend crosses in the overbought and oversold zones.
- MACD Multi Timeframe Signal Alerts MT4 - a free indicator with the same closed-bar approach. It alerts on MACD crosses on the chart or a higher timeframe.
- All my products on MQL5
Custom work
Want an EA that trades this indicator, a custom version of it, several of my indicators or EAs combined into one, an EA that trades another indicator you use (mine or another developer's), or a new indicator or EA of your own? Order it through MQL5 Freelance and choose me as the developer: order through Freelance. Send your requirements, rules and the flow or algorithm you want. The whole order, payment and delivery stay inside MQL5 Freelance.
Found a problem?
- In the inputs, set "Debug log for bug reports" to true.
- Repeat what went wrong.
- Open the Experts tab in the Toolbox. Copy the lines that start with "DBG" and paste them in a comment on this page, with the symbol and timeframe.
- Set the debug log back to false.
The debug lines never contain your account number, name, server, balance or equity.
If you find it useful, a short review on this page helps other traders find it.
Questions: use the comments on this page or send me a message on MQL5.
The defaults are a starting point. An indicator does not predict price, and trading carries a risk of loss.

version 1 better than version 1.2