Date and time/probuilder · probacktest · proorder · proscreener

CurrentHour

CurrentHour returns the hour of the clock at execution time, 0 to 23, identical on every bar of the chart. Use Hour to read the hour of each bar's close.

Syntax

probuilder
CurrentHour

How it works

CurrentHour reads the clock at the moment the code runs and returns the hour in 24-hour format, from 0 to 23. The reference is the time zone of the instrument's market, which may differ from the local machine. The constant takes no parameters and no bracket offset.

The value belongs to the Current family of date and time constants, which describe the moment of execution rather than any bar on the chart. Every bar of a calculation therefore sees the same number: an indicator refreshed at 14:20 returns 14 on every historical bar. The per-bar sibling is Hour, which returns the hour of the close of each bar being processed and changes along the time axis. Session filters applied to historical data belong with Hour or TIME; CurrentHour describes the wall clock now.

In a live ProOrder system CurrentHour is meaningful, since the code executes in real time as bars arrive. In a backtest it reflects the hour the test runs, which makes it unsuitable for historical entry or exit conditions.

Examples

Example 1, Noon flag (Indicator)

probuilder
// Set the flag when the script executes during the 12 o'clock hour
IF (CurrentHour = 12) THEN
    GoLunch = 1
ELSE
    GoLunch = 0
ENDIF
RETURN GoLunch

The indicator plots 1 across the whole chart when recalculated between 12:00:00 and 12:59:59 market time, and 0 at any other time of day.

Example 2, Scan restricted to session hours (ProScreener)

probuilder
// Return matches only while the cash session is open
inSession = (CurrentHour >= 9) AND (CurrentHour < 17)
SCREENER[inSession AND close > Average[20](close)] (close AS "Close")

The screener returns an empty list outside the chosen hours, a way to keep a scheduled scan quiet outside the session.

Example 3, Evening shutdown (ProOrder)

probuilder
// Stop the strategy before the evening maintenance window
DEFPARAM CumulateOrders = false
IF CurrentHour >= 22 THEN
    QUIT
ENDIF
IF close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

Live, the system stops itself from 22:00 market time onward. Backtests cannot exercise this branch meaningfully, because CurrentHour holds the hour of the test run on every bar.

Common errors and gotchas

  • Same value on every bar. CurrentHour describes the clock, not the chart, so a condition such as CurrentHour = 12 is true or false for the entire calculation at once. Per-bar session logic needs Hour or TIME.
  • Backtest blind spot. In a backtest CurrentHour returns the hour the test executes, so time filters built on it pass or block wholesale and produce results that do not match live behavior.
  • Market time zone, not local time. The hour is referenced to the instrument's market. A chart of a New York listing viewed from Europe returns New York hours, not the viewer's local hours.
  • No bracket offset. CurrentHour[1] does not compile. Only per-bar constants such as Hour[N] accept an index.
  • Hour, hour of the close of each bar, the per-bar sibling of this constant.
  • OpenHour, hour at the open of each bar.
  • CurrentMinute, minute of the clock at execution time.
  • CurrentSecond, second of the clock at execution time.
  • CurrentTime, full clock time at execution as an HHMMSS integer.
  • CurrentDayOfWeek, weekday of the clock at execution time.
  • TIME, closing time of each bar as an HHMMSS integer.
  • Timestamp, UNIX time of the close of each bar.