I'm trying to make a swing failure indicator using the line.new() function. I was able to create it but I'm not sure how to stop it. Specifically, I'd like the line to stop when there is a close above. Right now, I'm just getting 100s of lines. Any ideas?
Code: Select all
//@version=6
indicator("Swing Failure", overlay=true)
sfw1 = high > high[1] and close < high[1] and close < open
sfw2 = high < high[1] and close < open[1] and close < open and close[1] > open[1]
sfw3 = low < low[1] and close > low[1] and close > open and close[1] < open[1]
// Initialize a horizontal line at a fixed price level
var line hl_line = na // Track the horizontal line object
var line hl_line2 = na // Track the horizontal line object
if (sfw1 or sfw2) and barstate.isconfirmed
hl_line := line.new(x1=bar_index[1], y1=high[1], x2=bar_index + 5, y2=high[1], color=color.rgb(0, 0, 0), width=2, style=line.style_solid, extend=extend.right)
if (sfw3) and barstate.isconfirmed
hl_line2 := line.new(x1=bar_index[1], y1=low[1], x2=bar_index + 5, y2=low[1], color=color.blue, width=2, style=line.style_solid, extend=extend.right)