I have a simple for loop script that I grabbed from one of Matthew's videos to count the number of occurrences of a specific instance happening on my chart.
I also have these same instances plotted on the chart with the plotshape() function just so that I can double check the accuracy of the for loop count...and there is a big difference in the result!
The for loop
Code: Select all
positiveBars = 0
for i = (lookback - 1) to 0
if (high[i] < HH75 and low[i] > LL25)
positiveBars := positiveBars + 1
positiveBarsPercent = (positiveBars / lookback) * 100
Code: Select all
length = input(5)
HH = highest(high, length)
LL = lowest(low, length)
HH75 = HH-(HH-LL)*0.25
LL25 = LL+(HH-LL)*0.25