Kviatek - Multi Hour VWAP
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hundredtoamillion

//@version=5

indicator('Kviatek - Multi Hour VWAP', overlay=true, max_boxes_count = 500) 

resolution1 = input.timeframe("D", "VWAP resolution")
source      = input.source(ohlc4, "VWAP source")

session1    = input.session(defval = "0000-0000", title = "VWAP 1 Anchor")
session2    = input.session(defval = "0100-0000", title = "VWAP 2 Anchor")
session3    = input.session(defval = "0200-0000", title = "VWAP 3 Anchor")
session4    = input.session(defval = "0300-0000", title = "VWAP 4 Anchor")
session5    = input.session(defval = "0400-0000", title = "VWAP 4 Anchor")
session6    = input.session(defval = "0500-0000", title = "VWAP 4 Anchor")
session7    = input.session(defval = "0600-0000", title = "VWAP 4 Anchor")
session8    = input.session(defval = "0700-0000", title = "VWAP 4 Anchor")
session9    = input.session(defval = "0800-0000", title = "VWAP 4 Anchor")
session10   = input.session(defval = "0900-0000", title = "VWAP 4 Anchor")
session11   = input.session(defval = "1000-0000", title = "VWAP 4 Anchor")
session12   = input.session(defval = "1100-0000", title = "VWAP 4 Anchor")
session13   = input.session(defval = "1200-0000", title = "VWAP 4 Anchor")
session14   = input.session(defval = "1300-0000", title = "VWAP 4 Anchor")
session15   = input.session(defval = "1400-0000", title = "VWAP 4 Anchor")
session16   = input.session(defval = "1500-0000", title = "VWAP 4 Anchor")
session17   = input.session(defval = "1600-0000", title = "VWAP 4 Anchor")
session18   = input.session(defval = "1700-0000", title = "VWAP 4 Anchor")
session19   = input.session(defval = "1800-0000", title = "VWAP 4 Anchor")
session20   = input.session(defval = "1900-0000", title = "VWAP 4 Anchor")
session21   = input.session(defval = "2000-0000", title = "VWAP 4 Anchor")
session22   = input.session(defval = "2100-0000", title = "VWAP 4 Anchor")
session23   = input.session(defval = "2200-0000", title = "VWAP 4 Anchor")
session24   = input.session(defval = "2300-0000", title = "VWAP 4 Anchor")

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

H1 = time(resolution1, session1)
H2 = time(resolution1, session2)
H3 = time(resolution1, session3)
H4 = time(resolution1, session4)
H5 = time(resolution1, session5)
H6 = time(resolution1, session6)
H7 = time(resolution1, session7)
H8 = time(resolution1, session8)
H9 = time(resolution1, session9)
H10 = time(resolution1, session10)
H11 = time(resolution1, session11)
H12 = time(resolution1, session12)
H13 = time(resolution1, session13)
H14 = time(resolution1, session14)
H15 = time(resolution1, session15)
H16 = time(resolution1, session16)
H17 = time(resolution1, session17)
H18 = time(resolution1, session18)
H19 = time(resolution1, session19)
H20 = time(resolution1, session20)
H21 = time(resolution1, session21)
H22 = time(resolution1, session22)
H23 = time(resolution1, session23)
H24 = time(resolution1, session24)

open_bar(t) => na(t[1]) and not na(t) or t[1] < t ? 1 : 0

tf_switch1 = ta.change(open_bar(H1)) > 0
tf_switch2 = ta.change(open_bar(H2)) > 0
tf_switch3 = ta.change(open_bar(H3)) > 0
tf_switch4 = ta.change(open_bar(H4)) > 0
tf_switch5 = ta.change(open_bar(H5)) > 0
tf_switch6 = ta.change(open_bar(H6)) > 0
tf_switch7 = ta.change(open_bar(H7)) > 0
tf_switch8 = ta.change(open_bar(H8)) > 0
tf_switch9 = ta.change(open_bar(H9)) > 0
tf_switch10 = ta.change(open_bar(H10)) > 0
tf_switch11 = ta.change(open_bar(H11)) > 0
tf_switch12 = ta.change(open_bar(H12)) > 0
tf_switch13 = ta.change(open_bar(H13)) > 0
tf_switch14 = ta.change(open_bar(H14)) > 0
tf_switch15 = ta.change(open_bar(H15)) > 0
tf_switch16 = ta.change(open_bar(H16)) > 0
tf_switch17 = ta.change(open_bar(H17)) > 0
tf_switch18 = ta.change(open_bar(H18)) > 0
tf_switch19 = ta.change(open_bar(H19)) > 0
tf_switch20 = ta.change(open_bar(H20)) > 0
tf_switch21 = ta.change(open_bar(H21)) > 0
tf_switch22 = ta.change(open_bar(H22)) > 0
tf_switch23 = ta.change(open_bar(H23)) > 0
tf_switch24 = ta.change(open_bar(H24)) > 0

