Date and time/probuilder · probacktest · proorder · proscreener

OpenMonth

OpenMonth returns the month, 1 to 12, at which the current bar opened. Use Month for the month of the bar's close and CurrentMonth for the calendar now.

Syntax

probuilder
OpenMonth

How it works

OpenMonth returns the calendar month at which the bar being processed opened, from 1 for January to 12 for December. 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.

OpenMonth is the open-based member of the month trio. Its siblings are Month, which reads the month of each bar's close, and CurrentMonth, which reads the month of the clock at the moment the code executes and is identical on every bar. On daily and shorter timeframes the open month and close month of a bar are almost always the same; the distinction matters mainly on weekly or monthly bars that straddle a month boundary.

The constant takes no parameters and no bracket offset. It suits seasonal logic that keys on the month a bar begins, such as isolating the first bar of a new month or filtering for a particular season.

Examples

Example 1, January open flag (Indicator)

probuilder
// Flag bars that opened in January
iMonth = OpenMonth
IF iMonth = 1 THEN
    openedInJan = 1
ELSE
    openedInJan = 0
ENDIF
RETURN openedInJan

The indicator plots 1 on bars whose open falls in January and 0 in every other month, a simple way to highlight the start of each year on the chart.

Example 2, Scan for fourth-quarter opens (ProScreener)

probuilder
// Match instruments whose latest bar opened in the fourth quarter
q4Open = (OpenMonth >= 10) AND (OpenMonth <= 12)
SCREENER[q4Open AND close > Average[50](close)] (OpenMonth AS "OpenMonth")

The screener returns only instruments whose most recent bar opened in October, November or December, with the open month shown alongside.

Example 3, New-month entry gate (ProOrder)

probuilder
// Allow entries only on the first bar of a new month
DEFPARAM CumulateOrders = false
newMonth = OpenMonth <> Month[1]
IF newMonth AND close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

The condition compares the open month of the current bar with the close month of the previous bar, so it is true on the first bar after a month change, giving a once-a-month entry gate.

Common errors and gotchas

  • Open, not close. OpenMonth reads the month of the bar's open. For the close use Month. The two rarely differ except on bars that span a month boundary.
  • Not the calendar now. OpenMonth is a per-bar value that changes along the chart. For the month of the moment the code runs, use CurrentMonth.
  • Carries no year. OpenMonth returns only the month number, so January 2025 and January 2026 look identical. Combine with OpenYear or Year when the year matters.
  • No bracket offset. OpenMonth[1] does not compile. To reach an earlier bar's month use Month[N].
  • Month, month of the close of each bar.
  • CurrentMonth, month of the clock at execution time.
  • OpenYear, year at the open of each bar.
  • OpenDay, day of the month at the open of each bar.
  • OpenTime, opening time of each bar 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.