Date and time/probuilder · probacktest · proorder · proscreener

OpenDay

OpenDay returns the day of the month (1 to 31) on which the current bar opened in ProBuilder. Useful for logic tied to specific calendar days each month.

Syntax

probuilder
OpenDay

How it works

OpenDay reads the opening timestamp of the current bar and returns its day-of-month component as an integer between 1 and 31. The keyword takes no parameters and needs no market data, it operates purely on the date attached to the bar.

The keyword belongs to the Open family, which describes when a bar opened. The bare sibling Day describes the bar's closing date instead. On intraday and daily bars the two usually match, but on weekly or monthly bars, or on any bar spanning midnight, the opening and closing days can differ.

Since the value is a day-of-month, it says nothing about the weekday. A condition on OpenDay = 1 fires on the first calendar day present in the data, which may be a different weekday every month, and may be skipped entirely when the first falls on a weekend and no bar opens that day.

Common applications include start-of-month entries, monthly rebalancing anchors, and studies of behavior around recurring calendar days such as option-related dates.

Examples

Example 1, Detect a bar opening on the first of the month (Indicator)

probuilder
// Check whether the current bar opened on day 1 of the month
iDay = OpenDay
if iDay = 1 then
  // code for bars opening on the first calendar day
  firstDay = 1
else
  firstDay = 0
endif
RETURN firstDay

The indicator plots 1 for bars that opened on the first day of a month and 0 otherwise, making calendar turns visible on the chart.

Example 2, Start-of-month entry (ProBacktest)

probuilder
// Buy on the first bar opening in the first three days of each month
startOfMonth = OpenDay <= 3 AND OpenDay[1] > 3

IF startOfMonth AND NOT LONGONMARKET THEN
  BUY 1 SHARES AT MARKET
ENDIF

Comparing the current and previous values catches the transition into a new month even when day 1 falls on a weekend and the first traded bar opens on day 2 or 3.

Example 3, Screen only early in the month (ProScreener)

probuilder
// Match strong instruments during the first week of the month
earlyMonth = OpenDay <= 7
strong = close > Average[50](close)

SCREENER[earlyMonth AND strong] (OpenDay AS "Open day")

The screener limits results to bars opening in the first seven calendar days, with the opening day shown as the result column.

Common errors and gotchas

  • Open day versus close day. OpenDay refers to the bar's opening date. The sibling Day follows the closing date and can differ on bars that span midnight or a month boundary.
  • Day 1 may not exist in the data. When the first of the month falls on a non-trading day, no bar opens on day 1. Test a small range such as OpenDay <= 3 combined with a transition check instead of exact equality.
  • Calendar day, not weekday. Values 1 to 31 index the day of the month. For weekday logic such as Monday filters, use OpenDayOfWeek.
  • Fires on every matching bar. On intraday charts, OpenDay = 1 is true for all bars opening that day. Combine with a transition test or a time condition to act only once.
  • Day, day of the month of a bar's closing date, the sibling form of OpenDay.
  • OpenDate, full opening date of the current bar in YYYYMMDD format.
  • OpenDayOfWeek, weekday on which the current bar opened.
  • OpenMonth, month number in which the current bar opened.
  • OpenYear, year in which the current bar opened.
  • CurrentDayOfWeek, weekday of the machine clock.
  • Today, date of the current bar in YYYYMMDD format.