Date and time/probuilder · probacktest · proorder · proscreener

OpenDate

OpenDate returns the date a bar opened in YYYYMMDD format in ProBuilder. Use it to pin trades or analysis to exact calendar dates on any chart timeframe.

Syntax

probuilder
OpenDate

How it works

OpenDate reads the opening timestamp of the current bar and returns its date as one integer in YYYYMMDD form. A bar that opened on 8 July 2026 yields 20260708. Year, month, and day are packed into a single value, which makes chronological comparisons trivial: a numerically larger OpenDate is always a later date.

The keyword takes no parameters. It refers to the opening time of the bar, whereas bare date keywords such as Today describe the bar's closing date. On daily bars the two normally agree, but on weekly, monthly, or session-spanning bars the opening and closing dates can differ, so the choice of keyword matters.

Because the format packs three fields into one number, extracting a component requires arithmetic. The individual pieces are also available directly through OpenYear, OpenMonth, and OpenDay, which is usually the clearer approach.

Typical uses are restricting a backtest to a date range, anchoring calculations to a known event date, and disabling a live system after a fixed expiry date.

Examples

Example 1, Display the opening date of each bar (Indicator)

probuilder
// Store and plot the opening date of the current bar
myOpenDate = OpenDate
RETURN myOpenDate

The indicator returns the opening date of every bar as a YYYYMMDD number, a quick way to verify which calendar date any bar belongs to.

Example 2, Limit a backtest to a start date (ProBacktest)

probuilder
// Ignore all history before 2 January 2024
IF OpenDate >= 20240102 THEN
  IF close CROSSES OVER Average[50](close) THEN
    BUY 1 SHARES AT MARKET
  ENDIF
ENDIF

Because YYYYMMDD numbers sort chronologically, a single comparison against the literal 20240102 excludes every bar that opened before that date.

Example 3, Deactivate a system after an expiry date (ProOrder)

probuilder
// Stop opening new positions from 1 December 2026 onward
expired = OpenDate >= 20261201

IF NOT expired AND close CROSSES OVER Highest[20](close[1]) THEN
  BUY 1 SHARES AT MARKET
ENDIF

The breakout entry stays active only while the bar's opening date is before the cutoff, a simple way to time-limit a live strategy.

Common errors and gotchas

  • A number, not a date object. OpenDate returns an integer. Date arithmetic such as adding 7 does not yield the date one week later, it just adds 7 to the number and breaks at month boundaries. Use comparisons, not arithmetic.
  • Open date versus close date. OpenDate describes when the bar opened. On weekly or monthly bars the closing date can fall in a different month or year. Compare with Today, which follows the bar's date at close.
  • Component extraction is indirect. Pulling the month out of 20260708 requires division and rounding. Prefer OpenYear, OpenMonth, and OpenDay, which return the components directly.
  • Full eight-digit literals required. Comparisons must use complete YYYYMMDD values. A condition like OpenDate = 0708 never matches because the stored value always includes the year.
  • Today, date of the current bar in YYYYMMDD format, following the close.
  • OpenDay, day of the month on which the current bar opened.
  • OpenMonth, month number in which the current bar opened.
  • OpenYear, year in which the current bar opened.
  • OpenTime, opening time of the current bar in HHMMSS format.
  • OpenHour, hour at which the current bar opened.
  • Timestamp, bar close timestamp in seconds since 1970.
  • OpenTimestamp, bar open timestamp in seconds since 1970.