ICT Times [joshu]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © joshuuu
//@version=5
indicator("ICT Times [joshu]", overlay = false, max_boxes_count = 500)
var box killzone_box = na
var box sb_box = na
var box macro_box = na

is_newbar(string sess) =>
    t = time('D', sess, timezone = "America/New_York")
    na(t[1]) and not na(t) or t[1] < t

is_session(string sess) =>
    not na(time('D', sess, timezone = "America/New_York"))

is_over(string sess)   =>
    sess_index = 0
    sess_over = false
    if is_session(sess)
        sess_index := bar_index
    if bar_index[1] == sess_index[1] and bar_index > sess_index
        sess_over := true
    else
        sess_over := false

daily          = "0000-1600"
asia           = "2000-0000"
lokz           = "0200-0500"
nykz           = "0700-1000"
locl           = "1000-1200"
nyam           = "0830-1100"
nypm           = "1330-1600"

syminfo_type() =>
    var string stype = na
    if syminfo.type == "forex"
        stype := "forex"
    else if syminfo.type == "index"
        stype := "index"
    else if syminfo.prefix == "CME_DL"
        stype := "forex"
    else if syminfo.prefix == "CME_MINI_DL"
        stype := "index"

in_kz() =>
    var bool in_kz = na
    if syminfo_type() == "forex"
        in_kz := is_session(lokz) or is_session(nykz) or is_session(locl)
    else
        in_kz := is_session(lokz) or is_session(nyam) or is_session(nypm)
    in_kz

in_sb = is_session("0300-0400") or is_session("1000-1100") or (syminfo_type() != "forex" and is_session("1400-1500"))
in_macro = is_session("0233-0300") or is_session("0403-0430") or is_session("0850-0910") or is_session("0950-1010") or is_session("1050-1110") or is_session("1150-1210") or (syminfo_type() != "forex" and is_session("1310-1340")) or (syminfo_type() != "forex" and is_session("1515-1545"))
if in_kz() and not in_kz()[1] and timeframe.in_seconds() <= timeframe.in_seconds("60")
    killzone_box := box.new(bar_index, 1,bar_index,0, border_color = color.new(color.gray,100),bgcolor = color.new(color.gray,50), text = "killzone", text_size = size.tiny, text_color = chart.fg_color)
else
    if in_kz()
        box.set_right(killzone_box, bar_index)
    
if in_sb and not in_sb[1] and timeframe.in_seconds() <= timeframe.in_seconds("30")
    sb_box := box.new(bar_index, 2,bar_index,1, border_color = color.new(color.gray,100),bgcolor = color.new(color.gray,65), text = "sb", text_size = size.tiny, text_color = chart.fg_color)
else
    if in_sb
        box.set_right(sb_box, bar_index)

if in_macro and not in_macro[1] and timeframe.in_seconds() <= timeframe.in_seconds("5")
    macro_box := box.new(bar_index, 3,bar_index,2, border_color = color.new(color.gray,100),bgcolor = color.new(color.gray,85), text = "macro", text_size = size.tiny, text_color = chart.fg_color)
else
    if in_macro
        box.set_right(macro_box, bar_index)

