Search code examples
pine-scriptstock

How do I draw a horizontal line from the third friday close of every month in Pinescript?


Below I have the background color of the third friday of every month and a closing line for every week. I would like to set the closing line only for the third friday. Can anyone point me in the right direction?

//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)

Solution

  • //@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)
    

    enter image description here