Bollinger Bands Filled - Didi's Needles setup
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hgrams

//@version=5
indicator(shorttitle="BB Didi", title="Bollinger Bands Didi", overlay=true, timeframe="", timeframe_gaps=true)

// Inputs
length = input.int(8, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval = -500, maxval = 500)
useFill = input.bool(true, title = "Fill Bandes ?")


// Calculations
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// BB Condition
bbOpenUp = upper > upper[1] and lower < lower[1] and basis > basis[1]
bbOpenDown = upper > upper[1] and lower < lower[1] and basis < basis[1]
bbParallelUp = upper > upper[1] and (lower > lower[1] or lower == lower[1])
bbParallelDown = (upper < upper[1] or upper == upper[1]) and lower < lower[1]
bbClose = upper < upper[1] and lower > lower[1]

// Colors Settings
colBbOpenUp = input.color(color.new(#5b9bf5, 10), "BB Open Upper Color", group = "Color Setting", inline = "BB Colors")
colBbOpenDown = input.color(color.new(#fff176, 10), "BB Open Lower Color", group = "Color Setting", inline = "BB Colors")
colBbParallelUp = input.color(color.new(#5b9bf5, 30), "BB Parallel Upper", group = "Color Setting", inline = "BB Colors")
colBbParallelDown = input.color(color.new(#fff176, 30), "BB Parallel Lower", group = "Color Setting", inline = "BB Colors")
colBbClose = input.color(color.new(color.white, 70), "BB Close", group = "Color Setting", inline = "BB Colors")

// Plots
plot(basis, "Basis", bbOpenUp ? colBbOpenUp : bbOpenDown ? colBbOpenDown : bbParallelDown ? colBbParallelDown : bbParallelUp ? colBbParallelUp : colBbClose, offset = offset, display = display.none)
p1 = plot(upper, "Upper", bbOpenUp ? colBbOpenUp : bbOpenDown ? colBbOpenDown : bbParallelDown ? colBbParallelDown : bbParallelUp ? colBbParallelUp : colBbClose, offset = offset)
p2 = plot(lower, "Lower", bbOpenUp ? colBbOpenUp : bbOpenDown ? colBbOpenDown : bbParallelDown ? colBbParallelDown : bbParallelUp ? colBbParallelUp : colBbClose, offset = offset)

color fillBandsColor = na
if useFill
    fillBandsColor := switch
        bbParallelUp => color.new(colBbParallelUp, 90)
        bbParallelDown => color.new(colBbParallelDown, 90)
        bbOpenUp => color.new(colBbOpenUp, 80)
        bbOpenDown => color.new(colBbOpenDown, 80)
        bbClose => color.new(colBbClose, 98)

fill(p1, p2, title = "Background", color = fillBandsColor, display = display.all)
