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

//@version=4
study(title="myBBands", shorttitle="myBbands", overlay=true)
len_bb = input(20, minval=1, title="BB Length")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
bbp = input (100, minval = 3, title ="BBand Pinch length")

src = input(close, title="Source")

basis = sma(src, len_bb)
dev = mult * stdev(src, len_bb)
upper = basis + dev
lower = basis - dev
bbbw = bbw(close, len_bb, mult)
Lowestbbw = lowest(bbbw, bbp)[1]

pinch = float(na)
pinch := bbbw <= Lowestbbw ? 1 : close [1] > upper[1] ? na : close [1] < lower[1] ? na : pinch[1]

plot(basis, color=#ffffff, title="BB Basis", transp=85)
p1 = plot(upper, color=#ffffff, title="BB Upper", transp=85)
p2 = plot(lower, color=#ffffff, title="BB Lower", transp=85)
plot(pinch == 1 ? upper : na, style = plot.style_linebr, linewidth=2, color=#ff00ff, transp=10, title= 'BBand Pinch Coloru')
plot(pinch == 1 ? lower : na, style = plot.style_linebr, linewidth=2, color=#ff00ff, transp=10, title= 'BBand Pinch Colord')
fill(p1, p2, color=iff(pinch == 1, #9598a1, na), transp= 77, title= "Pinch Background")
//