I'm trying to plot a horizontal line (extended in both directions) at every pivothigh/pivotlow value. I'm almost there but I'm getting stuck at the last point. Could someone help me out? This is just a dummy code using only ta.pivothigh() to show where I'm getting stuck.
//@version=5
indicator(title="test", shorttitle="test", overlay=true)
pivotLength = 100
highOffset = high[pivotLength]
pivotHigh = ta.pivothigh(high, pivotLength, pivotLength)
yValues = ta.valuewhen(not na(pivotHigh), highOffset, 0)
line levelLine = line.new(bar_index, yValues, bar_index - 1, yValues, extend = extend.both) // <= getting stuck here
Unfortunately, I'm only repeatedly plotting the last horizontal line (levelLine). I don't know how to plot the previous horizontal lines (yes, I'm aware that if there are a lot of pivot values, not all horizontal lines will be displayed due to Pine Script's limitations).