PM RTH AH VWAPs [vnhilton]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vnhilton

//@version=5
indicator("PM RTH AH VWAPs [vnhilton]", "PM RTH AH VWAPs", true)

//Parameters
src     = input(hlc3, "Source For VWAP")

//PM VWAP
vwap    = ta.vwap(src, timeframe.change("D"))
pmVWAP  = request.security(ticker.modify(syminfo.tickerid, session.extended), timeframe.period, vwap)

//RTH VWAP
vwapRTH = ta.vwap(src, session.isfirstbar_regular)

//AH VWAP
var float vwapSum        = na
var float volumeSum      = na
var bool  sessionStarted = false

if time(timeframe.period, "1600-2000", syminfo.timezone)
    if not sessionStarted
        vwapSum        := src * volume
        volumeSum      := volume
        sessionStarted := true
    else
        vwapSum        := vwapSum[1] + src * volume
        volumeSum      := volumeSum[1] + volume
else
    sessionStarted     := false

vwapAH = volumeSum != 0 ? vwapSum / volumeSum : na

//Plots
pmPlot  = plot(session.ispremarket  ? pmVWAP  : na, "PM VWAP",  color.new(#002652, 0), style=plot.style_linebr)
rthPlot = plot(session.ismarket     ? vwapRTH : na, "RTH VWAP", color.new(#002652, 0), style=plot.style_linebr)
ahPlot  = plot(session.ispostmarket ? vwapAH  : na, "AH VWAP",  color.new(#002652, 0), style=plot.style_linebr)