Does anyone know how to track which event (high or low) came first on an outside bar (high > high1 and low < low1)?
For instance, if there are 4 lower lows in a row and the new bar breaks the previous low first, the lower low counter would be reassigned to 5. Later in the day, the high breaks the previous high. The lower low count would remain at 5 and the higher high count would be reassigned to 0.
If however if the new bar breaks the previous high first, the lower low counter would remain at 4 and the higher high would would be reassigned to 1. Later in the day, the low breaks the previous low. The higher high count would remain at 1 and the lower low count would be reassigned to 0.
This is the code I have so far which basically does what I want until an outside bar occurs. I understand why counts reset to 0 when both higher high and lower low are true and that's what I'm trying to overcome. Attached is a screenshot of a similar scenario. It counts 8 bars until the high breaks the previous high on an outside bar. With my code, I get 7 and then it resets to 0.
//@version=5
indicator("Count High's & Low's")
var hh = 0
var ll = 0
for i = 0 to bar_index
if high <= high[1]
ll := ll + 1
break
if high > high[1]
ll := 0
for i = 0 to bar_index
if low >= low[1]
hh := hh + 1
break
if low < low[1]
hh := 0
plot(ll, color = color.red)
plot(hh, color = color.green)