Dollar Cost Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jocull

//@version=5
indicator("Dollar Cost Volume", shorttitle="DCV", format=format.volume)

source = input.source(hlc3, "Pricing Source")
invert = input.bool(false, "Invert price?")
maLen = input.int(24, "SMA Length")
stDevLen = input.int(200, "Std Dev Length")
stDevMulti = input.float(2, "Std Dev Multiplier")

vol = volume
cost = (invert ? (1 / source) : source) * vol
ma = ta.sma(cost, maLen)
upper = ma + (ta.stdev(cost, stDevLen) * stDevMulti)

riseColor = color.rgb(38, 166, 154, 50)
fallColor = color.rgb(239, 83, 80, 50)
riseOrFallColor = source[0] < source[1] ? fallColor : riseColor

plot(cost, style=plot.style_columns, color=riseOrFallColor, title="Dollar Cost Volume")
plot(ma, style=plot.style_line, color=color.blue, title="Average")
plot(upper, style=plot.style_line, color=color.red, title="Std Dev Band", display=display.none)
