Date and time/probuilder · probacktest · proorder · proscreener

Month

Month returns the month number (1 to 12) of a bar's closing date in ProBuilder. Use the [N] offset for seasonal filters and month-of-year trading logic.

Syntax

probuilder
Month[N]

Parameters

NameTypeDefaultDescription
Ninteger0Bar offset. 0 reads the current bar, 1 the previous bar, and so on. When omitted, the current bar is read.

How it works

Month extracts the month component from the date associated with a bar. The value comes from the bar's closing timestamp, so a weekly bar that opens on 30 June and closes on 4 July reports Month = 7. The sibling keyword OpenMonth reads the opening date of the same bar and would report 6 in that case. On most intraday and daily bars the two agree, but they can differ on any bar that straddles a month boundary.

The returned value is an integer from 1 (January) to 12 (December). No market data is involved, the keyword operates purely on the timestamp attached to each bar, so it works identically on any instrument.

The [N] offset reads the month of earlier bars. Month[1] is the month of the previous bar's close, which is a simple way to detect a month change: when Month <> Month[1] the current bar is the first one closing in a new month.

Typical uses include seasonal studies, excluding specific months from a backtest, and triggering monthly rebalancing logic.

Examples

Example 1, Check whether the previous bar closed in December (Indicator)

probuilder
// Read the closing month of the previous bar
lastMonth = Month[1]
IF lastMonth = 12 THEN
  itWereChristmasMonth = 1
ELSE
  itWereChristmasMonth = 0
ENDIF
RETURN itWereChristmasMonth

The indicator plots 1 when the previous bar closed in December and 0 otherwise. The [1] offset shifts the reading one bar back.

Example 2, Seasonal long-only window (ProBacktest)

probuilder
// Only hold longs from November through April
inSeason = Month >= 11 OR Month <= 4

IF inSeason AND close CROSSES OVER Average[100](close) THEN
  BUY 1 SHARES AT MARKET
ENDIF

IF NOT inSeason AND LONGONMARKET THEN
  SELL AT MARKET
ENDIF

The strategy takes trend entries only during the November to April window and flattens any open long once the calendar leaves the season. Note the OR combination, the window wraps around the year end.

Example 3, Screen for a January close (ProScreener)

probuilder
// Match instruments whose latest bar closed in January above its 200-bar average
inJanuary = Month = 1
aboveTrend = close > Average[200](close)

SCREENER[inJanuary AND aboveTrend] (Month AS "Month")

The screener returns instruments trading above their long average on bars that closed in January, displaying the month number as the result column.

Common errors and gotchas

  • Close date, not open date. Month reads the bar's closing timestamp. Weekly or monthly bars that straddle a month boundary report the later month. Use OpenMonth when the opening date is the relevant one.
  • Months start at 1. The range is 1 to 12, there is no month 0. Conditions like Month = 0 never match and off-by-one conversions from zero-based systems produce silent logic errors.
  • Year-end windows need OR. A season such as November through April spans the year boundary. Month >= 11 AND Month <= 4 never matches, the correct form is Month >= 11 OR Month <= 4.
  • Detecting month changes. Comparing against a constant fires on every bar of that month. To act once per month, compare consecutive bars with Month <> Month[1].
  • OpenMonth, month of the current bar's opening date, the sibling form of Month.
  • CurrentMonth, month of the machine clock rather than a bar timestamp.
  • Day, day of the month of a bar's closing date.
  • Year, year of a bar's closing date.
  • Today, date of the current bar in YYYYMMDD format.
  • Hour, hour component of a bar's closing time.
  • DayOfWeek, weekday of a bar's closing date.