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

//@version=5
indicator(shorttitle="BB POS", title="Bollinger Band POS", overlay=true)
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(1, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", 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))

aboveSDev = low[1] < (ta.sma(close[1], length) + (mult * ta.stdev(close[1], length))) and low > upper
belowSDev = high[1] > (ta.sma(close[1], length) - (mult * ta.stdev(close[1], length))) and high < lower

if (aboveSDev)
    box.new(left=bar_index, top=high, right=bar_index+4, bottom=low, border_color=color.new(color.green,25), bgcolor=color.new(color.green,40))
    
if (belowSDev)
    box.new(left=bar_index, top=high, right=bar_index+4, bottom=low, border_color=color.new(color.blue,45), bgcolor=color.new(color.blue,40))