VWAP Market Session Anchored
// 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 Market Session Anchored", "VWAP Market Session Anchored", true)

// CONSTANTS 
// COLORS
color RED_L = #E74C3C, color RED_M = #B03A2E, color RED_D = #78281F
color ORA_L = #F0B27A, color ORA_M = #E67E22, color ORA_D = #AF601A
color YEL_L = #F7DC6F, color YEL_M = #F1C40F, color YEL_D = #B7950B
color GRE_L = #2ECC71, color GRE_M = #239B56, color GRE_D = #186A3B
color BLU_L = #85C1E9, color BLU_M = #3498DB, color BLU_D = #2874A6
color PUR_L = #8E44AD, color PUR_M = #6C3483, color PUR_D = #4A235A
color GRA_L = #BDC3C7, color GRA_M = #909497, color GRA_D = #626567
color WHI   = #FFFFFF, color BLA   = #000000, color CLE   = #00000000

// 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        sydney      = input.bool    (true,    "Sydney  ",           tooltip="", inline="0", group="Session")
color       sydneyColor = input.color   (GRE_M,   "",                   tooltip="", inline="0", group="Session")
bool        tokyo       = input.bool    (true,    "Tokyo    ",          tooltip="", inline="1", group="Session")
color       tokyoColor  = input.color   (ORA_M,   "",                   tooltip="", inline="1", group="Session")
bool        london      = input.bool    (true,    "London  ",           tooltip="", inline="0", group="Session") 
color       londonColor = input.color   (BLU_M,   "",                   tooltip="", inline="0", group="Session")
bool        newYork     = input.bool    (true,    "New York  ",         tooltip="", inline="1", group="Session")
color       newYorkColor= input.color   (RED_M,   "",                   tooltip="", inline="1", group="Session")
bool        custom      = input.bool    (false,   "Custom    ",         tooltip="", inline="2", group="Session")
color       customColor = input.color   (PUR_M,   "",                   tooltip="", inline="2", group="Session")
int         customStart = input.int     (8,       "UTC", 0, 23, 1,      tooltip="", inline="2", group="Session")
int         customEnd   = input.int     (13,      "-",   0, 23, 1,      tooltip="", inline="2", group="Session")

// CALCULATIONS
utcTime = hour(time(timeframe.period, '0000-2400', 'UTC'), 'UTC')

sydneySession  = utcTime >= 22 or  utcTime <=  5
tokyoSession   = utcTime >=  0 and utcTime <=  8
londonSession  = utcTime >=  7 and utcTime <= 15
newYorkSession = utcTime >= 13 and utcTime <= 21
customSession  = utcTime >= customStart and utcTime <= customEnd

[sydneyVwap , sydneyUpper , sydneyLower ] = ta.vwap(source, sydneySession [0] and not sydneySession [1], multiplier)
[tokyoVwap  , tokyoUpper  , tokyoLower  ] = ta.vwap(source, tokyoSession  [0] and not tokyoSession  [1], multiplier)
[londonVwap , londonUpper , londonLower ] = ta.vwap(source, londonSession [0] and not londonSession [1], multiplier)
[newYorkVwap, newYorkUpper, newYorkLower] = ta.vwap(source, newYorkSession[0] and not newYorkSession[1], multiplier)
[customVwap , customUpper , customLower ] = ta.vwap(source, customSession [0] and not customSession [1], multiplier)

// PLOTS
plotSydneyUpper = plot(sydney  and bands and sydneySession  ? sydneyUpper  : na, "Sydney Session VWAP Upper Band",   sydneyColor,  1, plot.style_linebr, false, 0, offset)
plotSydneyVwap  = plot(sydney            and sydneySession  ? sydneyVwap   : na, "Sydney Session VWAP",              sydneyColor,  1, plot.style_linebr, false, 0, offset)
plotSydneyLower = plot(sydney  and bands and sydneySession  ? sydneyLower  : na, "Sydney Session VWAP Lower Band",   sydneyColor,  1, plot.style_linebr, false, 0, offset)
fill(plotSydneyUpper, plotSydneyLower, color.new(sydneyColor, 95))

plotTokyoUpper  = plot(tokyo   and bands and tokyoSession   ? tokyoUpper   : na, "Tokyo Session VWAP Upper Band",    tokyoColor,   1, plot.style_linebr, false, 0, offset)
plotTokyoVwap   = plot(tokyo             and tokyoSession   ? tokyoVwap    : na, "Tokyo Session VWAP",               tokyoColor,   1, plot.style_linebr, false, 0, offset)
plotTokyoLower  = plot(tokyo   and bands and tokyoSession   ? tokyoLower   : na, "Tokyo Session VWAP Lower Band",    tokyoColor,   1, plot.style_linebr, false, 0, offset)
fill(plotTokyoUpper, plotTokyoLower, color.new(tokyoColor, 95))

plotLondonUpper = plot(london  and bands and londonSession  ? londonUpper  : na, "London Session VWAP Upper Band",   londonColor,  1, plot.style_linebr, false, 0, offset)
plotLondonVwap  = plot(london            and londonSession  ? londonVwap   : na, "London Session VWAP",              londonColor,  1, plot.style_linebr, false, 0, offset)
plotLondonLower = plot(london  and bands and londonSession  ? londonLower  : na, "London Session VWAP Lower Band",   londonColor,  1, plot.style_linebr, false, 0, offset)
fill(plotLondonUpper, plotLondonLower, color.new(londonColor, 95))

plotNewYorkUpper= plot(newYork and bands and newYorkSession ? newYorkUpper : na, "New York Session VWAP Upper Band", newYorkColor, 1, plot.style_linebr, false, 0, offset)
plotNewYorkVwap = plot(newYork           and newYorkSession ? newYorkVwap  : na, "New York Session VWAP",            newYorkColor, 1, plot.style_linebr, false, 0, offset)
plotNewYorkLower= plot(newYork and bands and newYorkSession ? newYorkLower : na, "New York Session VWAP Lower Band", newYorkColor, 1, plot.style_linebr, false, 0, offset)
fill(plotNewYorkUpper, plotNewYorkLower, color.new(newYorkColor, 95))

plotcustomUpper = plot(custom  and bands and customSession  ? customUpper  : na, "Custom Session VWAP Upper Band",   customColor,  1, plot.style_linebr, false, 0, offset)
plotcustomVwap  = plot(custom            and customSession  ? customVwap   : na, "Custom Session VWAP",              customColor,  1, plot.style_linebr, false, 0, offset)
plotcustomLower = plot(custom  and bands and customSession  ? customLower  : na, "Custom Session VWAP Lower Band",   customColor,  1, plot.style_linebr, false, 0, offset)
fill(plotcustomUpper, plotcustomLower, color.new(customColor, 95))