Price Weighted Volume MA (PWVMA)
// 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("Price Weighted Volume MA", "PWVMA", false, format.volume, explicit_plot_zorder = true)

vma(length = 9, reset = false)=>
    float price = math.sum(close, length)
    float vol   = math.sum(volume * close, length)
    var float counter = na
    counter := session.isfirstbar ? 1 : counter[1] + 1
    var float pri  = na
    var float volu = na
    pri := na(pri[1]) or session.isfirstbar ? close : nz(pri[1]) + close
    volu := na(volu[1]) or session.isfirstbar ? volume * close : volume * close + nz(volu[1])
    reset ? volu/pri : vol/price

evma(length = 9, reset = false)=>

    alpha = 2 / (length + 1)

    var float smoothed = na
    var float price = na
    var float counter = na
    counter := session.isfirstbar ? 1 : counter[1] + 1
    Alpha = reset ? (session.isfirstbar ? 1 : 2 / (counter + 1) ) : alpha
    price := na(price[1]) or (reset and session.isfirstbar) ? close : Alpha * close + (1 - Alpha) * nz(price[1])
    smoothed := na(smoothed[1]) or (reset and session.isfirstbar) ? volume * close : Alpha * (volume * close) + (1 - Alpha) * nz(smoothed[1])
    out = smoothed/price

select = input.string("VMA", "Select Style", ["VMA","EVMA"])
length = input.int(20, "Length", 2)
reset  = input.bool(false, "Session Weighting")

ma()=>
    switch select
        "VMA"  => vma(length, reset)
        "EVMA" => evma(length, reset)

plot(volume, "Volume", open < close ? color.new(#26a69a, 30) : color.new(#ef5350, 30), style = plot.style_columns)
plot(ma(), "Moving Average", color.blue, 2)
