Date and time/probuilder · probacktest · proorder · proscreener

OpenMinute

OpenMinute returns the minute at which the current bar opened, 0 to 59. Use Minute for the minute of the bar's close and CurrentMinute for the clock now.

Syntax

probuilder
OpenMinute

How it works

OpenMinute returns the minute within the hour at which the bar being processed opened, from 0 to 59. It reads the timestamp of the open of each bar, so it changes along the time axis as the calculation walks from bar to bar. The value is referenced to the local time zone of the account.

OpenMinute is the open-based member of the minute trio. Its siblings are Minute, which reads the minute of each bar's close, and CurrentMinute, which reads the minute of the clock at the moment the code executes and is identical on every bar. On most timeframes the open minute and close minute differ by the bar duration: a five-minute bar that closes at minute 5 opened at minute 0.

The constant takes no parameters and no bracket offset. It is most useful for pinning logic to the opening minute of a session or hour, such as a breakout measured from the top of the hour.

Examples

Example 1, Top-of-hour open flag (Indicator)

probuilder
// Flag bars that opened at the top of the hour
IF OpenMinute = 0 THEN
    openedOnHour = 1
ELSE
    openedOnHour = 0
ENDIF
RETURN openedOnHour

The indicator plots 1 on bars whose open falls exactly on minute 0 of an hour and 0 on the rest, marking the first bar of each hour on an intraday chart.

Example 2, Scan for early-hour bars (ProScreener)

probuilder
// Match instruments whose latest bar opened in the first quarter of the hour
earlyOpen = OpenMinute < 15
SCREENER[earlyOpen AND close > Average[20](close)] (OpenMinute AS "OpenMin")

The screener returns only instruments whose most recent bar opened in the first fifteen minutes of an hour, with the open minute shown alongside.

Example 3, First-bar-of-hour entry (ProOrder)

probuilder
// Only allow entries on the bar that opens each hour
DEFPARAM CumulateOrders = false
firstBarOfHour = OpenMinute = 0
IF firstBarOfHour AND close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

The strategy restricts entries to the bar that opens on the hour, a filter suited to hourly breakout ideas built on a shorter working timeframe.

Common errors and gotchas

  • Open, not close. OpenMinute reads the minute of the bar's open. For the close use Minute. The two differ by the bar duration on most timeframes.
  • Not the wall clock. OpenMinute is a per-bar value that changes along the chart. For the minute of the moment the code runs, use CurrentMinute.
  • Depends on bar alignment. Which minute a bar opens on follows the timeframe and session start, so OpenMinute = 0 only appears when bars actually begin on the hour.
  • No bracket offset. OpenMinute[1] does not compile. To reach an earlier bar's minute use Minute[N].
  • Minute, minute of the close of each bar.
  • CurrentMinute, minute of the clock at execution time.
  • OpenHour, hour at the open of each bar.
  • OpenSecond, second at the open of each bar.
  • OpenTime, opening time of each bar as an HHMMSS integer.
  • Second, second of the close of each bar.
  • TIME, closing time of each bar as an HHMMSS integer.
  • Timestamp, UNIX time of the close of each bar.