Shubham Surve
Shubham Surve

Reputation: 1

how to count number of days in a month in tradingview?

i want to count how many days were in a month and week for my further calculations in pine different months have different count of days so i am not getting a accurate results if i keep updating the previous count of days using a input function. Is there any function i can use so that i get the exact count of days in each month. for example: count of days in February month = 20 count of days in March month = 21 and i need to multiply this with 5 so if i keep updating these values my previous calculation are inaccurate. can any one tell me how to fix this.

Upvotes: 0

Views: 842

Answers (1)

StaticNoiseLog
StaticNoiseLog

Reputation: 1400

This should work:

days_in_month = 31 - (((month - 1) % 7) % 2)
if month == 2
    leap_day = iff(year % 4 == 0, 1, 0)
    days_in_month := 28 + leap_day

Upvotes: 1

Related Questions