Sidechair

time

Browse the reference

The opening time of the current bar as a UNIX timestamp in milliseconds.

Try it in the editor

time is a series int holding the moment the current bar opened, counted in milliseconds since 1970-01-01 00:00 UTC. It is the same number for a given bar whatever time zone the chart displays, so time zones only matter when you turn it into a date with year(), hour() and the other calendar functions.

Use it to compare a bar with a fixed date, such as time >= timestamp(2024, 1, 1), to measure how long ago a bar printed, or as the x value of a drawing placed with xloc.bar_time.

Type

series int

Remarks

  • time[n] is na when n reaches back past the first bar.
  • On a daily or higher chart the value is the open of the day, week or month bar, not midnight in your own time zone.
  • The function time(timeframe, session) returns the same kind of value for another timeframe or only inside a trading session.

Example

Pine ScriptColour the bars after a dateOpen in editor
//@version=6
indicator("Since January 2024", overlay = true)
since = time >= timestamp("UTC", 2024, 1, 1, 0, 0, 0)
bgcolor(since ? color.new(color.blue, 90) : na)
plot((timenow - time) / 86400000, "Days old", display = display.data_window)

See also

Runs on Sidechair