Sidechair

dayofweek()

Browse the reference

Returns the weekday of a UNIX timestamp, from 1 for Sunday to 7 for Saturday, in the exchange or a chosen time zone.

Try it in the editor

dayofweek(time, timezone) turns any timestamp in milliseconds into its weekday for the time zone you give. Use it on a stored value such as the time of an earlier signal, or on timestamp(...) results.

The dayofweek variable does the same thing for the bar being calculated, so write the variable when that is what you need.

Syntax

Pine Script
dayofweek(time: series int, timezone: series string (optional)) -> series int

Arguments

NameTypeDefaultDescription
timeseries intrequiredA UNIX timestamp in milliseconds (a value like time, time_close or timestamp(...)).
timezoneseries stringthe exchange time zoneThe IANA time zone name, such as "America/New_York", or a UTC offset such as "UTC-5" or "GMT+2". When left out, the exchange time zone of the chart symbol is used.

Returns

series int: The weekday, 1 (Sunday) to 7 (Saturday); compare with the dayofweek.* constants.

Remarks

  • A na timestamp returns na.
  • On Sidechair: the timezone argument takes the same names as timestamp() and defaults to the symbol's exchange time zone.

Example

Pine Scriptdayofweek() of a stored timeOpen in editor
//@version=6
indicator("dayofweek() of a timestamp", overlay = true)
var int signalTime = na
if ta.crossover(close, ta.sma(close, 20))
    signalTime := time
plot(dayofweek(signalTime, "UTC"), "dayofweek of last cross", display = display.data_window)
plot(ta.sma(close, 20), "SMA 20", color.gray)

See also

Runs on Sidechair