【问题标题】:How do I draw a horizontal line from the third friday close of every month in Pinescript?如何在 Pinescript 中从每个月的第三个星期五收盘时画一条水平线?
【发布时间】:2021-02-22 02:41:14
【问题描述】:

下面我有每个月第三个星期五的背景颜色和每周的收盘线。我想只为第三个星期五设置收盘线。谁能指出我正确的方向?

//Third Friday background color

study(title="sauce", shorttitle="ss", overlay=true)
c = #c2c2c2
c1 = #aa8a8a
bgColor =
    (dayofweek == friday and dayofmonth < 22 and dayofmonth > 14) ? color(c1, 90) :
    (dayofweek == friday) ? color(c, 90) :
    color(#cbcbcb, 0)
bgcolor(color=bgColor)

//Weekly close

cwl = input(true, title="Previous Closing Weekly Line")
wclose = security(tickerid, 'W', close[1]) 
wcolor2 = purple
plot(cwl and wclose? wclose :na , title="Weekly_Close",style=circles, color=wcolor2, linewidth=3)

【问题讨论】:

    标签: pine-script stock


    【解决方案1】:
    //@version=4
    study(title="Help (sauce)", shorttitle="ss", overlay=true)
    c = #c2c2c2
    c1 = #aa8a8a
    
    //bgColor = (dayofweek == dayofweek.friday and dayofmonth < 22 and dayofmonth > 14) ? color.new(c1, 90) : (dayofweek == dayofweek.friday) ? color.new(c, 90) : color.new(#cbcbcb, 0)
    bgColor = color.white
    var wclose = 0.0
    tmpWclose = security(syminfo.tickerid, 'W', close[1])
    
    if dayofweek == dayofweek.friday and dayofmonth < 22 and dayofmonth > 14
        wclose := tmpWclose
        bgColor := color.new(c1, 90) 
    else
        bgColor := color.new(#cbcbcb, 0)
    
    bgcolor(color=bgColor)
    
    //Weekly close
    cwl = input(true, title="Previous Closing Weekly Line")
    wcolor2 = color.purple
    plot(cwl and wclose? wclose : na , title="Weekly_Close", style=plot.style_circles, color=wcolor2, linewidth=3)
    

    【讨论】:

    • 有什么方法可以在日间绘制(在日线图上)?
    • 有什么问题?只需将时间范围更改为 D,一切正常。
    • 谢谢!关闭 [1] 是问题所在。我将其更改为 close[0] ,现在这条线似乎处于正确的价格。我认为这可能是由于不同的@version。还将“W”更改为“D”。
    • 知道如何绘制紫色线范围的高/低吗?谢谢。
    • 最简单的方法是使用security,例如。对于年度高点,`highW=security(syminfo.ticker, "W", highest(close,52))'。
    【解决方案2】:

    将脚本翻译成 pine v4。由于dayofweek 函数行为,该脚本仅适用于日内时间范围。

    //@version=4
    study(title="sauce", shorttitle="ss", overlay=true)
    c = #c2c2c2
    c1 = #aa8a8a
    
    bool isThirdFriday = dayofweek == dayofweek.friday and dayofmonth < 22 and dayofmonth > 14
    
    bgColor = 
      isThirdFriday ? color.new(c1, 70) : 
      dayofweek == dayofweek.friday ? color.new(c, 90) : 
      color.new(#cbcbcb, 0)
      
    bgcolor(color=bgColor)
    
    var float thirdFridayClose = na
    if not isThirdFriday and nz(isThirdFriday[1])
        thirdFridayClose := close[1] // 'open' for daily timeframe
    
    plot(thirdFridayClose)
    

    【讨论】:

    • 有什么方法可以在日间绘制(在日线图上)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    相关资源
    最近更新 更多