Loops is my weakness unfortunately... and I need to build a nested loop, unless it can be done differently somehow. Also this is in TradingView Pinescript v5.
So I have automated trendlines and I can capture crossings of each up or down at any point and time top_red_trendline_up_cross = ta.crossover(high, top_red_trendline_coordinates)
If I want to check previous candle high if it crosses that same line I would do: top_red_trendline_up_cross = ta.crossover(high[1], top_red_trendline_coordinates)
Or if previous candle high crosses 3 trend lines ago: top_red_trendline_up_cross = ta.crossover(high[1], top_red_trendline_coordinates[3])
And so on... FYI: each trend line becomes obsolete at some point one it is broken and new one is drawn, so the coordinates of the line change every time it happens.
Basically I want to write a loop which will look for these based on the input provided. The logic is: 1,1 | 1,2 | 1,3 | 1,4 | 2,x
2,1 | 2,2 | 2,3 | 2,4 | 2,x
y,1 | y,2 | y,3 | y,4 | y,a
How would I put it into the loop? Or nested loop? Tried this, but it shows these crossings at obviously wrong places =/
top_red_trendline_up_cross = false
for x = 0 to 10
for y = 0 to 10
top_red_trendline_up_cross := ta.crossover(high[x], top_red_trendline_coordinates[y])
plotshape(top_red_trendline_up_cross, style=shape.xcross, color=color.red, size=size.normal, location=location.abovebar)
I already got pretty advanced into Pinescript, but loops always kill me and you can't go around loops with such task.. Appreciate any help/suggestions!