I have updated the title of your question. The original title you entered did not include the very important detail about consecutive bars. The title I have selected will make it much easier for the rest of our audience to understand the context immediately and will assist those searching for these specific terms.
So the code needs to compute the percent difference from the low to the high. But we can also measure this value by computing the percent difference from high to low. I have included both in the solution.
The code includes user inputs to adjust the percent threshold and number of consecutive bars without modifying the code.
input percentThreshold = 5.0;
input consectutiveBars = 5;
# two ways to compute percent diff
# from low to high
def percentFromLow = 100 * (high / low - 1);
# from high to low
def percentFromHigh = AbsValue(100 * (low / high - 1));
# scan using computation from low to high
plot scan = Sum(percentFromLow >= percentThreshold, consectutiveBars) >= consectutiveBars;
# scan using the computation from high to low
#plot scan =Sum(percentFromHigh >= percentThreshold, consectutiveBars) >= consectutiveBars;