This is a nice indicator to track corrections. Can you briefly explain how it works? Does it repaint? Thanks for posting!
it finds peaks and valleys, based on this,
input length = 10;
on every bar, it looks back 10 bars and forward 10 bars and checks if the current bar is,
..the highest , for a peak
..or the lowest, for a valley.
it uses code from robert, that uses a changing offset to look for valleys and peaks, so it can still find them on the last 10 bars. if this wasn't used , and it looked ahead 10 bars and tried to read from a bar that doesn't exist, there would be an error, and it wouldn't draw a line.
def offset = Min(length - 1, lastBar - bn);
it could redraw/undraw a line... during the last 10 bars on the chart.
it is looking at different quantities of bars in the future. when it gets to the 11th bar from the last, it won't change anymore.
sometimes 2 of the same, peak or valley, happen in a row. if they do, i wanted the 2nd one to be ignored, and the line from the first to keep going. i left in code to highlight every peak and valley, so users could see when one is skipped (no line from it)
this calculates the price level for a peak line,
def peak_line = if bn == 1 then 0 # if the 1st bar , set to 0
else if peak2 then close # if a peak occurs, read the close
else if valley2[1] then 0 # if a valley occurs , reset the price
else peak_line[1]; # if no signals , then read the previous value to keep it going.