VWAP, AVWAP and MVWAP - Omkar Banne
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OmkarBanne

//@version=5
indicator("VWAP, AVWAP and MVWAP - Omkar Banne", overlay = true)


avwap_group ='-----------------AVWAP settings-----------------'
avwap_on = input(true, "Plot AVWAP?", group=avwap_group, inline = '1')
avwap_color = input(color.new(color.white,1), group = avwap_group, inline = "2")

avwap_year = input(2023, title="Year", group = avwap_group, inline = "3")
avwap_month = input(4, title="Month", group = avwap_group, inline = "3")
avwap_day = input(28, title="Day", group = avwap_group, inline = "3")


anchor_date = timestamp(avwap_year,avwap_month,avwap_day)
anchor_range = time >= anchor_date and time[1] < anchor_date

float sum_pricexvolume = na
float sum_volume = na

sum_pricexvolume := anchor_range ? hlc3 * volume : sum_volume[1] + (hlc3*volume)
sum_volume := anchor_range ? volume : sum_volume[1] + volume

avwap = sum_pricexvolume / sum_volume


mvwap_group ='-----------------MVWAP settings-----------------'
mvwap_on = input(true, "Plot MVWAP?", group=mvwap_group, inline = '1')

mvwap_length = input(10, "Moving VWAP length", group = mvwap_group, inline = "2")
mvwap_color = input(color.new(color.blue,1), group = mvwap_group, inline = "2")


vwap_group ='-----------------VWAP settings-----------------'

vwap_on = input(true, "Plot VWAP?", group=vwap_group, inline = '1')
vwap_color = input(color.new(color.red,1), group = vwap_group, inline = "2")
vwap_source = input(hlc3, 'VWAP Source', group = vwap_group, inline = "2")


vwap = ta.vwap(vwap_source)

mvwap = ta.ema(vwap,mvwap_length)


//--------------PLOT--------------------
plot(avwap_on? avwap : na,  linewidth = 2, color=avwap_color)
plot(vwap_on? vwap : na, style = plot.style_line, linewidth = 1, color = vwap_color)
plot(mvwap_on? mvwap : na, linewidth = 2, color= mvwap_color)

