You are on page 1of 1

//@version=5

strategy("Bollinger Band Breakout", shorttitle="BB Breakout", overlay=true)

length = input.int(20, title="Length", minval=1)


maType = input.string("SMA", title="Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, title="StdDev", minval=0.001, maxval=50)

ma(source, length, _type) =>


switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

basis = ma(src, length, maType)


dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, title="Offset", minval = -500, maxval = 500)

plot(basis, title="Basis", color=#FF6D00, offset = offset)


p1 = plot(upper, title="Upper", color=#2962FF, offset = offset)
p2 = plot(lower, title="Lower", color=#2962FF, offset = offset)

// Buy Condition: Price crosses below the lower Bollinger Band


buyCondition = ta.crossover(close, lower)
strategy.entry("Buy", strategy.long, when = buyCondition)

// Sell Condition: Price crosses above the upper Bollinger Band


sellCondition = ta.crossunder(close, upper)
strategy.close("Buy", when = sellCondition)

You might also like