如何在TradingView中绘制上一年最后一个交易日收盘价的水平线?

How to plot a horizontal line in TradingView at the closing price of the last trading day of the previous year?

我是 pine-script 的新手,我认为这很简单,但我现在已经苦苦挣扎了几个小时,但没有太大的成功。如果能帮助我弄清楚如何以最后一个交易日的收盘价绘制一条水平线,我将不胜感激。这是我尝试创建的示例。

这应该可以做到。

//@version=5
indicator("My Script", overlay=true)

var line    myLine          = line.new(na, na, na, na, extend=extend.right, color=color.red)
var float   prevYearClose   = na

if year != year[1]
    // Move line
    line.set_xy1(myLine, bar_index-1, close[1])
    line.set_xy2(myLine, bar_index  , close[1])