Hour
Hour returns the hour (0 to 23) of a bar's closing time in ProBuilder. Use it with the [N] offset to build time-of-day filters for intraday strategies.
Syntax
Hour[N]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| N | integer | 0 | Bar offset. 0 reads the current bar, 1 the previous bar, and so on. The brackets can be omitted to read the current bar. |
How it works
Hour extracts the hour component from the timestamp of a bar, expressed in 24-hour format. The value reflects the bar's closing time, so on a 1-hour chart a bar that opens at 09:00 and closes at 10:00 reports Hour = 10. The sibling keyword OpenHour reads the opening timestamp of the same bar instead, which is why the two keywords can disagree by one bar's duration on intraday charts.
The optional [N] index walks back through history. Hour[1] is the hour of the previous bar's close, Hour[5] the close hour five bars back. This makes it possible to compare the current time slot against earlier ones without storing values manually.
The returned hour depends on the time zone configured in the platform, not on the exchange's local clock. Two users running the same code with different time zone settings can see different values for the same bar.
Hour is most meaningful on intraday timeframes. On daily or higher timeframes every bar closes at the same session time, so the keyword adds no discriminating information there.
Examples
Example 1, Detect the previous bar's close hour (Indicator)
// Flag bars whose previous bar closed during the 9 o'clock hour
IF (Hour[1] = 9) THEN
lasthourwasnine = 1
ELSE
lasthourwasnine = 0
ENDIF
RETURN lasthourwasnineThe indicator plots 1 whenever the previous bar's closing hour was 9, and 0 otherwise. The [1] offset shifts the reading one bar into the past.
Example 2, Restrict entries to a trading window (ProOrder)
// Only allow new long entries between 09:00 and 17:00
timeOK = Hour >= 9 AND Hour < 17
IF timeOK AND close CROSSES OVER Average[50](close) THEN
BUY 1 SHARES AT MARKET
ENDIFThe timeOK flag gates entries so the system stays inactive outside the chosen session hours, a common way to avoid thin overnight markets.
Example 3, Screen for late-session momentum (ProScreener)
// Match instruments making a new 20-bar high after 15:00
lateSession = Hour >= 15
newHigh = close >= Highest[20](close)
SCREENER[lateSession AND newHigh] (Hour AS "Close hour")The screener only returns instruments whose latest bar closed at 15:00 or later while printing a 20-bar closing high, and displays the close hour as the sort column.
Common errors and gotchas
- Close time, not open time. Hour reads the bar's closing timestamp. On a 1-hour chart the bar covering 09:00 to 10:00 returns 10, not 9. Use
OpenHourwhen the logic should key off the time a bar started. - Time zone dependence. The value follows the platform's configured time zone. Code that hardcodes exchange hours breaks silently when run under a different time zone setting.
- Useless on daily charts. On daily and higher timeframes every bar reports the same closing hour, so conditions such as
Hour = 9either always or never match. Apply the keyword on intraday timeframes. - Midnight wrap-around. Sessions that span midnight cannot be tested with a single range check. A window from 22:00 to 02:00 needs
Hour >= 22 OR Hour < 2, not an AND combination.
Related instructions
OpenHour, hour of the current bar's opening time, the sibling form of Hour.CurrentHour, hour of the machine clock rather than a bar timestamp.Minute, minute component (0 to 59) of a bar's closing time.Month, month number (1 to 12) of a bar's closing date.Day, day of the month of a bar's closing date.DayOfWeek, weekday of a bar's closing date.TIME, full closing time of a bar in HHMMSS format.Today, date of the current bar in YYYYMMDD format.
