time - PineScript Variable
Overview
Section titled “Overview”time contains the UNIX timestamp (milliseconds since 1970-01-01 UTC) corresponding to the open of the current bar in the chart’s exchange timezone.
Remarks
Section titled “Remarks”- Values reflect the bar open, so overnight sessions may report the previous calendar day.
- Pair with helpers like
year(time)orweekofyear(time)to derive calendar attributes. - For realtime clocks, use
timenow(current moment) ortime_close(estimated bar close).
Example
Section titled “Example”//@version=5indicator("Session shading via time", overlay=true)
start = timestamp("America/New_York", 2024, 1, 2, 9, 30, 0)finish = timestamp("America/New_York", 2024, 1, 2, 16, 0, 0)
inWindow = time >= start and time <= finish
bgcolor(inWindow ? color.new(color.teal, 88) : na, title="NY Session on Jan 2, 2024")