I would like to know if someone could help me with this part code. I have 2 arrays of lines, one for support and one for resistance. I would like to be able to detect when one line is testing a candle but just for last candle crossing. I got this so far but this code just check previous candle.
for i = 0 to support.size() - 1
if (high[1] > support.get(i).get_y1() and math.max(open[1],close[1])< support.get(i).get_y1()) or (low[1] < support.get(i).get_y1() and math.min(open[1],close[1])> support.get(i).get_y1())
lastCrossedBar := bar_index
deleteLine := true
if deleteLine
line.delete(support.get(i))
for i = 0 to resistance.size() - 1
if (high[1] > resistance.get(i).get_y1() and math.max(open[1],close[1])< resistance.get(i).get_y1()) or (low[1] < resistance.get(i).get_y1() and math.min(open[1],close[1])> resistance.get(i).get_y1())
lastCrossedBar := bar_index
deleteLine := true
if deleteLine
line.delete(resistance.get(i))
Thank you!
[]in pinescript is called history reference operator.If you use it like
[1]it will refer to the previous candle. So, just remove them and if you want to avoid repainting addbarstate.isconfirmedas an additional condition to the cross.