Divergence
Price makes a new swing extreme while RSI or MACD momentum does not.
Regular divergence (the TradingView Divergence Indicator rule) between the last two pivots of the oscillator (RSI of the close, or the MACD histogram of the close). A pivot low is an oscillator value strictly below the pivot_left values before it and the pivot_right values after it (pivot high: strictly above); it is known on the candle pivot_right candles after it. Each new pivot is compared with the previous pivot of its kind when the candles between them are min_spacing to max_spacing. bull: the low at the new pivot candle is below the low at the previous one and the oscillator is higher; bear: the high is above the previous high and the oscillator is lower. bull / bear are true on the candle the new pivot is known. bull_pivot_price / bear_pivot_price hold the low / high of the newer pivot candle of the last bullish / bearish divergence until the next one of that kind.
Divergence is a structure detector: it marks price structure on the chart and counts against the plan's detector limit.
Settings
| Setting | Default | Range | What it does |
|---|---|---|---|
| osc | rsi | rsi, macd_hist | Oscillator compared with price. |
| rsi_length | 14 | 1 to 500 | RSI length. |
| fast | 12 | 1 to 500 | Fast EMA length. |
| slow | 26 | 2 to 500 | Slow EMA length. |
| signal | 9 | 1 to 500 | Signal EMA length. |
| pivot_left | 5 | 1 to 100 | Pivot lookback left: candles before a pivot whose oscillator value it must pass. |
| pivot_right | 5 | 1 to 100 | Pivot lookback right: candles after a pivot whose oscillator value it must pass (the divergence is known this many candles after the pivot). |
| min_spacing | 5 | 1 to 500 | Fewest candles between the two pivots. |
| max_spacing | 60 | 2 to 1000 | Most candles between the two pivots. |
What it gives
| Output | What it is |
|---|---|
| Bullish divergence | True on the candle a bullish divergence is confirmed. |
| Bearish divergence | True on the candle a bearish divergence is confirmed. |
| Bullish divergence pivot low | Low of the newer pivot candle of the last bullish divergence. |
| Bearish divergence pivot high | High of the newer pivot candle of the last bearish divergence. |
What it reads
It reads the whole candle (open, high, low, close and volume).
Warm-up
With its default settings, Divergence needs 211 closed candles before its first value. A backtest loads them before its start date, so the first trade can already use it.
Test it
Copy this sentence into the Algonney chat to backtest it:
Backtest a strategy on BTC that uses Divergence with its default settings