vwap1 = ta.vwap(source, tf_switch1)
vwap2 = ta.vwap(source, tf_switch2)
vwap3 = ta.vwap(source, tf_switch3)
vwap4 = ta.vwap(source, tf_switch4)
vwap5 = ta.vwap(source, tf_switch5)
vwap6 = ta.vwap(source, tf_switch6)
vwap7 = ta.vwap(source, tf_switch7)
vwap8 = ta.vwap(source, tf_switch8)
vwap9 = ta.vwap(source, tf_switch9)
vwap10 = ta.vwap(source, tf_switch10)
vwap11 = ta.vwap(source, tf_switch11)
vwap12 = ta.vwap(source, tf_switch12)
vwap13 = ta.vwap(source, tf_switch13)
vwap14 = ta.vwap(source, tf_switch14)
vwap15 = ta.vwap(source, tf_switch15)
vwap16 = ta.vwap(source, tf_switch16)
vwap17 = ta.vwap(source, tf_switch17)
vwap18 = ta.vwap(source, tf_switch18)
vwap19 = ta.vwap(source, tf_switch19)
vwap20 = ta.vwap(source, tf_switch20)
vwap21 = ta.vwap(source, tf_switch21)
vwap22 = ta.vwap(source, tf_switch22)
vwap23 = ta.vwap(source, tf_switch23)
vwap24 = ta.vwap(source, tf_switch24)

color1 = close > vwap1 ? color.green : color.red
color2 = close > vwap2 ? color.green : color.red
color3 = close > vwap3 ? color.green : color.red
color4 = close > vwap4 ? color.green : color.red
color5 = close > vwap5 ? color.green : color.red
color6 = close > vwap6 ? color.green : color.red
color7 = close > vwap7 ? color.green : color.red
color8 = close > vwap8 ? color.green : color.red
color9 = close > vwap9 ? color.green : color.red
color10 = close > vwap10 ? color.green : color.red
color11 = close > vwap11 ? color.green : color.red
color12 = close > vwap12 ? color.green : color.red
color13 = close > vwap13 ? color.green : color.red
color14 = close > vwap14 ? color.green : color.red
color15 = close > vwap15 ? color.green : color.red
color16 = close > vwap16 ? color.green : color.red
color17 = close > vwap17 ? color.green : color.red
color18 = close > vwap18 ? color.green : color.red
color19 = close > vwap19 ? color.green : color.red
color20 = close > vwap20 ? color.green : color.red
color21 = close > vwap21 ? color.green : color.red
color22 = close > vwap22 ? color.green : color.red
color23 = close > vwap23 ? color.green : color.red
color24 = close > vwap24 ? color.green : color.red

plot(vwap1, color = tf_switch1 ? na :color1, linewidth = 1)
plot(vwap2, color = tf_switch2 ? na :color2, linewidth = 1)
plot(vwap3, color = tf_switch3 ? na :color3, linewidth = 1)
plot(vwap4, color = tf_switch4 ? na :color4, linewidth = 1)
plot(vwap5, color = tf_switch5 ? na :color5, linewidth = 1)
plot(vwap6, color = tf_switch6 ? na :color6, linewidth = 1)
plot(vwap7, color = tf_switch7 ? na :color7, linewidth = 1)
plot(vwap8, color = tf_switch8 ? na :color8, linewidth = 1)
plot(vwap9, color = tf_switch9 ? na :color9, linewidth = 1)
plot(vwap10, color = tf_switch10 ? na :color10, linewidth = 1)
plot(vwap11, color = tf_switch11 ? na :color11, linewidth = 1)
plot(vwap12, color = tf_switch12 ? na :color12, linewidth = 1)
plot(vwap13, color = tf_switch13 ? na :color13, linewidth = 1)
plot(vwap14, color = tf_switch14 ? na :color14, linewidth = 1)
plot(vwap15, color = tf_switch15 ? na :color15, linewidth = 1)
plot(vwap16, color = tf_switch16 ? na :color16, linewidth = 1)
plot(vwap17, color = tf_switch17 ? na :color17, linewidth = 1)
plot(vwap18, color = tf_switch18 ? na :color18, linewidth = 1)
plot(vwap19, color = tf_switch19 ? na :color19, linewidth = 1)
plot(vwap20, color = tf_switch20 ? na :color20, linewidth = 1)
plot(vwap21, color = tf_switch21 ? na :color21, linewidth = 1)
plot(vwap22, color = tf_switch22 ? na :color22, linewidth = 1)
plot(vwap23, color = tf_switch23 ? na :color23, linewidth = 1)
plot(vwap24, color = tf_switch24 ? na :color24, linewidth = 1)