RSI Divergence Alert Indicator: Pivots on the RSI Line Itself

Written by Dominic Walsh · Published · Last updated

The rsi divergence alert indicator looks for regular divergence. Price makes a lower low while RSI makes a higher one, or price makes a higher high while RSI makes a lower one. What separates this build is where it hunts for pivots. It finds them on the RSI line itself, not on price. Then it checks what price did at those same bars.

This build ships as a compiled .ex4 for MT4 and .ex5 for MT5.

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Separate window
Plots 3: RSI, Bull Divergence, Bear Divergence
Alerts popup, push notification, email, sound
Inputs 13

What the Rsi divergence alert Indicator draws on the chart

RSI is the dodger blue line in its own pane, scaled 0 to 100.

Bull Divergence marks a lime arrow just under the RSI value at a qualifying pivot low.

Bear Divergence marks a red arrow just above the RSI value at a qualifying pivot high.

Both markers sit on the RSI scale inside the pane, clamped so they stay visible near the extremes.

  • RSI: line, dodger blue, width 2
  • Bull Divergence: arrow, lime, width 2, arrow code 233
  • Bear Divergence: arrow, red, width 2, arrow code 234
RSI divergence alert indicator with divergence arrows on the RSI line in its own pane
RSI divergence alert indicator with divergence arrows on the RSI line in its own pane

How the Rsi divergence alert Indicator calculates its values

Computing Wilder’s RSI once per call

The source header notes this build computes the RSI in one pass rather than calling iRSI per bar. A seed bar takes avgGain and avgLoss as plain averages over `RSIPeriod`. Every later bar smooths them Wilder’s way. avgGain becomes (avgGain * (RSIPeriod – 1) + g) / RSIPeriod, and avgLoss does the same. That is the original formula, and one pass keeps it fast.

Finding pivots on the oscillator

`LeftBars` and `RightBars` set the fractal window, at `5` and `3` by default. The asymmetry is deliberate: more bars on the older side make a pivot meaningful, fewer on the newer side let it confirm sooner. Those pivots are located on RsiBuf, the oscillator line, which is the reverse of tools that find price pivots first.

Pairing two pivots and comparing

dist takes prevLowIdx minus c and must stay within `MaxPivotDistance`. A bullish signal then needs low[c] below low[prevLowIdx] while RsiBuf[c] sits above RsiBuf[prevLowIdx]. Price lower, momentum higher. BullBuf receives Clamp(RsiBuf[c] – 3.0, 1.0, 99.0), so the marker sits just under the line and stays inside the pane even at an extreme reading.

How to read the signals

The arrows live on the RSI scale, so read them against the line rather than against price.

Every signal joins two pivots. Look left of an arrow to find the earlier one it was compared with.

A wide pivot distance lets the tool pair swings that are far apart, which changes which comparisons are possible at all.

Turning on the extreme filter cuts the count sharply and leaves divergences that formed in oversold or overbought territory.

Alert channels in this build: popup, push notification, email and sound, one message per closed bar.

Four channels ship beneath `EnableAlerts`: popup, push notification, email and sound, with `SoundFile` naming the clip. Popup starts enabled. The source header confirms the message goes out once per closed bar, which matches the pivot confirmation delay.

Every Rsi divergence alert Indicator input

Core settings

Setting What it does Default
RSIPeriod RSI period. Bars in the oscillator, default `14`, Wilder’s original figure. 14
OverboughtLevel Overbought reference. Upper reference at `70`, used by the extreme filter rather than for signals on its own. 70
OversoldLevel Oversold reference. Lower reference at `30`. 30
LeftBars Pivot: bars to the left (older). Bars on the older side of an RSI pivot, default `5`. 5
RightBars Pivot: bars to the right (newer). Bars on the newer side, default `3`. Lower than LeftBars so a pivot confirms sooner. 3
MaxPivotDistance Max bars between paired pivots. Furthest apart two paired pivots may sit, default `60` bars. 60
RequireExtreme Bull pivot < OS / bear pivot > OB. Off by default. Set it `true` and a bull pivot must sit below the oversold level, a bear pivot above overbought. off

Alert settings

Setting What it does Default
EnableAlerts (see inputs panel) on
EnablePopup (see inputs panel) on
EnablePushNotify (see inputs panel) off
EnableEmail (see inputs panel) off
EnableSound (see inputs panel) off
SoundFile (see inputs panel) alert.wav
RSI divergence alert indicator inputs: RSIPeriod, LeftBars, RightBars, MaxPivotDistance
RSI divergence alert indicator inputs: RSIPeriod, LeftBars, RightBars, MaxPivotDistance

Settings that fit your chart

Divergence needs swings with room between them. The majors on H1 and H4 suit it well. A 60-bar pivot distance covers about two and a half days of H1 bars. On M5 the RSI turns constantly and many pairings mean nothing. On the daily chart signals turn rare and each one spans months, which suits position traders.

When the Rsi divergence alert Indicator fails

Divergence is a warning, not a trigger. Price can keep making lower lows against a rising RSI for a long time before anything turns.

Pivots on the RSI confirm three bars late by default, so every arrow arrives after the swing it marks.

Without the extreme filter the tool pairs mid-range pivots where a divergence carries much less weight than one at an oversold reading.

Copy the compiled Rsi divergence alert Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.

Download the Rsi divergence alert Indicator for MT4 and MT5

The zip holds the compiled Rsi divergence alert Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.

Download this indicator free

Enter your email and the file is yours. You also get the full MT4 and MT5 library.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

Why find pivots on the RSI rather than on price?

Because the oscillator is the half that has to disagree. Locating pivots on RsiBuf first means every candidate already represents a turn in momentum, and the code then checks what price did at those same bars. Tools that start from price pivots often find swings where the RSI never turned at all.

Why are LeftBars and RightBars different?

To trade confirmation speed against significance. `LeftBars` at `5` means a pivot must stand out against five older bars, which makes it meaningful. `RightBars` at `3` means only three newer bars are needed to confirm it, so the arrow arrives sooner. Equal values would make it either slower or weaker.

What does RequireExtreme add?

A location filter. With it on, a bullish divergence only counts when the RSI pivot sits below `OversoldLevel`, and a bearish one only when it sits above `OverboughtLevel`. That removes mid-range divergences, which are common and weak. Expect far fewer arrows and better context on the ones that remain.

What is MaxPivotDistance controlling?

How far apart two paired pivots may be, at `60` bars by default. dist is measured as prevLowIdx minus c and checked against that ceiling. Widen it on slower charts where swings are further apart. Narrow it to keep every comparison tied to recent structure.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Rsi divergence alert Indicator as one input. Always backtest before trading live.

Category: this is part of our Oscillators collection. Browse more Oscillators for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment