The non repaint divergence indicator builds a Wilder RSI in one pass. It then compares the pivots on that line with the pivots on price. A pivot counts only once `InpPivotRight` newer bars have closed. That wait is what keeps every mark fixed. Arrows show in the RSI pane and, if you want them, on price.
This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.
| Platforms | MT4 (.ex4) + MT5 (.ex5) |
|---|---|
| Chart window | Separate window (levels 30 / 50 / 70) |
| Plots | 3: RSI, Bull Div, Bear Div |
| Alerts | popup, push notification, email, sound |
| Inputs | 14 |
What the Non repaint divergence Indicator draws on the chart
RSI is the dodger blue line in the lower pane, with level lines at 30, 50 and 70.
Bull Div places a lime arrow just under the RSI low that formed the divergence.
Bear Div places a red arrow just above the matching RSI high.
OBJ_ARROW objects put BUY and SELL marks on price while `InpDrawPriceArrows` stays true.
- RSI: line, dodger blue, width 2
- Bull Div: arrow, lime, width 2, arrow code 233
- Bear Div: arrow, red, width 2, arrow code 234

How the Non repaint divergence Indicator calculates its values
Building RSI in one pass
gain and loss arrays fill from the close differences. The first average takes a plain mean over `InpRSIPeriod` `14` bars. Every bar after that uses Wilder smoothing. rs is avgGain over avgLoss. rsi then takes 100 minus 100 over 1 plus rs. One pass covers the whole history.
Confirming pivots on both series
A pivot needs `InpPivotLeft` `3` older bars and `InpPivotRight` `3` newer bars on the correct side. The code keeps the last few pivots with their bar index, price and RSI value. Waiting for those three bars to close is what makes the mark stick.
Pairing pivots into a divergence
Bearish needs a higher price high against a lower RSI high. Bullish needs a lower price low against a higher RSI low. The two pivots must sit within `InpLookbackBars` `60` of each other. When both hold, the code writes the arrow two points off the RSI value.
How to read the signals
The mark sits on the confirmed pivot bar, three bars behind the current one.
Level lines at `InpLevelOB` `70.0` and `InpLevelOS` `30.0` give context for where a divergence formed.
Divergence above 70 or below 30 carries more weight than one forming near 50.
Set `InpDrawPriceArrows` to false if you want the pane on its own.
Alert channels in this build: popup, push notification, email and sound, one message per closed bar.
`InpEnableAlerts` ships off, so switch it on before anything fires. `InpEnablePopup` and `InpEnableSound` are true underneath it. `InpEnablePush` and `InpEnableEmail` are false. `InpSoundFile` names the clip. The guard allows one message per closed bar.
Every Non repaint divergence Indicator input
Core settings
| Setting | What it does | Default |
|---|---|---|
InpRSIPeriod |
RSI period. RSI length, default `14`. | 14 |
InpPivotLeft |
Bars left of pivot. Older bars a pivot must beat, default `3`. | 3 |
InpPivotRight |
Bars right of pivot (confirm delay). Newer bars needed to confirm a pivot, default `3`. This setting is the confirm delay. | 3 |
InpLookbackBars |
Max bars between paired pivots. Largest bar gap between paired pivots, default `60`. | 60 |
InpLevelOB |
Overbought reference. Overbought reference line, default `70.0`. | 70.0 |
InpLevelOS |
Oversold reference. Oversold reference line, default `30.0`. | 30.0 |
Display settings
| Setting | What it does | Default |
|---|---|---|
InpArrowOffsetPts |
Arrow offset (points) on price chart. Price chart arrow offset in points, default `12`. | 12 |
InpDrawPriceArrows |
Draw BUY/SELL arrows on price chart. Draws BUY and SELL marks on price, default `true`. | on |
Alert settings
| Setting | What it does | Default |
|---|---|---|
InpEnableAlerts |
Master alert switch. Master alert switch, default `false`. | off |
InpEnablePopup |
Popup alert. Terminal popup, default `true`. | on |
InpEnablePush |
Mobile push. Mobile push, default `false`. | off |
InpEnableEmail |
Email. Mail delivery, default `false`. | off |
InpEnableSound |
Sound. Sound playback, default `true`. | on |
InpSoundFile |
Clip played when sound is on, default `alert.wav`. | alert.wav |

Settings that fit your chart
Divergence needs a market that swings rather than drifts. EURUSD H1 is the reference chart. There `InpLookbackBars` at `60` covers about two and a half days. Shorter timeframes give more pivots and more pairings. Most of them are small. Up on H4 the pairings turn rare, and each one spans a real swing.
When the Non repaint divergence Indicator fails
Not repainting costs three bars. The mark can never land on the extreme itself.
RSI can disagree with price through an entire trend without that trend ending.
`InpPivotLeft` and `InpPivotRight` at `3` is a loose pivot test, so small swings qualify.
Copy the compiled Non repaint divergence 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 Non repaint divergence Indicator for MT4 and MT5
The zip holds the compiled Non repaint divergence 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.
FAQ
What makes InpPivotRight the non-repaint setting?
It counts the newer bars a pivot must beat before it becomes real. At `3` the code waits for three bars to close on the correct side. It then fixes the pivot for good. Nothing recalculates later, so a mark from yesterday still sits in the same place today.
What does InpLookbackBars at 60 limit?
The bar distance between the two pivots a divergence compares. Sixty bars on EURUSD H1 is about two and a half days. Pivots further apart get ignored. Two swings from different weeks rarely say anything useful about one another.
Why does the RSI plot show levels at 30 and 70?
They come from `InpLevelOS` and `InpLevelOB`, at `30.0` and `70.0`. The lines carry no logic of their own here. The divergence test reads pivot values only. What the levels give you is context for judging where a divergence formed.
Can I turn off the price chart arrows?
Yes. Set `InpDrawPriceArrows` to false and the OBJ_ARROW objects on price stop appearing. Bull Div and Bear Div marks inside the RSI pane carry on as before. You keep the signal without adding clutter to the chart.
Are results guaranteed?
No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Non repaint divergence 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
- The core method is documented in Secondary market on Wikipedia.
- Additional market context is at istddev (STDDEV) at the MQL5 Documentation.
