RSI in Bollinger bands
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Phantom_007

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
ob = input(70, minval=50, maxval = 100, title="Overbought Level")
os = input(30, minval=0, maxval = 50, title="Oversold Level")

bl = input(60, minval=50, maxval = 100, title="Buyers Level")
sl = input(40, minval=0, maxval = 50, title="Sellers Level")

src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=color.yellow, linewidth = 2)
hline(50, "Mid Band", color=color.gray)
band6=hline(bl, "Buyers Band", color=color.green)
band4=hline(sl, "Sellers Band", color=color.red)
band1 = hline(ob, "Upper Band", color=color.red, linewidth =2, linestyle= hline.style_solid)
band0 = hline(os, "Lower Band", color=color.green, linewidth =2, linestyle= hline.style_solid)
fill(band4, band6, color=#9915FF, transp=90, title="Background")
fill(band6, band1, color=color.green, transp=90, title="60-70")
fill(band4, band0, color=color.red, transp=90, title="60-70")
// bb
length = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(rsi, length)
dev = mult * stdev(rsi, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))