FDL
FDL

Reputation: 115

How do I get the number of bars elapsed year-to-date since beginning of the year?

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

Answers (1)

mr_statler
mr_statler

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

Related Questions