Reputation: 115
I would like to get the number of bars elapsed year-to-date since the beginning of the year in pine-script.
I am using pine-script v5.
Upvotes: 0
Views: 684
Reputation: 2161
ta.barssince()
function counts the number of bars since the last time a condition was true.
ta.change()
function checks for changes in a value.
You can combine those functions, and check the amount of bars since the last time a year changed:
barsSinceBeginingOfYear = ta.barssince(ta.change(time("12M")))
Upvotes: 2