I ask for help. I write an indicator, but I'm stuck - I can't find a solution.
And so - there is some signal in history, a horizontal line is automatically drawn from it - an array is created. I adjust the number of displayed lines accordingly.
Accordingly, the displayed lines on their continuation have intersections with candles - that is, the candle closes above the line.
I need the lines that were crossed by the candles to be removed, well, or change color...
And accordingly, when a new signal appears, new lines appear...
Removal or color change occurs strictly after closing the candle above the line...
I tried a bunch of options - but not a single one works correctly...
I attach a code that I could not go beyond...
Thank you...
//@version=5
indicator("NHNHNHNH", overlay = true)
Kol_Linii = input(2, "Количество линий")
Signal = open[3] < close[3] and open[2] < close[2] and open[1] < close[1] and close < open and high[1] > high and high[1] > close[1] and high > open)
X_for_LINIA = ta.valuewhen(Signal, bar_index, 0)
Y_for_LINIA = ta.valuewhen(Signal, high, 0)
var b = array.new_float()
array.push(b, Y_for_LINIA)
peresechenie = ta.crossover(close, Y_for_LINIA)
var p = array.new_bool()
array.push(p, peresechenie)
if Signal
LINIA = line.new(X_for_LINIA, Y_for_LINIA,X_for_LINIA+1,Y_for_LINIA, extend = extend.right, color = color.fuchsia, width = 1)
var a = array.new_line()
array.push(a, LINIA)
var line_price = array.new_float()
array.push(line_price, line.get_price(LINIA, bar_index))
if array.size(a) > Kol_Linii
ln = array.shift(a)
line.delete(ln) `

You should use an array to store your lines.
Then, on each close, loop over all the lines in this array.
If the Y value of the line is inferior to the actual close (= the candle close is above the line), delete the line and delete the corresponding array row. I tested this code which works well :
I put a label with the size of the ArrayLine array and the value of the Y line for testing purpose, you can delete it :