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

//@version=5
indicator("BB phases", overlay = true)

bullishColor = input.color(color.rgb(76, 175, 79, 80), "bullish color", group = "personalisation")
bearishColor = input.color(color.rgb(255, 82, 82, 80), "bearish color", group = "personalisation")
squeezeColor = input.color(color.rgb(33, 149, 243, 80), "squeeze color", group = "personalisation")


[middleBB, upperBB, lowerBB] = ta.bb(close, 20, 2)


marketPhase = close < upperBB and close > lowerBB ? "squeeze" : close > upperBB ? "pump" : close < lowerBB ? "dump" : "error"

if marketPhase[1] == "pump" 
    if close > middleBB
        marketPhase := "pump"

if marketPhase[1] == "dump"
    if close < middleBB
        marketPhase := "dump"

bbColor = marketPhase == "squeeze" ? squeezeColor : marketPhase == "pump" ? bullishColor : marketPhase == "dump" ? bearishColor : color.gray

u = plot(upperBB, color=color.rgb(255, 235, 59, 64))
l = plot(lowerBB, color=color.rgb(255, 235, 59, 64))

fill(u, l, color=bbColor)



reintegrateBollingerHigh = close < upperBB and close[1] > upperBB
reintegrateBollingerLow = close > lowerBB and close[1] < lowerBB

plotshapeSize = size.normal
plotshape(series=reintegrateBollingerHigh, style=shape.triangledown, color=bearishColor, text="", size=plotshapeSize, location=location.abovebar)
plotshape(series=reintegrateBollingerLow, style=shape.triangleup, color=bullishColor, text="", size=plotshapeSize, location=location.belowbar)

