// Time zone offset input (hours from UTC) timeZoneOffset = input.int(0, title="Time Zone Offset (hours)", minval=-12, maxval=14)
// Input fields to set exact times for each time interval (in UTC) startTime1 = input.time(timestamp("1970-01-01 08:05"), title="Start Time 1 (UTC)") endTime1 = input.time(timestamp("1970-01-01 09:15"), title="End Time 1 (UTC)")
startTime2 = input.time(timestamp("1970-01-01 09:45"), title="Start Time 2 (UTC)") endTime2 = input.time(timestamp("1970-01-01 10:15"), title="End Time 2 (UTC)")
startTime3 = input.time(timestamp("1970-01-01 10:45"), title="Start Time 3 (UTC)") endTime3 = input.time(timestamp("1970-01-01 11:15"), title="End Time 3 (UTC)")
// Function to adjust time by time zone offset adjustTimeByTimeZoneOffset(timeVal) => timeVal + timeZoneOffset * 3600000 // Convert hours to milliseconds
// Function to check if the current time (adjusted by the time zone offset) is within a time range isInTimeRange(startTime, endTime) => // Get the current time in UTC and adjust it by the time zone offset currentTime = na(time) ? na : timestamp("1970-01-01 00:00") + (time % 86400000) adjustedCurrentTime = adjustTimeByTimeZoneOffset(currentTime) // Check if the adjusted time is within the specified range adjustedCurrentTime >= startTime and adjustedCurrentTime <= endTime
// Calculate the timestamp for 10 days ago tenDaysAgo = timestamp("1970-01-01 00:00") + (dayofmonth(time) - 10) * 86400000
// Function to check if the bar is within the last 10 days isInLastTenDays() => time >= tenDaysAgo
// Highlight time intervals with background colors when the current time (adjusted) is in the specified range and within the last 10 days bgcolor(isInLastTenDays() and isInTimeRange(adjustTimeByTimeZoneOffset(startTime1), adjustTimeByTimeZoneOffset(endTime1)) ? color.new(color.blue, 85) : na) bgcolor(isInLastTenDays() and isInTimeRange(adjustTimeByTimeZoneOffset(startTime2), adjustTimeByTimeZoneOffset(endTime2)) ? color.new(color.green, 85) : na) bgcolor(isInLastTenDays() and isInTimeRange(adjustTimeByTimeZoneOffset(startTime3), adjustTimeByTimeZoneOffset(endTime3)) ? color.new(color.red, 85) : na)
// Option to add vertical lines at the start of each time interval plotVerticalLines = input.bool(true, title="Show Vertical Lines at Start Times")
if plotVerticalLines if isInLastTenDays() and isInTimeRange(adjustTimeByTimeZoneOffset(startTime1), adjustTimeByTimeZoneOffset(startTime1)) line.new(x1=bar_index, y1=high, x2=bar_index, y2=high, color=color.blue, width=2) if isInLastTenDays() and isInTimeRange(adjustTimeByTimeZoneOffset(startTime2), adjustTimeByTimeZoneOffset(startTime2)) line.new(x1=bar_index, y1=high, x2=bar_index, y2=high, color=color.green, width=2) if isInLastTenDays() and isInTimeRange(adjustTimeByTimeZoneOffset(startTime3), adjustTimeByTimeZoneOffset(startTime3)) line.new(x1=bar_index, y1=high, x2=bar_index, y2=high, color=color.red, width=2)