wnG - VWAP MOD 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wingoutoulouse

//@version=5

indicator(title="wnG - VWAP", shorttitle="wnG - VWAP [p]", overlay=true)

// Inputs
//ATR_vs_TR = input.bool(true,title="Progressive Daily TR ?")
Period = input.string("D",title="Period", options=["240", "D", "W", "M"])
vwap_src = input.source(hlc3, title="Source")
ATR_vs_TR = input.string("Progressive Daily",title="ATR Type", options=["Progressive Daily", "24 Hours rolling ATR"])
vwap_show = input.bool(true, title='Show VWAP ?', inline="line 0")
band_show = input.bool(true, title='Show BAND ?', inline="line 0")


vwap1 = input.float(title='VWAP 1', defval=1, step=0.5, inline="line 1")
vwap2 = input.float(title='VWAP 2', defval=-1, step=0.5, inline="line 1")
vwap3 = input.float(title='VWAP 3', defval=2, step=0.5, inline="line 2")
vwap4 = input.float(title='VWAP 4', defval=-2, step=0.5, inline="line 2")
vwap5 = input.float(title='VWAP 5', defval=3, step=0.5, inline="line 3")
vwap6 = input.float(title='VWAP 6', defval=-3, step=0.5, inline="line 3")


start = request.security(syminfo.tickerid, "D", time,lookahead=barmerge.lookahead_on)

newSession = start > start[1] ? 1 : 0

vwapsum = 0.0
volumesum = 0.0
vwapsum := newSession[1] ? vwap_src * volume : vwapsum[1] + vwap_src * volume
volumesum := newSession[1] ? volume : volumesum[1] + volume
//vwap_now = barstate.isconfirmed ? vwapsum/volumesum : na
vwap_now = vwapsum/volumesum 

actual_TF = timeframe.in_seconds(timeframe.period)/60
length_ATR = 1440 / actual_TF
size_ATR = ta.atr(length_ATR)

var start_index = 0
start_index := newSession ? bar_index : start_index[1]
length_TR = bar_index - start_index == 0 ? 1440 / actual_TF : bar_index - start_index
true_range = ta.tr(true)

true_range_sum = 0.0
for i = 0 to length_TR-1
    true_range_sum += true_range[i] 
average_true_range = true_range_sum / length_TR


vwap_1 = ATR_vs_TR == "Progressive Daily" ? vwap_now + average_true_range * vwap1 : vwap_now + size_ATR * vwap1
vwap_2 = ATR_vs_TR == "Progressive Daily" ? vwap_now + average_true_range * vwap2 : vwap_now + size_ATR * vwap2
vwap_3 = ATR_vs_TR == "Progressive Daily" ? vwap_now + average_true_range * vwap3 : vwap_now + size_ATR * vwap3
vwap_4 = ATR_vs_TR == "Progressive Daily" ? vwap_now + average_true_range * vwap4 : vwap_now + size_ATR * vwap4
vwap_5 = ATR_vs_TR == "Progressive Daily" ? vwap_now + average_true_range * vwap5 : vwap_now + size_ATR * vwap5
vwap_6 = ATR_vs_TR == "Progressive Daily" ? vwap_now + average_true_range * vwap6 : vwap_now + size_ATR * vwap6

plot(vwap_show ? vwap_now : na, color=color.white, title='VWAP',linewidth=2)

plot_vwap1 = plot(band_show ? vwap_1 : na, color=color.gray, title='VWAP 1', linewidth=1)
plot_vwap2 = plot(band_show ? vwap_2 : na, color=color.gray, title='VWAP 2', linewidth=1)
plot_vwap3 = plot(band_show ? vwap_3 : na, color=color.gray, title='VWAP 3', linewidth=1) 
plot_vwap4 = plot(band_show ? vwap_4 : na, color=color.gray, title='VWAP 4', linewidth=1)
plot_vwap5 = plot(band_show ? vwap_5 : na, color=color.gray, title='VWAP 5', linewidth=1)
plot_vwap6 = plot(band_show ? vwap_6 : na, color=color.gray, title='VWAP 6', linewidth=1)

fill(plot_vwap4, plot_vwap6, color=color.new(color.lime,80))
fill(plot_vwap3, plot_vwap5, color=color.new(color.red,80))
