Date and time/probuilder · probacktest · proorder · proscreener

CurrentYear

CurrentYear returns the four-digit year of the clock at execution time, identical on every bar of the chart. Use Year to read the year of each bar's close.

Syntax

probuilder
CurrentYear

How it works

CurrentYear reads the clock at the moment the code runs and returns the calendar year as a four-digit integer, such as 2026. 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 in 2026 returns 2026 on every historical bar. The per-bar sibling is Year, which returns the year of the close of each bar being processed and changes along the time axis. Year-by-year segmentation of historical data belongs with Year; CurrentYear describes the calendar now.

In a live ProOrder system CurrentYear is meaningful, since the code executes in real time as bars arrive. In a backtest it reflects the year the test runs, which makes it unsuitable for historical year-based conditions.

Examples

Example 1, Current year label (Indicator)

probuilder
// Retrieve the year of the clock at execution time
iYear = CurrentYear
RETURN iYear AS "this is the current year"

The indicator plots a flat line at the current year across the whole chart, refreshed to the wall-clock year each time the script recalculates.

Example 2, Scan gated by year (ProScreener)

probuilder
// Return matches only from a chosen year onward
recentEnough = CurrentYear >= 2026
SCREENER[recentEnough AND close > Average[50](close)] (close AS "Close")

The screener only reports results once the clock reaches 2026 or later, a simple calendar gate on a scheduled scan.

Example 3, Year-based stop (ProOrder)

probuilder
// Stop the strategy at the turn of a chosen year
DEFPARAM CumulateOrders = false
IF CurrentYear >= 2027 THEN
    QUIT
ENDIF
IF close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

Live, the system stops itself once the calendar rolls into 2027. Backtests cannot exercise this branch meaningfully, because CurrentYear holds the year of the test run on every bar.

Common errors and gotchas

  • Same value on every bar. CurrentYear describes the calendar, not the chart, so a condition such as CurrentYear = 2026 is true or false for the entire calculation at once. Per-bar year logic needs Year.
  • Backtest blind spot. In a backtest CurrentYear returns the year the test executes, so year filters built on it pass or block wholesale and produce results that do not match live behavior.
  • Market time zone, not local time. The year is referenced to the instrument's market and does not adjust for the viewer's local offset.
  • No bracket offset. CurrentYear[1] does not compile. Only per-bar constants such as Year[N] accept an index.
  • Year, four-digit year of the close of each bar, the per-bar sibling of this constant.
  • OpenYear, year at the open of each bar.
  • CurrentMonth, month of the clock at execution time.
  • CurrentHour, hour of the clock at execution time.
  • CurrentTime, full clock time at execution as an HHMMSS integer.
  • Month, month of each bar.
  • Day, day of the month of each bar.
  • TIME, closing time of each bar as an HHMMSS integer.