hour() - Pine Script Function
hour()
Section titled “hour()”Overview
Section titled “Overview”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.
Syntax
Section titled “Syntax”hour(time, timezone) → series intParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
time | series int | UNIX timestamp (ms), typically the built-in time series. |
timezone | const string | Optional IANA timezone. Defaults to the exchange timezone when omitted. |
Returns
Section titled “Returns”Hour of day (0–23) in the specified timezone.
Remarks
Section titled “Remarks”- Combine with
minute()/second()for finer session filtering. - When used with
request.security, pass the security’stimeseries to get its local hour.
Example
Section titled “Example”//@version=5indicator("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 < marketClosebgcolor(inSession ? color.new(color.green, 90) : na)plot(close, "Close")