【问题标题】:Pick closing value of last Thursday of month选择当月最后一个星期四的收盘价
【发布时间】:2022-12-04 06:11:51
【问题描述】:
标签:
pine-script
pinescript-v5
pine-script-v4
【解决方案1】:
Pine script 目前没有交易日日历,因此(据我所知)不可能检查它是否是最后交易日。
我们可以检查我们是否在last week of the month 上,此外还可以检查是否是星期四。它不会适用于所有情况(例如,在最后一周星期四没有交易日的情况下)但它在大多数情况下都适用。
//@version=5
indicator("My Script", overlay = true)
f_is_leap_year() =>
if ((year % 4) != 0)
false
else if ((year % 100) != 0)
true
else if ((year % 400) == 0)
true
else
false
f_get_last_day() =>
if (month == 1) or (month == 3) or (month == 5) or (month == 7) or (month == 8) or (month == 10) or (month == 12)
31
else if (month == 4) or (month == 6) or (month == 9) or (month == 11)
30
else
f_is_leap_year() ? 29 : 28 // February
is_last_day = (f_get_last_day() == dayofmonth)
last_thursday = dayofmonth > f_get_last_day() - 7 and dayofweek == dayofweek.thursday
plotshape(last_thursday)