Divergence Detector
Early warning that the existing trend is losing fuel.
Finds moments when price prints a new extreme but RSI and MACD do not — classic early reversal signal.
The idea
Trends end when the people driving them run out of money or conviction. That exhaustion shows up in momentum indicators before it shows up in price. By the time the chart breaks down, RSI has already been sliding lower for weeks.
Divergence Detector automates the pattern recognition: for every bar, it looks back 20 bars, finds the lowest low (for bullish setups) and highest high (for bearish setups), and compares the momentum readings at those extremes with the current reading.
Signal types
| Label | Meaning | Strength |
|---|---|---|
| Bull Div (RSI) | Price new low, RSI higher low | Normal |
| Bull Div (MACD) | Price new low, MACD histogram higher | Normal |
| Bull Div (RSI+MACD) | Both agree | Strong |
| Bear Div (RSI) | Price new high, RSI lower high | Normal |
| Bear Div (MACD) | Price new high, MACD histogram lower | Normal |
| Bear Div (RSI+MACD) | Both agree | Strong |
Signals respect an 8-bar cooldown to avoid clustering.
How to use it
- Enable Divergence Detector in the Scripts panel. Markers appear under or above the candle that completed the divergence.
- Treat the signal as permission to look for a trade, not a trade itself. Wait for price action confirmation — a break of the last minor swing, a reversal candle, a retest of a key level.
- Strong signals (RSI+MACD) are worth paying attention to even in trending markets. Weak single-indicator signals need extra context.
Why divergences work (and when they fail)
In a typical cycle, the final push higher is driven by late buyers chasing momentum. They pay more but generate less follow-through, so the oscillator can't keep up with price. Eventually the marginal buyer runs out and the trend reverses.
The mode that breaks this is a parabolic blowoff. In that regime, divergences form and persist for a long time without resolving. If you see three or four stacked bearish divergences that keep getting invalidated, you are likely in a blowoff — step aside and wait for the break.