Skip to content

hour() - Pine Script Function

Use hour() to extract the hour (0–23) from a UNIX timestamp. Pass syminfo.timezone (or another IANA timezone) to align the hour with the exchange or locale you care about.

hour(time, timezone) → series int
NameTypeDescription
timeseries intUNIX timestamp (ms), typically the built-in time series.
timezoneconst stringOptional IANA timezone. Defaults to the exchange timezone when omitted.

Hour of day (023) in the specified timezone.

  • Combine with minute()/second() for finer session filtering.
  • When used with request.security, pass the security’s time series to get its local hour.
//@version=5
indicator("Hourly session shading", overlay=true)
sessionHour = hour(time, syminfo.timezone)
marketOpen = input.int(9, "Session start hour")
marketClose = input.int(16, "Session end hour")
inSession = sessionHour >= marketOpen and sessionHour < marketClose
bgcolor(inSession ? color.new(color.green, 90) : na)
plot(close, "Close")