Date and time/probuilder · probacktest · proorder · proscreener

Day

Day returns the day of the month, 1 to 31, of a bar on the chart. Day accepts a bracket offset such as Day[1] to read the day of an earlier bar.

Syntax

probuilder
Day[N]

How it works

Day returns the day of the month of the bar being processed, as an integer from 1 to 31. It reads the calendar date attached to each bar, so unlike the Current family it changes along the time axis: successive bars on a daily chart step through the days of the month, and the value resets after the last day of each month.

The optional index N selects a bar relative to the one being processed. Day[0], or plain Day, is the current bar. A positive N looks back: Day[1] is the previous bar, Day[5] is five bars back. The chart must hold enough history for the requested offset, otherwise the value is undefined at the left edge.

Day reports only the day number and carries no month or year. Comparing Day values across a month boundary can be misleading, since day 31 of one month is followed by day 1 of the next. For a full date use Day together with Month and Year, or reach for Days and Timestamp when you need a single monotonic value.

Examples

Example 1, Day of the previous bar (Indicator)

probuilder
// Retrieve the day of the month from the previous bar
myDay = Day[1]
RETURN myDay

The indicator plots the day-of-month number of the bar immediately before each processed bar, a stepped line that climbs through the month and drops at each month change.

Example 2, Scan for start-of-month bars (ProScreener)

probuilder
// Match instruments whose latest bar falls in the first three days of a month
earlyInMonth = Day <= 3
SCREENER[earlyInMonth AND close > Average[20](close)] (Day AS "Day")

The screener returns only instruments whose most recent bar sits in the opening days of a calendar month, with the day number shown alongside.

Example 3, First-trading-day filter (ProOrder)

probuilder
// Allow entries only when a new month has just started
DEFPARAM CumulateOrders = false
newMonthStart = Day < Day[1]
IF newMonthStart AND close CROSSES OVER Average[20](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

The condition Day < Day[1] is true on the first bar of a new month, because the day number drops from a high value back to 1. The strategy uses that as a once-a-month entry gate.

Common errors and gotchas

  • Day of the month, not of the week. Day returns 1 to 31, the calendar day. For the weekday use DayOfWeek.
  • No month or year. Day carries only the day number, so day 5 in March and day 5 in April look identical. Combine with Month and Year for a full date.
  • Month boundaries. A test such as Day > Day[1] fails on the first bar of a month because the number resets to 1. Handle the rollover explicitly when comparing across bars.
  • Offset beyond history. Day[N] needs N bars of history. Near the left edge of the chart the value is undefined.
  • OpenDay, day of the month at the open of each bar.
  • Month, month of each bar, pairs with Day for a full date.
  • Year, four-digit year of each bar.
  • DayOfWeek, weekday of each bar, 1 for Monday to 7 for Sunday.
  • Days, whole days elapsed since 1 January 1900 up to each bar.
  • TIME, closing time of each bar as an HHMMSS integer.
  • Timestamp, UNIX time of the close of each bar.
  • Yesterday, date of the day before a bar, in YYYYMMDD form.