Date and time/probuilder · probacktest · proorder · proscreener

OpenHour

OpenHour returns the hour (0 to 23) at which the current bar opened, in local platform time. Use OpenHour in ProBuilder for session and time-of-day rules.

Syntax

probuilder
OpenHour

How it works

OpenHour reads the opening timestamp of the current bar and returns its hour component in 24-hour format. The keyword takes no parameters.

It is the opening-time counterpart of the bare keyword Hour, which follows the bar's closing timestamp. On a 1-hour chart the bar covering 09:00 to 10:00 reports OpenHour = 9 and Hour = 10. When a rule should fire based on the time a bar starts, for example acting on the bar that opens the cash session, OpenHour is the appropriate form.

The returned hour depends on the time zone configured in the platform, not on the exchange clock. The same code can therefore behave differently for users in different time zones, which matters when session boundaries are hardcoded.

On daily and higher timeframes every bar opens at the same session time, so the keyword only discriminates on intraday charts. Like other bar series, past values can be read with an index, for example OpenHour[1] for the previous bar.

Examples

Example 1, Detect bars opening at 9 (Indicator)

probuilder
// Check whether the current bar opened during the 9 o'clock hour
iHour = OpenHour
if iHour = 9 then
  // logic tied to the market opening hour
  openingHour = 1
else
  openingHour = 0
endif
RETURN openingHour

The indicator plots 1 on bars that opened between 09:00 and 09:59, isolating the first hour of a typical cash session.

Example 2, Morning-only entry window (ProOrder)

probuilder
// Allow entries only on bars opening between 08:00 and 10:59
window = OpenHour >= 8 AND OpenHour < 11

IF window AND close CROSSES OVER Average[20](close) THEN
  BUY 1 SHARES AT MARKET
ENDIF

New positions can only be opened on bars that start during the morning window, while exits and management remain active at all hours.

Example 3, Screen the opening hour for gaps (ProScreener)

probuilder
// Match instruments gapping up on bars opening at 9
atOpen = OpenHour = 9
gapUp = open > close[1] * 1.01

SCREENER[atOpen AND gapUp] (((open / close[1]) - 1) * 100 AS "Gap %")

The screener flags instruments whose 9 o'clock bar opened more than 1 percent above the prior close, sorting by gap size.

Common errors and gotchas

  • Open time, not close time. OpenHour follows the bar's opening timestamp. The sibling Hour reads the close, so the two differ by one bar length on intraday charts. Mixing them shifts every time filter by one bar.
  • Local time zone. The value follows the platform's configured time zone rather than exchange time. Hardcoded session hours can be wrong for users with different settings, or after a daylight saving change.
  • No discrimination on daily charts. On daily and higher timeframes every bar opens at the same hour, so conditions like OpenHour = 9 match every bar or none.
  • Windows spanning midnight. A session from 22:00 to 02:00 needs OpenHour >= 22 OR OpenHour < 2. The AND form never matches.
  • Hour, hour of a bar's closing time, the sibling form of OpenHour.
  • CurrentHour, hour of the machine clock rather than a bar timestamp.
  • OpenMinute, minute at which the current bar opened.
  • OpenSecond, second at which the current bar opened.
  • OpenTime, full opening time of the current bar in HHMMSS format.
  • TIME, full closing time of a bar in HHMMSS format.
  • CurrentTime, machine clock time in HHMMSS format.