I want a Function to return the nature of the first weekly candle of the month in Pine Script.
This code uses changes in the week of the year to determine the week of the month:
//@version=5
indicator("weekOfMonth()")
weekOfMonth(timestamp = time) =>
var week = weekofyear(timestamp) %4
if ta.change(weekofyear(timestamp))
week += 1
if ta.change(month(timestamp))
week := 1
int result = timeframe.ismonthly ? na : week
plot(weekOfMonth())
How can I get the first weekly candle of the month in Pine Script?
New contributor
Niainarisoa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.