4 Anchored VWAP
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © raviudal

//@version=5
indicator("4 Anchored VWAP", overlay=true)

//==============================================================================================AVWAP1
 
src = input.source(hlc3, "Source")
startCalculationDate1 = input.time(timestamp("17 Mar 2020"), "Drag to move date")
vwap_calc1() =>
    var srcVolArray = array.new_float(na)
    var volArray = array.new_float(na)
    if startCalculationDate1 <= time
        array.push(srcVolArray, src*volume)
        array.push(volArray, volume)
    else
        array.clear(srcVolArray), array.clear(volArray)
    array.sum(srcVolArray)/array.sum(volArray)
anchoredVwap1 = vwap_calc1()
plot(anchoredVwap1, "Green AVWAP line", linewidth=2, color=color.green)

//==============================================================================================AVWAP2
 
startCalculationDate2 = input.time(timestamp("27 Oct 2008"), "Drag to move date" )
vwap_calc2() =>
    var srcVolArray = array.new_float(na)
    var volArray = array.new_float(na)
    if startCalculationDate2 <= time
        array.push(srcVolArray, src*volume)
        array.push(volArray, volume)
    else
        array.clear(srcVolArray), array.clear(volArray)
    array.sum(srcVolArray)/array.sum(volArray)
anchoredVwap2 = vwap_calc2()
plot(anchoredVwap2, "Blue AVWAP line", linewidth=2, color=color.blue)


//==============================================================================================AVWAP2
 
startCalculationDate3 = input.time(timestamp("22 Feb 2016"), "Drag to move date" )
vwap_calc3() =>
    var srcVolArray = array.new_float(na)
    var volArray = array.new_float(na)
    if startCalculationDate3 <= time
        array.push(srcVolArray, src*volume)
        array.push(volArray, volume)
    else
        array.clear(srcVolArray), array.clear(volArray)
    array.sum(srcVolArray)/array.sum(volArray)
anchoredVwap3 = vwap_calc3()
plot(anchoredVwap3, "Red AVWAP line", linewidth=2, color=color.red)


//==============================================================================================AVWAP2
 
startCalculationDate4 = input.time(timestamp("26 Oct 2020"), "Drag to move date" )
vwap_calc4() =>
    var srcVolArray = array.new_float(na)
    var volArray = array.new_float(na)
    if startCalculationDate4 <= time
        array.push(srcVolArray, src*volume)
        array.push(volArray, volume)
    else
        array.clear(srcVolArray), array.clear(volArray)
    array.sum(srcVolArray)/array.sum(volArray)
anchoredVwap4 = vwap_calc4()
plot(anchoredVwap4, "Black AVWAP line", linewidth=2, color=color.black)



