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

//@version=5
indicator("Multiple Non-Anchored VWAP", overlay=true, shorttitle="VWAP")

show_vwap_1                         = input.bool(defval=true, title='Show VWAP #1', group='Display VWAP')
show_vwap_2                         = input.bool(defval=false, title='Show VWAP #2', group='Display VWAP')
show_vwap_3                         = input.bool(defval=false, title='Show VWAP #3', group='Display VWAP')
show_vwap_4                         = input.bool(defval=false, title='Show VWAP #4', group='Display VWAP')
show_vwap_5                         = input.bool(defval=false, title='Show VWAP #5', group='Display VWAP')

input_stdev_1                       = input.bool(defval=true, title='Show StDev #1', group='Display StDev')
input_stdev_2                       = input.bool(defval=true, title='Show StDev #2', group='Display StDev')
input_stdev_3                       = input.bool(defval=true, title='Show StDev #3', group='Display StDev')

cumulativePeriod_1                  = input.int(21, "Period #1", step=1, group='Choose Period for VWAP', minval=1)
cumulativePeriod_2                  = input.int(63, "Period #2", step=1, group='Choose Period for VWAP', minval=1)
cumulativePeriod_3                  = input.int(126, "Period #3", step=1, group='Choose Period for VWAP', minval=1)
cumulativePeriod_4                  = input.int(252, "Period #4", step=1, group='Choose Period for VWAP', minval=1)
cumulativePeriod_5                  = input.int(756, "Period #5", step=1, group='Choose Period for VWAP', minval=1)

stdev_band_1                        = input.float(defval=1.0, title="StDev Band #1", step=0.1, group="Choose # of StDev's", minval=0.1)
stdev_band_2                        = input.float(defval=2.0, title="StDev Band #2", step=0.1, group="Choose # of StDev's", minval=0.1)
stdev_band_3                        = input.float(defval=3.0, title="StDev Band #3", step=0.1, group="Choose # of StDev's", minval=0.1)



typicalPrice                        = (high + low + close) / 3
typicalPriceVolume                  = typicalPrice * volume

cumulativeTypicalPriceVolume_1      = math.sum(typicalPriceVolume, cumulativePeriod_1)
cumulativeVolume_1                  = math.sum(volume, cumulativePeriod_1)
vwapValue_1                         = cumulativeTypicalPriceVolume_1 / cumulativeVolume_1
vwap_hi_1_1                         = vwapValue_1 + (stdev_band_1 * ta.stdev(vwapValue_1, cumulativePeriod_1))
vwap_lo_1_1                         = vwapValue_1 - (stdev_band_1 * ta.stdev(vwapValue_1, cumulativePeriod_1))
vwap_hi_1_2                         = vwapValue_1 + (stdev_band_2 * ta.stdev(vwapValue_1, cumulativePeriod_1))
vwap_lo_1_2                         = vwapValue_1 - (stdev_band_2 * ta.stdev(vwapValue_1, cumulativePeriod_1))
vwap_hi_1_3                         = vwapValue_1 + (stdev_band_3 * ta.stdev(vwapValue_1, cumulativePeriod_1))
vwap_lo_1_3                         = vwapValue_1 - (stdev_band_3 * ta.stdev(vwapValue_1, cumulativePeriod_1))

cumulativeTypicalPriceVolume_2      = math.sum(typicalPriceVolume, cumulativePeriod_2)
cumulativeVolume_2                  = math.sum(volume, cumulativePeriod_2)
vwapValue_2                         = cumulativeTypicalPriceVolume_2 / cumulativeVolume_2
vwap_hi_2_1                         = vwapValue_2 + (stdev_band_1 * ta.stdev(vwapValue_2, cumulativePeriod_2))
vwap_lo_2_1                         = vwapValue_2 - (stdev_band_1 * ta.stdev(vwapValue_2, cumulativePeriod_2))
vwap_hi_2_2                         = vwapValue_2 + (stdev_band_2 * ta.stdev(vwapValue_2, cumulativePeriod_2))
vwap_lo_2_2                         = vwapValue_2 - (stdev_band_2 * ta.stdev(vwapValue_2, cumulativePeriod_2))
vwap_hi_2_3                         = vwapValue_2 + (stdev_band_3 * ta.stdev(vwapValue_2, cumulativePeriod_2))
vwap_lo_2_3                         = vwapValue_2 - (stdev_band_3 * ta.stdev(vwapValue_2, cumulativePeriod_2))

