Date and time/probuilder · probacktest · proorder · proscreener

CurrentMonth

CurrentMonth returns the month of the clock at execution time, 1 to 12, identical on every bar of the chart. Use Month to read the month of each bar's close.

Syntax

probuilder
CurrentMonth

How it works

CurrentMonth reads the clock at the moment the code runs and returns the calendar month, from 1 for January to 12 for December. 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 October returns 10 on every historical bar. The per-bar sibling is Month, which returns the month of the close of each bar being processed and changes along the time axis. Seasonal logic applied to historical data belongs with Month; CurrentMonth describes the calendar now.

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

Examples

Example 1, Halloween month flag (Indicator)

probuilder
// Set the flag when the script executes during October
IF (CurrentMonth = 10) THEN
    HalloweenMonth = 1
ELSE
    HalloweenMonth = 0
ENDIF
RETURN HalloweenMonth

The indicator plots 1 across the whole chart when recalculated during October market time, and 0 in any other month.

Example 2, Scan restricted to a season (ProScreener)

probuilder
// Return matches only during the fourth quarter
inQ4 = (CurrentMonth >= 10) AND (CurrentMonth <= 12)
SCREENER[inQ4 AND close > Average[50](close)] (close AS "Close")

The screener returns an empty list outside October, November and December, a way to keep a scan active only during a chosen season.

Example 3, Month-gated strategy (ProOrder)

probuilder
// Skip new entries during the summer month of August
DEFPARAM CumulateOrders = false
IF CurrentMonth = 8 THEN
    QUIT
ENDIF
IF close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

Live, the system stops itself for the whole of August. Backtests cannot exercise this branch meaningfully, because CurrentMonth holds the month of the test run on every bar.

Common errors and gotchas

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