The week number of the year for the current bar's open time, starting at 1.
weekofyear is a series int that counts weeks through the year and resets when the year changes. weekofyear != weekofyear[1] marks the first bar of each week and keeps working across a change of year.
Type
series int
Remarks
- weekofyear[n] is na before the first bar.
- On Sidechair: weeks follow ISO 8601: they start on Monday and week 1 is the week with the year's first Thursday, so the last days of December can be week 1 and the first days of January can be week 52 or 53.
Example
//@version=6
indicator("Alternate weeks", overlay = true)
odd = weekofyear % 2 == 1
bgcolor(odd ? color.new(color.gray, 90) : na)
plot(weekofyear, "Week", display = display.data_window)See also
Runs on Sidechair