\n","author":{"@type":"Person","name":"Klikerko"},"upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"
This should do it.
\n//@version=5\nindicator("My Script", overlay=true)\n\nvar line myLine = line.new(na, na, na, na, extend=extend.right, color=color.red)\nvar float prevYearClose = na\n\nif year != year[1]\n // Move line\n line.set_xy1(myLine, bar_index-1, close[1])\n line.set_xy2(myLine, bar_index , close[1]) \n
\n","author":{"@type":"Person","name":"Bjorn Mistiaen"},"upvoteCount":1}}}Reputation: 1097
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.
Upvotes: 1
Views: 2034
Reputation: 6905
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])
Upvotes: 1