cumulativeTypicalPriceVolume_3      = math.sum(typicalPriceVolume, cumulativePeriod_3)
cumulativeVolume_3                  = math.sum(volume, cumulativePeriod_3)
vwapValue_3                         = cumulativeTypicalPriceVolume_3 / cumulativeVolume_3
vwap_hi_3_1                         = vwapValue_3 + (stdev_band_1 * ta.stdev(vwapValue_3, cumulativePeriod_3))
vwap_lo_3_1                         = vwapValue_3 - (stdev_band_1 * ta.stdev(vwapValue_3, cumulativePeriod_3))
vwap_hi_3_2                         = vwapValue_3 + (stdev_band_2 * ta.stdev(vwapValue_3, cumulativePeriod_3))
vwap_lo_3_2                         = vwapValue_3 - (stdev_band_2 * ta.stdev(vwapValue_3, cumulativePeriod_3))
vwap_hi_3_3                         = vwapValue_3 + (stdev_band_3 * ta.stdev(vwapValue_3, cumulativePeriod_3))
vwap_lo_3_3                         = vwapValue_3 - (stdev_band_3 * ta.stdev(vwapValue_3, cumulativePeriod_3))

cumulativeTypicalPriceVolume_4      = math.sum(typicalPriceVolume, cumulativePeriod_4)
cumulativeVolume_4                  = math.sum(volume, cumulativePeriod_4)
vwapValue_4                         = cumulativeTypicalPriceVolume_4 / cumulativeVolume_4
vwap_hi_4_1                         = vwapValue_4 + (stdev_band_1 * ta.stdev(vwapValue_4, cumulativePeriod_4))
vwap_lo_4_1                         = vwapValue_4 - (stdev_band_1 * ta.stdev(vwapValue_4, cumulativePeriod_4))
vwap_hi_4_2                         = vwapValue_4 + (stdev_band_2 * ta.stdev(vwapValue_4, cumulativePeriod_4))
vwap_lo_4_2                         = vwapValue_4 - (stdev_band_2 * ta.stdev(vwapValue_4, cumulativePeriod_4))
vwap_hi_4_3                         = vwapValue_4 + (stdev_band_3 * ta.stdev(vwapValue_4, cumulativePeriod_4))
vwap_lo_4_3                         = vwapValue_4 - (stdev_band_3 * ta.stdev(vwapValue_4, cumulativePeriod_4))

cumulativeTypicalPriceVolume_5      = math.sum(typicalPriceVolume, cumulativePeriod_5)
cumulativeVolume_5                  = math.sum(volume, cumulativePeriod_5)
vwapValue_5                         = cumulativeTypicalPriceVolume_5 / cumulativeVolume_5
vwap_hi_5_1                         = vwapValue_5 + (stdev_band_1 * ta.stdev(vwapValue_5, cumulativePeriod_5))
vwap_lo_5_1                         = vwapValue_5 - (stdev_band_1 * ta.stdev(vwapValue_5, cumulativePeriod_5))
vwap_hi_5_2                         = vwapValue_5 + (stdev_band_2 * ta.stdev(vwapValue_5, cumulativePeriod_5))
vwap_lo_5_2                         = vwapValue_5 - (stdev_band_2 * ta.stdev(vwapValue_5, cumulativePeriod_5))
vwap_hi_5_3                         = vwapValue_5 + (stdev_band_3 * ta.stdev(vwapValue_5, cumulativePeriod_5))
vwap_lo_5_3                         = vwapValue_5 - (stdev_band_3 * ta.stdev(vwapValue_5, cumulativePeriod_5))

plot(show_vwap_1 ? vwapValue_1 : na, title='VWAP #1', color=color.teal)
plot(show_vwap_1 and input_stdev_1 ? vwap_hi_1_1 : na, title='VWAP #1 + Stdev 1', color=color.teal, linewidth=1)
plot(show_vwap_1 and input_stdev_1 ? vwap_lo_1_1 : na, title='VWAP #1 - Stdev 1', color=color.teal, linewidth=1)
plot(show_vwap_1 and input_stdev_2 ? vwap_hi_1_2 : na, title='VWAP #1 + Stdev 2', color=color.teal, linewidth=2)
plot(show_vwap_1 and input_stdev_2 ? vwap_lo_1_2 : na, title='VWAP #1 + Stdev 2', color=color.teal, linewidth=2)
plot(show_vwap_1 and input_stdev_3 ? vwap_hi_1_3 : na, title='VWAP #1 + Stdev 3', color=color.teal, linewidth=3)
plot(show_vwap_1 and input_stdev_3 ? vwap_lo_1_3 : na, title='VWAP #1 + Stdev 3', color=color.teal, linewidth=3)

