FX Sessions & Killzones EDT [Spring/Summer]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © skullp

//@version=5
indicator("FX Sessions & Killzones ET", overlay = true)

// Custom Session Box
customBoxSwitch = input.bool(defval = true, title = "", inline = "custom", group = "Custom Session Box")
customBoxBgColor = input.color(defval = #ec407a1a, title = "", inline = "custom", group = "Custom Session Box")
customBoxBorderColor = input.color(defval = #ec407980, title = "", inline = "custom", group = "Custom Session Box")
string customBoxHours = input.session(defval = "0000-0829", title = "", inline = "custom", group = "Custom Session Box", display = display.all - display.status_line)
string customBoxDays = input.string(defval = "23456", title = "", inline = "custom", group = "Custom Session Box", display = display.all - display.status_line)
string customBoxTime = customBoxHours + ":" + customBoxDays
customSessionActive = time(timeframe.period, customBoxTime, "America/New_York") and timeframe.isintraday
customSessionStart = customSessionActive and not customSessionActive[1]
var customSessionHigh = 0.0
var customSessionLow = 0.0
if customSessionStart
    customSessionHigh := high
    customSessionLow := low
else if customSessionActive
    customSessionHigh := math.max(customSessionHigh, high)
    customSessionLow := math.min(customSessionLow, low)
var box customSessionBox = na
if customSessionStart and customBoxSwitch
    customSessionBox := box.new(left = bar_index, top = na, right = na, bottom = na, border_color = customBoxBorderColor, border_width = 1, border_style=line.style_dotted, bgcolor = customBoxBgColor)
if customSessionActive and customBoxSwitch
    box.set_top(customSessionBox, customSessionHigh)
    box.set_bottom(customSessionBox, customSessionLow)
    box.set_right(customSessionBox, bar_index + 1)

// Sydney Session
sydneySwitch = input.bool(defval = false, title = "", inline = "sydney", group = "Sydney Session")
sydneyColor = input.color(defval = #2962ff1a, title = "", inline = "sydney", group = "Sydney Session")
string sydneyHours = input.session(defval = "1700-0200", title = "", inline = "sydney", group = "Sydney Session", display = display.all - display.status_line)
string sydneyDays = input.string(defval = "23456", title = "", inline = "sydney", group = "Sydney Session", tooltip = "1 = Sunday, 7 = Saturday", display = display.all - display.status_line)
string sydneyTime = sydneyHours + ":" + sydneyDays
sydneySession = time(timeframe.period, sydneyTime, "America/New_York") and timeframe.isintraday

// Asia Session
asiaSwitch = input.bool(defval = false, title = "", inline = "asia", group = "Asia Session")
asiaColor = input.color(defval = #673ab71a, title = "", inline = "asia", group = "Asia Session")
string asiaHours = input.session(defval = "1900-0400", title = "", inline = "asia", group = "Asia Session", display = display.all - display.status_line)
string asiaDays = input.string(defval = "23456", title = "", inline = "asia", group = "Asia Session", display = display.all - display.status_line)
string asiaTime = asiaHours + ":" + asiaDays
asiaSession = time(timeframe.period, asiaTime, "America/New_York") and timeframe.isintraday

// Tokyo Session
tokyoSwitch = input.bool(defval = false, title = "", inline = "tokyo", group = "Tokyo Session")
tokyoColor = input.color(defval = #9c27b01a, title = "", inline = "tokyo", group = "Tokyo Session")
string tokyoHours = input.session(defval = "2000-0500", title = "", inline = "tokyo", group = "Tokyo Session", display = display.all - display.status_line)
string tokyoDays = input.string(defval = "23456", title = "", inline = "tokyo", group = "Tokyo Session", display = display.all - display.status_line)
string tokyoTime = tokyoHours + ":" + tokyoDays
tokyoSession = time(timeframe.period, tokyoTime, "America/New_York") and timeframe.isintraday

// Frankfurt Session
frankfurtSwitch = input.bool(defval = false, title = "", inline = "frankfurt", group = "Frankfurt Session")
frankfurtColor = input.color(defval = #e91e631a, title = "", inline = "frankfurt", group = "Frankfurt Session")
string frankfurtHours = input.session(defval = "0200-1100", title = "", inline = "frankfurt", group = "Frankfurt Session", display = display.all - display.status_line)
string frankfurtDays = input.string(defval = "23456", title = "", inline = "frankfurt", group = "Frankfurt Session", display = display.all - display.status_line)
string frankfurtTime = frankfurtHours + ":" + frankfurtDays
frankfurtSession = time(timeframe.period, frankfurtTime, "America/New_York") and timeframe.isintraday

// London Session
londonSwitch = input.bool(defval = false, title = "", inline = "london", group = "London Session")
londonColor = input.color(defval = #f236451a, title = "", inline = "london", group = "London Session")
string londonHours = input.session(defval = "0300-1200", title = "", inline = "london", group = "London Session", display = display.all - display.status_line)
string londonDays = input.string(defval = "23456", title = "", inline = "london", group = "London Session", display = display.all - display.status_line)
string londonTime = londonHours + ":" + londonDays
londonSession = time(timeframe.period, londonTime, "America/New_York") and timeframe.isintraday

// New York / US Session
newyorkSwitch = input.bool(defval = false, title = "", inline = "newyork", group = "New York / US Session")
newyorkColor = input.color(defval = #ff98001a, title = "", inline = "newyork", group = "New York / US Session")
string newyorkHours = input.session(defval = "0800-1700", title = "", inline = "newyork", group = "New York / US Session", display = display.all - display.status_line)
string newyorkDays = input.string(defval = "23456", title = "", inline = "newyork", group = "New York / US Session", display = display.all - display.status_line)
string newyorkTime = newyorkHours + ":" + newyorkDays
newyorkSession = time(timeframe.period, newyorkTime, "America/New_York") and timeframe.isintraday

// Asian Range
asiaRangeSwitch = input.bool(defval = true, title = "", inline = "asiaRange", group = "Asian Range")
asiaRangeColor = input.color(defval = #7e57c21a, title = "", inline = "asiaRange", group = "Asian Range")
string asiaRangeHours = input.session(defval = "1900-0000", title = "", inline = "asiaRange", group = "Asian Range", display = display.all - display.status_line)
string asiaRangeDays = input.string(defval = "12345", title = "", inline = "asiaRange", group = "Asian Range", display = display.all - display.status_line)
string asiaRangeTime = asiaRangeHours + ":" + asiaRangeDays
asiaRangeSession = time(timeframe.period, asiaRangeTime, "America/New_York") and timeframe.isintraday

// Asian Open Killzone
asiaOpenSwitch = input.bool(defval = false, title = "", inline = "asiaOpen", group = "Asian Open Killzone")
asiaOpenColor = input.color(defval = #9575cd1a, title = "", inline = "asiaOpen", group = "Asian Open Killzone")
string asiaOpenHours = input.session(defval = "1900-2100", title = "", inline = "asiaOpen", group = "Asian Open Killzone", display = display.all - display.status_line)
string asiaOpenDays = input.string(defval = "12345", title = "", inline = "asiaOpen", group = "Asian Open Killzone", display = display.all - display.status_line)
string asiaOpenTime = asiaOpenHours + ":" + asiaOpenDays
asiaOpenSession = time(timeframe.period, asiaOpenTime, "America/New_York") and timeframe.isintraday

// London Open Killzone
londonOpenSwitch = input.bool(defval = true, title = "", inline = "londonOpen", group = "London Open Killzone")
londonOpenColor = input.color(defval = #f7525f1a, title = "", inline = "londonOpen", group = "London Open Killzone")
string londonOpenHours = input.session(defval = "0200-0500", title = "", inline = "londonOpen", group = "London Open Killzone", display = display.all - display.status_line)
string londonOpenDays = input.string(defval = "23456", title = "", inline = "londonOpen", group = "London Open Killzone", display = display.all - display.status_line)
string londonOpenTime = londonOpenHours + ":" + londonOpenDays
londonOpenSession = time(timeframe.period, londonOpenTime, "America/New_York") and timeframe.isintraday

// London Close Killzone
londonCloseSwitch = input.bool(defval = false, title = "", inline = "londonClose", group = "London Close Killzone")
londonCloseColor = input.color(defval = #f77c801a, title = "", inline = "londonClose", group = "London Close Killzone")
string londonCloseHours = input.session(defval = "1000-1200", title = "", inline = "londonClose", group = "London Close Killzone", display = display.all - display.status_line)
string londonCloseDays = input.string(defval = "23456", title = "", inline = "londonClose", group = "London Close Killzone", display = display.all - display.status_line)
string londonCloseTime = londonCloseHours + ":" + londonCloseDays
londonCloseSession = time(timeframe.period, londonCloseTime, "America/New_York") and timeframe.isintraday

// New York / US Open Killzone
newyorkOpenSwitch = input.bool(defval = true, title = "", inline = "newyorkOpen", group = "New York / US Open Killzone")
newyorkOpenColor = input.color(defval = #f57c001a, title = "", inline = "newyorkOpen", group = "New York / US Open Killzone")
string newyorkOpenHours = input.session(defval = "0700-1000", title = "", inline = "newyorkOpen", group = "New York / US Open Killzone", display = display.all - display.status_line)
string newyorkOpenDays = input.string(defval = "23456", title = "", inline = "newyorkOpen", group = "New York / US Open Killzone", display = display.all - display.status_line)
string newyorkOpenTime = newyorkOpenHours + ":" + newyorkOpenDays
newyorkOpenSession = time(timeframe.period, newyorkOpenTime, "America/New_York") and timeframe.isintraday

// Indices
indicesSwitch = input.bool(defval = false, title = "", inline = "indices", group = "Indices")
indicesColor = input.color(defval = #4caf501a, title = "", inline = "indices", group = "Indices")
string indicesHours = input.session(defval = "0930-1600", title = "", inline = "indices", group = "Indices", display = display.all - display.status_line)
string indicesDays = input.string(defval = "23456", title = "", inline = "indices", group = "Indices", display = display.all - display.status_line)
string indicesTime = indicesHours + ":" + indicesDays
indicesSession = time(timeframe.period, indicesTime, "America/New_York") and timeframe.isintraday

// Indices Closing / Power Hour
indicesCloseSwitch = input.bool(defval = false, title = "", inline = "indicesClose", group = "Indices Closing / Power Hour")
indicesCloseColor = input.color(defval = #66bb6a1a, title = "", inline = "indicesClose", group = "Indices Closing / Power Hour")
string indicesCloseHours = input.session(defval = "1500-1600", title = "", inline = "indicesClose", group = "Indices Closing / Power Hour", display = display.all - display.status_line)
string indicesCloseDays = input.string(defval = "23456", title = "", inline = "indicesClose", group = "Indices Closing / Power Hour", display = display.all - display.status_line)
string indicesCloseTime = indicesCloseHours + ":" + indicesCloseDays
indicesCloseSession = time(timeframe.period, indicesCloseTime, "America/New_York") and timeframe.isintraday

// Silver Bullet London AM
silverLondonSwitch = input.bool(defval = false, title = "", inline = "silverLondon", group = "Silver Bullet London AM")
silverLondonColor = input.color(defval = #4dd0e11a, title = "", inline = "silverLondon", group = "Silver Bullet London AM")
string silverLondonHours = input.session(defval = "0300-0400", title = "", inline = "silverLondon", group = "Silver Bullet London AM", display = display.all - display.status_line)
string silverLondonDays = input.string(defval = "23456", title = "", inline = "silverLondon", group = "Silver Bullet London AM", display = display.all - display.status_line)
string silverLondonTime = silverLondonHours + ":" + silverLondonDays
silverLondonSession = time(timeframe.period, silverLondonTime, "America/New_York") and timeframe.isintraday

// Silver Bullet New York / US AM
silverNYAMSwitch = input.bool(defval = false, title = "", inline = "silverNYAM", group = "Silver Bullet New York / US AM")
silverNYAMColor = input.color(defval = #4dd0e11a, title = "", inline = "silverNYAM", group = "Silver Bullet New York / US AM")
string silverNYAMHours = input.session(defval = "1000-1100", title = "", inline = "silverNYAM", group = "Silver Bullet New York / US AM", display = display.all - display.status_line)
string silverNYAMDays = input.string(defval = "23456", title = "", inline = "silverNYAM", group = "Silver Bullet New York / US AM", display = display.all - display.status_line)
string silverNYAMTime = silverNYAMHours + ":" + silverNYAMDays
silverNYAMSession = time(timeframe.period, silverNYAMTime, "America/New_York") and timeframe.isintraday

// Silver Bullet New York / US PM
silverNYPMSwitch = input.bool(defval = false, title = "", inline = "silverNYPM", group = "Silver Bullet New York / US PM")
silverNYPMColor = input.color(defval = #4dd0e11a, title = "", inline = "silverNYPM", group = "Silver Bullet New York / US PM")
string silverNYPMHours = input.session(defval = "1400-1500", title = "", inline = "silverNYPM", group = "Silver Bullet New York / US PM", display = display.all - display.status_line)
string silverNYPMDays = input.string(defval = "23456", title = "", inline = "silverNYPM", group = "Silver Bullet New York / US PM", display = display.all - display.status_line)
string silverNYPMTime = silverNYPMHours + ":" + silverNYPMDays
silverNYPMSession = time(timeframe.period, silverNYPMTime, "America/New_York") and timeframe.isintraday

// Warning if on higher time frames
f_print(_text) =>
    var table _t = table.new(position.top_right, 1, 1)
    table.cell(_t, 0, 0, _text, text_color = #2a2e39, text_size = size.small, bgcolor = #b2b5be)
var chartIsMoreThan120Min = timeframe.isseconds or (timeframe.isintraday and timeframe.multiplier >= 120)
if chartIsMoreThan120Min
    f_print("Some of the sessions may require lower time frames to appear.")

// Plot
color noColor = color(na)
bgcolor(sydneySwitch and sydneySession ? sydneyColor : noColor)
bgcolor(asiaSwitch and asiaSession ? asiaColor : noColor)
bgcolor(tokyoSwitch and tokyoSession ? tokyoColor : noColor)
bgcolor(frankfurtSwitch and frankfurtSession ? frankfurtColor : noColor)
bgcolor(londonSwitch and londonSession ? londonColor : noColor)
bgcolor(newyorkSwitch and newyorkSession ? newyorkColor : noColor)
bgcolor(asiaRangeSwitch and asiaRangeSession ? asiaRangeColor : noColor)
bgcolor(asiaOpenSwitch and asiaOpenSession ? asiaOpenColor : noColor)
bgcolor(londonOpenSwitch and londonOpenSession ? londonOpenColor : noColor)
bgcolor(londonCloseSwitch and londonCloseSession ? londonCloseColor : noColor)
bgcolor(newyorkOpenSwitch and newyorkOpenSession ? newyorkOpenColor : noColor)
bgcolor(indicesSwitch and indicesSession ? indicesColor : noColor)
bgcolor(indicesCloseSwitch and indicesCloseSession ? indicesCloseColor : noColor)
bgcolor(silverLondonSwitch and silverLondonSession ? silverLondonColor : noColor)
bgcolor(silverNYAMSwitch and silverNYAMSession ? silverNYAMColor : noColor)
bgcolor(silverNYPMSwitch and silverNYPMSession ? silverNYPMColor : noColor)