Ultimate Time Filter V1
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FloppyDisque
//@version=5
indicator("Ultimate Time Filter", shorttitle = "UTFv1", overlay = true)
// Time Filter {
// Beginning / End date filter {
g_time          = "Time Filter"
timeZone        = input.string("GMT+0", "Time Zone", group = g_time, 
     tooltip = "GMT and UTC is the same thing \nMatch this setting to bottom right time",
     options = ["GMT-10", "GMT-9", "GMT-8", "GMT-7", "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT+0", "GMT+1", "GMT+2", "GMT+3", "GMT+4", "GMT+5", "GMT+6", "GMT+7", "GMT+8", "GMT+9", "GMT+10", "GMT+10:30", "GMT+11", "GMT+12", "GMT+13", "GMT+13:45"])
startTimeIn     = input.time(timestamp("24 Feb 2022"), "Start Date Filter", group = g_time,
     tooltip = "Changing timezone at bottom right of chart will change start time\nSet chart timezone to your prefered time first, then change indicator setting")
endTimeIn       = input.time(timestamp("01 Jan 2099"), "End Date Filter", group = g_time)

startTimeYear   = year  (startTimeIn, timeZone)
startTimeMonth  = month (startTimeIn, timeZone)
startTimeDay    = dayofmonth(startTimeIn, timeZone)
endTimeYear     = year  (endTimeIn, timeZone)
endTimeMonth    = month (endTimeIn, timeZone)
endTimeDay      = dayofmonth(endTimeIn, timeZone)

startTime   = timestamp(timeZone, startTimeYear, startTimeMonth, startTimeDay)
endTime     = timestamp(timeZone, endTimeYear, endTimeMonth, endTimeDay)
inDate      = time >= startTime and time <= endTime
//}
// Weekdays Filter {
useWeek = input.bool(true, "Use Weekdays Filter?", group = g_time,
     tooltip = "Disable to allow all weekdays, Enable to choose certain days")
useMon  = input.bool(true, "Mon  ", inline = "Days", group = g_time)
useTue  = input.bool(true, "Tue  ", inline = "Days", group = g_time)
useWed  = input.bool(true, "Wed  ", inline = "Days", group = g_time)
useThu  = input.bool(true, "Thu  ", inline = "Days", group = g_time)
useFri  = input.bool(true, "Fri  ", inline = "Days", group = g_time)
useSat  = input.bool(true, "Sat  ", inline = "Days", group = g_time)
useSun  = input.bool(true, "Sun", inline = "Days", group = g_time)
inWeek  = if useWeek and useMon and dayofweek(time, timeZone) == dayofweek.monday
    true
else if useWeek and useTue and dayofweek(time, timeZone) == dayofweek.tuesday
    true
else if useWeek and useWed and dayofweek(time, timeZone) == dayofweek.wednesday
    true
else if useWeek and useThu and dayofweek(time, timeZone) == dayofweek.thursday
    true
else if useWeek and useFri and dayofweek(time, timeZone) == dayofweek.friday
    true
else if useWeek and useSat and dayofweek(time, timeZone) == dayofweek.saturday
    true
else if useWeek and useSun and dayofweek(time, timeZone) == dayofweek.sunday
    true
else if not(useWeek)
    true

//}
// Session Filter {
isInSess(_sess) => time(timeframe.period, _sess, timeZone)

useSess     = input.bool(false, "Use Session Filter?", group = g_time)
timeSess1    = input.session("0900-1730", "Time Session", group = g_time)
inSess1 = isInSess(timeSess1)

useSess2    = input.bool(false, "Use 2ND Session Filter?", group = g_time)
timeSess2   = input.session("1930-2100", "Time Session 2", group = g_time)
inSess2 = isInSess(timeSess2)

inSess = if useSess and inSess1
    true
else if useSess2 and inSess2
    true
else if not (useSess)
    true
//}
// Display Time Filter --- USE VARIABLE -->"inTime"<-- AS TIME FILTER IN ANY CODE {
inTime = inDate and inWeek and inSess
bgcolor(inTime ? color.new(color.blue, 90) : na, title = "Time Filter")
//}
//}