OpenTimestamp
OpenTimestamp returns the Unix timestamp of the current bar's opening time in ProBuilder, counting seconds since 1 January 1970 UTC, unaffected by time zones.
Syntax
OpenTimestampThe keyword takes no parameters. A history index in square brackets reads earlier bars, so OpenTimestamp[1] gives the opening timestamp of the previous bar.
How it works
A Unix timestamp counts time as a running total of seconds starting from the Unix Epoch, 1 January 1970 at 00:00:00 UTC. OpenTimestamp reports that count for the moment the current candlestick opened. Because the scale is anchored to UTC, the value is identical for every user regardless of platform time zone settings or daylight saving transitions.
This makes OpenTimestamp the right tool for duration arithmetic. Subtracting two timestamps yields a difference in whole seconds, something that is unsafe with HHMMSS values such as OpenTime, where the digits encode hours and minutes rather than a linear count.
The companion keyword Timestamp reports the Unix time of the bar close. The difference Timestamp - OpenTimestamp therefore equals the bar duration on completed bars, and the age of the bar so far on the live forming bar. Differences between the opening timestamps of consecutive bars expose gaps in the data, such as overnight breaks or weekends.
Examples
Example 1, Seconds elapsed inside the current bar (Indicator)
// Seconds between the bar open and the bar timestamp
elapsed = Timestamp - OpenTimestamp
RETURN elapsedOn completed bars the plot equals the bar duration in seconds. On the live bar it shows how long the candlestick has been forming.
Example 2, Detecting a session gap between bars (ProOrder)
// Detect a gap larger than 4 hours between consecutive bar opens
gapSeconds = OpenTimestamp - OpenTimestamp[1]
IF gapSeconds > 14400 AND NOT OnMarket THEN
// The first bar after a long break, such as a new session
BUY 1 CONTRACT AT MARKET
ENDIF
SET STOP PLOSS 40Comparing the opening timestamps of two consecutive bars measures the real elapsed time between them, which identifies the first bar after an overnight or weekend break.
Example 3, Filtering out stale instruments (ProScreener)
// Match instruments whose current bar opened within the last 15 minutes
fresh = Timestamp - OpenTimestamp < 900
SCREENER[fresh] ("Fresh bar")The screener keeps instruments whose latest candlestick is younger than 900 seconds, discarding those that have not printed recent data.
Common errors and gotchas
- Seconds, not milliseconds. ProBuilder Unix timestamps count seconds. Constants copied from other environments that use millisecond epochs will be off by a factor of 1000.
- Mixing timestamp and HHMMSS systems.
OpenTimestamplives on a linear UTC scale whileOpenTimeis a local-time HHMMSS composite. Comparing or subtracting values across the two systems produces meaningless numbers. - Assuming local time. The value is anchored to UTC. Session boundaries defined in local hours must be handled with
OpenTimeorOpenHour, not by adding a fixed offset to the timestamp, since offsets change with daylight saving. - Bar close versus wall clock. On historical bars,
Timestampis the close time of that bar, not the present moment.Timestamp - OpenTimestamponly tracks a running age on the live forming bar.
Related instructions
Timestamp, Unix timestamp of the bar close.OpenTime, opening time of the bar as a local HHMMSS integer.CurrentTime, current wall-clock time in HHMMSS format.TIME, closing time of a bar in HHMMSS format.OpenDate, date on which the bar opened, in YYYYMMDD format.OpenHour, hour component of the bar opening time.BarIndex, number of bars since the beginning of the loaded history.IntradayBarIndex, bar counter that resets at the start of each day.
