timestamp() - Pine Script Function
timestamp()
Section titled “timestamp()”Overview
Section titled “Overview”timestamp() lets you generate UNIX timestamps from date components or ISO / RFC-formatted strings. Pine relies on these values for scheduling, session comparisons, and date arithmetic.
Syntax
Section titled “Syntax”timestamp(dateString) → const inttimestamp(timezone, year, month, day, hour, minute, second) → series inttimestamp(year, month, day, hour, minute, second) → series intThere are additional overloads for const vs series arguments; Pine infers the correct one based on input types.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
dateString | const/series string | Date/time string in RFC 2822 ("20 Feb 2024 09:30:00 -0500") or ISO 8601 ("2024-02-20T09:30:00-05:00") format. |
timezone | const/series string (optional) | Timezone identifier or offset (e.g., "America/New_York", "GMT+3"). |
year, month, day, hour, minute, second | const/series int | Components of the date/time. Omitted components default to zero. |
Returns
Section titled “Returns”series int — UNIX timestamp in milliseconds for the specified date/time.
Remarks
Section titled “Remarks”- When no timezone is provided,
timestamp()assumes UTC (GMT+0). This differs fromtime(), which operates in the exchange timezone by default. - Use
timestamp()withtime >= timestamp(...)style checks to enable logic at specific calendar moments (e.g., new year, scheduled release). timestamp()with literal inputs yieldsconst intoutputs, useful for static configuration (e.g., indicator titles).
Example
Section titled “Example”//@version=5indicator("Scheduled alert window", overlay=true)
releaseTime = input.string("2024-09-20T08:30:00-04:00", "Event time")eventTs = timestamp(releaseTime)
isEventBar = time >= eventTs and time[1] < eventTsplotshape(isEventBar, style=shape.labelup, text="Event", color=color.new(color.orange, 0), textcolor=color.white, location=location.abovebar)