I wish to create an indicator that plots the current, as well as previous, protected highs/lows of ranges. To do this I'm utilising Williams Fractals; in a bullish market, the protected low would be the last swing low before a break of structure, and the high of the range would not be determined until a new swing high followed by a swing low had occurred (i.e. if a swing high followed by a second swing high occurred, the script should keep updating until a high is followed by a swing low).
Thr issue I'm experiencing is not knowing the logic to use that tells Pine Script I'm only interested in the last swing low that occurred before the break, or that I'm waiting on the criteria of a subsequent swing low after a swing high to save as my range boundaries.
Any advice on which functions to utilise to achieve this would be greatly appreciated.
Using a fixed look back period does not appear to be appropriate as the number of bars back that the criteria was met is not always consistent. Also it's not the lowest low or highest high in a look back period, it's the first/last swing points in trying to plot.