VOLD Ratio (Volume Difference Ratio) by Tenozen
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tenozen

//@version=5
indicator("VOLD Ratio",precision = 6)

is_new_time = ta.change(time("W"))
up_net_volume = close > open? volume: 0
down_net_volume = close < open? volume: 0

var float up_vol = na
var float down_vol = na

var float [] unv = array.new_float()
var float [] dnv = array.new_float()

if (is_new_time)
    up_vol := up_net_volume
    down_vol := down_net_volume
    array.push(unv, up_vol)
    array.push(dnv, down_vol)
else
    if (up_vol == up_vol)
        up_vol := up_net_volume
        array.push(unv, up_vol)
    if (down_vol == down_vol)
        down_vol := down_net_volume
        array.push(dnv, down_vol)

net_valup = array.sum(unv)
net_valdown = array.sum(dnv)

vold = net_valup/net_valdown

plot(vold, "VOLD Ratio", color.new(color.white, 50))

//Bollinger Bands
length = input.int(50, minval=1)
src = vold
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color.new(color.yellow, 50), offset = offset)
p1 = plot(upper, "Upper", color.new(color.white,50), offset = offset)
p2 = plot(lower, "Lower", color.new(color.white,50), offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))