Bollinger Bands Width and Bollinger Bands %B
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © polarbearking

//@version=5
indicator(title="Bollinger Bands Width and Bollinger Bands %B", shorttitle="BBW & %B", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

// Bollinger Bands Width (BBW): Color = (Default: Green [#138484]) 
// Bollinger Bands %B (%B): Color = (Default: Blue [#62b6ee])

length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

basis = ta.sma(src, length)
stdev = ta.stdev(src, length)
dev = mult * stdev

upper = basis + dev
lower = basis - dev
bbw = ((upper-lower)/basis) * 10
bbr = (src - lower)/(upper - lower) * 10

hline(mult * 4)
hline(mult * 3)
hline(mult * 2)
hline(mult)
hline(1)
hline(10)

plot(bbr, "Bollinger Bands %B", color=#62b6ee)
plot(bbw, "Bollinger Bands Width", color=#138484)
