TBM VWAP Bands Style Setup
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5

indicator(title='VWAP', overlay=true)

getVWAP(x) =>
    float p = na
    float vol = na
    float sn = na
    float lastv = na
    float laststd = na
    newSession = ta.change(request.security(syminfo.tickerid, x, time, lookahead=barmerge.lookahead_on)) ? 1 : 0
    p := newSession ? hlc3 * volume : nz(p[1]) + hlc3 * volume
    vol := newSession ? volume : nz(vol[1]) + volume
    v = p / vol
    sn := newSession ? 0 : nz(sn[1]) + volume * (hlc3 - nz(v[1])) * (hlc3 - v)
    std = math.sqrt(sn / vol)
    lastv := newSession == 1 ? v[1] : lastv[1]
    laststd := newSession == 1 ? std[1] : laststd[1]
    [v, std, lastv, laststd]


// Inputs
period = input.string('1D', title='Time segmented VWAP Period', options=['1D', 'Custom'])
custom_period = input('10D', title='Time segmented VWAP Custom Period')
period_out = period == 'Custom' ? custom_period : period

b1_t = input.float(1.0, title='Band 1 multiplier', step=0.1)
b2_t = input.float(2.0, title='Band 2 multiplier', step=0.1)
b3_t = input.float(3.0, title='Band 3 multiplier', step=0.1)
b4_t = input.float(1.5, title='Band 4 multiplier', step=0.1)

// Calcs

[vwap_t, std_t, vwap_prev, std_t_prev] = getVWAP(period_out)

// Plots

//VWAPs

plot(vwap_t, title='VWAP', color=color.rgb(235, 204, 28), linewidth=1)

//BANDs

// Time Segmented VWAP

plot(vwap_t + b1_t * std_t, title='ST DEV 1', color=color.rgb(118, 21, 156), linewidth=1)
plot(vwap_t - b1_t * std_t, title='ST DEV 1', color=color.rgb(118, 21, 156), linewidth=1)
plot(vwap_t + b2_t * std_t, title='ST DEV 2', color=color.rgb(0, 134, 161), linewidth=1)
plot(vwap_t - b2_t * std_t, title='ST DEV 2', color=color.rgb(0, 134, 161), linewidth=1)
plot(vwap_t + b3_t * std_t, title='ST DEV 3', color=color.rgb(232, 27, 1), linewidth=1)
plot(vwap_t - b3_t * std_t, title='ST DEV 3', color=color.rgb(232, 27, 1), linewidth=1)
plot(vwap_t + b4_t * std_t, title='ST DEV 4', color=color.new(color.rgb(216, 113, 1), 70), linewidth=1)
plot(vwap_t - b4_t * std_t, title='ST DEV 4', color=color.new(color.rgb(216, 113, 1), 70), linewidth=1)

