divergence detects regular (reversal) and hidden (trend-continuation) divergences between price fractal pivots and both RSI and MACD histogram, boosting pairs confirmed by both oscillators simultaneously.
Parameters
Parameter
Default
Range
Type
Timeframe overrides
window
500
60..2000
integer
—
pivotSpan
3
2..10
integer
4 on <= 5m, 2 on >= 1d
rsiPeriod
14
5..30
integer
—
includeHidden
1
0..1
integer (0 or 1)
—
max
4
1..8
integer
—
Algorithm & Nuances
Pivot pair window: Computes rsi(c, rsiPeriod) and macd(c, 12, 26, 9) (histogram). Inspects the latest 18 swing lows and latest 18 swing highs, testing each pivot b against up to 4 preceding same-side pivots a within 5 <= b - a <= 80 bars.
Clean-path check: Rejects any pair (a, b) where an intervening candle k in (a, b) pierces past the pair’s extreme by more than 0.25 * atr[k], ensuring diagonal divergence segments never cut across intermediate price action.
RSI qualification:
regular_bull: Lower low (l[b] < l[a]), higher RSI (rb > ra + 2), first pivot oversold (ra <= 45, extra +0.6 boost if ra <= 35).
Deduplicates per (direction, secondPivot) keeping the highest score, then returns the max most recent divergences ordered chronologically.
Drawings & Facts
Drawings: For each divergence (up to max), 1 dashed segment trendline connecting the two price pivots plus 1mark at the second pivot (Bull Div, Bear Div, Hid Bull, Hid Bear with RSI, MACD, or RSI+MACD).