# RSI bullish divergence

> RSI bullish divergence is an alert that checks every 15 minutes, fires at most once per bar and shows where it fires on the chart.

Source: https://algobarsx.com/docs/ex-12-rsi-divergence-alert/

```algobarsx
alert "RSI bullish divergence"
    check: every 15m
    repeat: once per bar
    show_on_chart: true

input rsi_length = 14
input lookback = 30

momentum_now = rsi(close, rsi_length)
lower_low = low < lowest(low, lookback)[1]
higher_rsi = momentum_now > lowest(momentum_now, lookback)[1]

when lower_low and higher_rsi and was(momentum_now < 30, within: 5 bars):
    notify "Bullish RSI divergence on {market.symbol}: RSI {momentum_now:0.0}"
```
What this script says

RSI bullish divergence is an alert that checks every 15 minutes, fires at most once per bar and shows where it fires on the chart.

You can change 2 inputs: `rsi_length` (default 14) and `lookback` (default 30).

It calculates `momentum_now` as the RSI over `rsi_length` bars, `lower_low` as whether the low is below the previous bar's lowest low of the last `lookback` bars and `higher_rsi` as whether `momentum_now` is above the previous bar's lowest `momentum_now` of the last `lookback` bars.

When `lower_low` and `higher_rsi` and `momentum_now` is below 30 at some point within the last 5 bars, it sends the notification "Bullish RSI divergence on {market.symbol}: RSI {momentum_now:0.0}".
