Date and time/probuilder · probacktest · proorder · proscreener

OpenTime

OpenTime returns the opening time of the current bar as an HHMMSS integer in the platform's local time zone. Used for time-based conditions in ProBuilder.

Syntax

probuilder
OpenTime

The keyword takes no parameters. Like other date and time constants, it accepts an optional history index in square brackets, so OpenTime[1] reads the opening time of the previous bar.

How it works

Every bar on a chart records the moment it started forming. OpenTime exposes that moment as a single integer in HHMMSS layout: the first two digits are the hour in 24-hour format, the next two the minutes, and the last two the seconds. A bar opening at 09:30:00 therefore yields 93000, and one opening at 14:05:30 yields 140530.

The value follows the local time zone set in the ProRealTime™ platform preferences, not the exchange time zone or UTC. Two users running identical code with different time zone settings can observe different OpenTime values for the same bar.

OpenTime pairs naturally with TIME, which reports the closing time of a bar. On intraday charts the two differ by the bar duration. For an epoch-based, time zone independent equivalent of the bar open, use OpenTimestamp instead.

Because the result is a plain integer, it can be compared with literals (OpenTime >= 80000), stored in variables, or combined with other expressions inside any conditional statement.

Examples

Example 1, Flagging the session opening bar (Indicator)

probuilder
sessionStart = 0
// Flag the bar that opened at exactly 09:30:00
IF OpenTime = 93000 THEN
  sessionStart = 1
ENDIF
RETURN sessionStart

The indicator plots 1 on the bar that opened at 9:30 AM local time and 0 everywhere else, a simple way to mark the start of a trading session.

Example 2, Restricting entries to a morning window (ProOrder)

probuilder
// Allow new long entries only on bars opening between 08:00 and 11:30
IF OpenTime >= 80000 AND OpenTime <= 113000 THEN
  IF NOT LongOnMarket AND close CROSSES OVER Average[50](close) THEN
    BUY 1 CONTRACT AT MARKET
  ENDIF
ENDIF
SET STOP PLOSS 30

The outer condition acts as a time filter, so the moving average crossover can only trigger a position during the defined morning window.

Example 3, Screening for late-session bars (ProScreener)

probuilder
// Match instruments whose current bar opened at or after 16:00
lateOpen = OpenTime >= 160000
SCREENER[lateOpen] ("Open time")

The screener returns instruments whose most recent bar opened during the final stretch of the trading day, useful for separating late prints from stale data.

Common errors and gotchas

  • Wrong digit count in comparisons. 9:30 AM is 93000, not 930 or 0930. The value is a numeric HHMMSS composite, so every comparison literal must spell out hours, minutes, and seconds.
  • Time zone dependence. OpenTime reflects the platform's local time zone setting. Code shared between users in different time zones, or run on a VPS with another clock, will match different bars unless the settings agree.
  • Confusing open and close times. TIME reports when a bar closes, OpenTime reports when it opens. On a 1-hour chart the two differ by an hour, which is enough to shift an entry filter by a full bar.
  • Exact equality on mismatched timeframes. OpenTime = 93000 only matches when a bar actually opens at that second. On a 7-minute or tick-based chart no bar may satisfy the equality, so range comparisons are safer.
  • CurrentTime, current wall-clock time rather than the bar's open.
  • TIME, closing time of a bar in the same HHMMSS format.
  • OpenTimestamp, Unix timestamp of the bar open, time zone independent.
  • Timestamp, Unix timestamp of the bar close.
  • OpenHour, hour component of the bar opening time.
  • OpenMinute, minute component of the bar opening time.
  • OpenSecond, second component of the bar opening time.
  • OpenDate, date on which the bar opened, in YYYYMMDD format.