OPEN-SOURCE SCRIPT

Candle Closes Outside Bollinger Bands

//version=5
indicator("Candle Closes Outside Bollinger Bands", overlay=true)

// Bollinger Bands parameters
length = input.int(20, title="BB Length")
src = close
mult = input.float(2.0, title="BB Multiplier")

// Bollinger Bands Calculation
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upperBB = basis + dev
lowerBB = basis - dev

// Condition for closing outside of the Bollinger Bands
closeAboveUpperBB = close > upperBB
closeBelowLowerBB = close < lowerBB

// Plotting signals
plotshape(closeAboveUpperBB, title="Close Above Upper BB", location=location.abovebar, color=color.green, style=shape.labelup, text="Close > Upper BB")
plotshape(closeBelowLowerBB, title="Close Below Lower BB", location=location.belowbar, color=color.red, style=shape.labeldown, text="Close < Lower BB")

// Optionally, plot the Bollinger Bands for visual reference
plot(upperBB, color=color.blue, title="Upper BB")
plot(lowerBB, color=color.blue, title="Lower BB")
Bands and Channels

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer