You can use this indicator to detect the levels and trend.
I used the highest of the two last highest pivots and the lowest of the two last lowest pivots to calculate "max" and "min" or high level or low level.
I also calculate the average of the 4 values to reach the average line which could be a trend detector in higher lengths.
Default length is 3 but using 10 or 20 as length is really good as trending detector.
I need help to upgrade a trend detector system. please read the script for more information.