VWAP Open Session Anchored by Hampeh
// 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("VWAP Open Session Anchored by Hampeh", "VWAP OPen Session", true)

// CONSTANTS 
// COLORS
color night_color = #8E44AD
color evening_color = #4469ad
color morning_color = #44ad5b

// INPUTS
float       source      = input.source  (hlc3,    "Source", tooltip="", inline="",  group="Volume Weighted Average Price")
int         offset      = input.int     (0,       "Offset", tooltip="", inline="",  group="Volume Weighted Average Price")
bool        bands       = input.bool    (false,   "Band Multiplier", tooltip="", inline="0", group="Volume Weighted Average Price")
float       multiplier  = input.float   (1,       "", tooltip="", inline="0", group="Volume Weighted Average Price")

bool        morning      = input.bool    (true,    "Morning", tooltip="", inline="0", group="Session")
color       morningColor = input.color   (morning_color,   "", tooltip="", inline="0", group="Session")
bool        evening       = input.bool    (true,    "Evening", tooltip="", inline="1", group="Session")
color       eveningColor  = input.color   (evening_color,   "", tooltip="", inline="1", group="Session")
bool        night      = input.bool    (true,    "Night", tooltip="", inline="0", group="Session") 
color       nightColor = input.color   (night_color,   "", tooltip="", inline="0", group="Session")

// CALCULATIONS
morningSession_full = input.session('1030-1230', 'Morning Session')
eveningSession_full = input.session('1430-1800', 'Evening Session')
nightSession_full = input.session('2100-2330', 'Night Session')

morningSession = time(timeframe.period, morningSession_full + ':1234567')
eveningSession = time(timeframe.period, eveningSession_full + ':1234567')
nightSession = time(timeframe.period, nightSession_full + ':1234567')

[morningVwap , morningUpper , morningLower ] = ta.vwap(source, morningSession [0] and not morningSession [1], multiplier)
[eveningVwap  , eveningUpper  , eveningLower  ] = ta.vwap(source, eveningSession  [0] and not eveningSession  [1], multiplier)
[nightVwap , nightUpper , nightLower ] = ta.vwap(source, nightSession [0] and not nightSession [1], multiplier)

// PLOTS
plotMorningUpper = plot(morning  and bands and morningSession  ? morningUpper  : na, "Morning Session VWAP Upper Band",   morningColor,  1, plot.style_linebr, false, 0, offset)
plotMorningVwap  = plot(morning            and morningSession  ? morningVwap   : na, "Morning Session VWAP",              morningColor,  2, plot.style_linebr, false, 0, offset)
plotMorningLower = plot(morning  and bands and morningSession  ? morningLower  : na, "Morning Session VWAP Lower Band",   morningColor,  1, plot.style_linebr, false, 0, offset)
fill(plotMorningUpper, plotMorningLower, color.new(morningColor, 95))

plotEveningUpper  = plot(evening   and bands and eveningSession   ? eveningUpper   : na, "Evening Session VWAP Upper Band",    eveningColor,   1, plot.style_linebr, false, 0, offset)
plotEveningVwap   = plot(evening             and eveningSession   ? eveningVwap    : na, "Evening Session VWAP",               eveningColor,   2, plot.style_linebr, false, 0, offset)
plotEveningLower  = plot(evening   and bands and eveningSession   ? eveningLower   : na, "Evening Session VWAP Lower Band",    eveningColor,   1, plot.style_linebr, false, 0, offset)
fill(plotEveningUpper, plotEveningLower, color.new(eveningColor, 95))

plotNightUpper = plot(night  and bands and nightSession  ? nightUpper  : na, "Night Session VWAP Upper Band",   nightColor,  1, plot.style_linebr, false, 0, offset)
plotNightVwap  = plot(night            and nightSession  ? nightVwap   : na, "Night Session VWAP",              nightColor,  2, plot.style_linebr, false, 0, offset)
plotNightLower = plot(night  and bands and nightSession  ? nightLower  : na, "Night Session VWAP Lower Band",   nightColor,  1, plot.style_linebr, false, 0, offset)
fill(plotNightUpper, plotNightLower, color.new(nightColor, 95))