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

I'm new to pine-script and I thought this would be simple, but I'm struggling for a few hours now without much success. I would appreciate help with figuring out how to plot a horizontal line at the closing price of the last trading day. Here is an example of what I was trying to create.


This should do it. //@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])