Volume Weighted Bollinger Bands Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ankit_1618

//@version=4
strategy("Volume Weighted Bollinger Bands Strategy", overlay=true)

src = input(close, title="Source")
length = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")

ema8 = ema(src, 8)
ema21 = ema(src, 21)
ema55 = ema(src, 55)
ema233 = ema(src, 233)
_vwap = vwap

average_weighting = (ema8 + ema21 + ema55 + ema233 + _vwap) / 5


basis = sma(average_weighting, length)
dev = mult * stdev(average_weighting, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=#198787, transp=95)

condition_long = close > upper and close[1] > upper
condition_short = close< lower and close[1] < lower

if (condition_long)
    strategy.entry("Long", strategy.long)

if (condition_short)
    strategy.entry("Short", strategy.short)
    
strategy.close("Long", when = condition_short )
strategy.close("Short", when =  condition_long )



