【问题标题】:Pick closing value of last Thursday of month选择当月最后一个星期四的收盘价
【发布时间】:2022-12-04 06:11:51
【问题描述】:

我需要选择每月最后一个星期四的收盘价,然后对其应用标准偏差。我该怎么做?如果星期四是交易假期,那么它应该是星期三而不是星期五。

我在这里看到一个代码 - Pine Script / Trading View - Calculating Trading Day of Month (TDOM) 但我不知道如何将其更改为我想要的。

【问题讨论】:

    标签: 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-26
      • 2021-02-19
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多