Date and time/probuilder · probacktest · proorder · proscreener

CurrentDayOfWeek

CurrentDayOfWeek returns the weekday from the clock at execution time, 0 Sunday to 6 Saturday, the same on every bar, unlike the per-bar DayOfWeek value.

Syntax

probuilder
CurrentDayOfWeek

How it works

CurrentDayOfWeek reads the clock at the moment the code executes and returns the weekday as an integer. ProRealTime™ uses the time zone of the instrument's market as the reference, so the value can differ from the weekday on the machine displaying the chart. The constant takes no parameters and accepts no bracket offset.

The value follows the platform convention of 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on up to 6 for Saturday.

Because the number comes from the clock rather than from chart data, every bar in a calculation sees the same value. An indicator recalculated on a Tuesday returns 2 on every historical bar of the chart. This is the defining difference from the sibling constant DayOfWeek, which returns the weekday of the close of each bar being processed and therefore changes along the time axis. Conditions that filter historical bars by weekday belong with DayOfWeek; CurrentDayOfWeek answers the question of which day it is right now.

In a live ProOrder system the two values usually coincide on the most recent intraday bar, since the strategy processes bars in real time. In a backtest they diverge completely: CurrentDayOfWeek reflects the day the test runs, not the day of any historical bar.

Examples

Example 1, Flag a specific weekday (Indicator)

probuilder
// Set the flag when the script executes on a Wednesday
IF (CurrentDayOfWeek = 3) THEN
    Wednesday = 1
ELSE
    Wednesday = 0
ENDIF
RETURN Wednesday

The indicator plots 1 across the whole chart when it recalculates on a Wednesday, and 0 otherwise, illustrating that the value does not vary per bar.

Example 2, Friday-only scan (ProScreener)

probuilder
// Return matches only when the scan itself runs on a Friday
isFriday = (CurrentDayOfWeek = 5)
SCREENER[isFriday AND close > Average[20](close)] (close AS "Close")

The screener produces results only when executed on a Friday, regardless of the dates of the bars it scans.

Example 3, Weekend guard on a 24/7 market (ProOrder)

probuilder
// Stand aside at the weekend on a market that trades every day
DEFPARAM CumulateOrders = false
weekend = (CurrentDayOfWeek = 0) OR (CurrentDayOfWeek = 6)
IF NOT weekend AND close > Average[50](close) THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

Live, the filter blocks new entries on Saturdays and Sundays. In a backtest the same code filters nothing meaningful, because every historical bar sees the day the test runs; a historical version of this filter needs DayOfWeek.

Common errors and gotchas

  • Constant across the whole chart. Every bar evaluates to the same number, the weekday of the moment of execution. Using CurrentDayOfWeek to filter historical bars silently passes or blocks the entire chart at once. Use DayOfWeek for per-bar conditions.
  • Sunday numbering. The platform manual defines the range as 0 for Sunday through 6 for Saturday. Some references number the week 1 through 7 with Sunday as 7. Monday through Saturday agree in both schemes; verify Sunday handling on a live chart before depending on it.
  • Backtest results that cannot reproduce live behavior. A weekday filter built on CurrentDayOfWeek behaves correctly in live execution but is untestable historically, so backtest statistics for such a system do not reflect the live filter.
  • No bracket offset. CurrentDayOfWeek[1] is invalid. The constant has no history to index into; only the per-bar constants such as DayOfWeek[N] accept an offset.
  • DayOfWeek, weekday of the close of each bar, the per-bar sibling of this constant.
  • OpenDayOfWeek, weekday at the open of each bar.
  • CurrentTime, clock time at execution as an HHMMSS integer.
  • CurrentHour, hour of the clock at execution time.
  • CurrentMinute, minute of the clock at execution time.
  • CurrentMonth, month of the clock at execution time.
  • CurrentYear, year of the clock at execution time.
  • Day, day of the month at the close of each bar.