plot(show_vwap_2 ? vwapValue_2 : na, title='VWAP #2', color=color.blue)
plot(show_vwap_2 and input_stdev_1 ? vwap_hi_2_1 : na, title='VWAP #2 + Stdev 1', color=color.blue, linewidth=1)
plot(show_vwap_2 and input_stdev_1 ? vwap_lo_2_1 : na, title='VWAP #2 - Stdev 1', color=color.blue, linewidth=1)
plot(show_vwap_2 and input_stdev_2 ? vwap_hi_2_2 : na, title='VWAP #2 + Stdev 2', color=color.blue, linewidth=2)
plot(show_vwap_2 and input_stdev_2 ? vwap_lo_2_2 : na, title='VWAP #2 + Stdev 2', color=color.blue, linewidth=2)
plot(show_vwap_2 and input_stdev_3 ? vwap_hi_2_3 : na, title='VWAP #2 + Stdev 3', color=color.blue, linewidth=3)
plot(show_vwap_2 and input_stdev_3 ? vwap_lo_2_3 : na, title='VWAP #2 + Stdev 3', color=color.blue, linewidth=3)

plot(show_vwap_3 ? vwapValue_3 : na, title='VWAP #3', color=color.purple)
plot(show_vwap_3 and input_stdev_1 ? vwap_hi_3_1 : na, title='VWAP #3 + Stdev 1', color=color.purple, linewidth=1)
plot(show_vwap_3 and input_stdev_1 ? vwap_lo_3_1 : na, title='VWAP #3 - Stdev 1', color=color.purple, linewidth=1)
plot(show_vwap_3 and input_stdev_2 ? vwap_hi_3_2 : na, title='VWAP #3 + Stdev 2', color=color.purple, linewidth=2)
plot(show_vwap_3 and input_stdev_2 ? vwap_lo_3_2 : na, title='VWAP #3 + Stdev 2', color=color.purple, linewidth=2)
plot(show_vwap_3 and input_stdev_3 ? vwap_hi_3_3 : na, title='VWAP #3 + Stdev 3', color=color.purple, linewidth=3)
plot(show_vwap_3 and input_stdev_3 ? vwap_lo_3_3 : na, title='VWAP #3 + Stdev 3', color=color.purple, linewidth=3)

plot(show_vwap_4 ? vwapValue_4 : na, title='VWAP #4', color=color.red)
plot(show_vwap_4 and input_stdev_1 ? vwap_hi_4_1 : na, title='VWAP #4 + Stdev 1', color=color.red, linewidth=1)
plot(show_vwap_4 and input_stdev_1 ? vwap_lo_4_1 : na, title='VWAP #4 - Stdev 1', color=color.red, linewidth=1)
plot(show_vwap_4 and input_stdev_2 ? vwap_hi_4_2 : na, title='VWAP #4 + Stdev 2', color=color.red, linewidth=2)
plot(show_vwap_4 and input_stdev_2 ? vwap_lo_4_2 : na, title='VWAP #4 + Stdev 2', color=color.red, linewidth=2)
plot(show_vwap_4 and input_stdev_3 ? vwap_hi_4_3 : na, title='VWAP #4 + Stdev 3', color=color.red, linewidth=3)
plot(show_vwap_4 and input_stdev_3 ? vwap_lo_4_3 : na, title='VWAP #4 + Stdev 3', color=color.red, linewidth=3)

plot(show_vwap_5 ? vwapValue_5 : na, title='VWAP #5', color=color.green)
plot(show_vwap_5 and input_stdev_1 ? vwap_hi_5_1 : na, title='VWAP #5 + Stdev 1', color=color.green, linewidth=1)
plot(show_vwap_5 and input_stdev_1 ? vwap_lo_5_1 : na, title='VWAP #5 - Stdev 1', color=color.green, linewidth=1)
plot(show_vwap_5 and input_stdev_2 ? vwap_hi_5_2 : na, title='VWAP #5 + Stdev 2', color=color.green, linewidth=2)
plot(show_vwap_5 and input_stdev_2 ? vwap_lo_5_2 : na, title='VWAP #5 + Stdev 2', color=color.green, linewidth=2)
plot(show_vwap_5 and input_stdev_3 ? vwap_hi_5_3 : na, title='VWAP #5 + Stdev 3', color=color.green, linewidth=3)
plot(show_vwap_5 and input_stdev_3 ? vwap_lo_5_3 : na, title='VWAP #5 + Stdev 3', color=color.green, linewidth=3)

//
//
//