Volume Weighted Standard Deviation (VWSD)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("Volume Weighted Standard Deviation", overlay = true)

vstdev(source, length)=>
    mean_price = ta.sma(source, length)
    mean_volume = ta.sma(volume, length)

    squared_diff_price = math.sum(math.pow(source - mean_price, 2) * volume, length)

    vstdev = math.sqrt((squared_diff_price) / math.sum(volume, length))

source = input.source(close, "Source")
length = input.int(20, "Length", 1)
mult   = input.float(1.5, "Deviation", 0)

sma    = ta.sma(close, 20)
vstdev = vstdev(close, 20)

plot(sma)
plot(sma - vstdev * mult)
plot(sma + vstdev * mult)
