rth vwap
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ldbc

//@version=4
study("rth vwap", overlay=true)

input_rth = input("0930-1600", type=input.session, title="Regular Session Time (EST)", tooltip="If you want to get full session (including overnight) high/low values, then change the regular session interval.  For example, on a 5-mninute chart, 1800-1655 will provide the high and low for the full daily session.")
rth_session = time("1440",str.format("{0}:23456", input_rth), "America/New_York")


// RTH High/Low

var float rth_vwap = na
var float rth_p = na
var float rth_vol = na

if rth_session
    if not rth_session[1]
        rth_p := hlc3 * volume
        rth_vol := volume
        rth_vwap := hlc3
    else
        rth_p := rth_p[1] + hlc3 * volume
        rth_vol := rth_vol[1] + volume
        rth_vwap := rth_p / rth_vol
else 
    rth_vwap := na


// Plots

rth_vwap_plot = plot(rth_session ? rth_vwap : na, title="rth_vwap", color = #00FFFFDD, linewidth=2, style=plot.style_linebr)