Thanks.
input lookback = 40;
# if while is used, fold loops as long as while statement is true
# when while becomes false, the loop stops, even if fold hasn't reached the highest count value
def bigbarcnt = fold k = 1 to lookback
with p
while (high > getvalue(high, k) and low < getvalue(low, k))
do p + 1;
What happens when lookback reaches 41? Does the while process stop? Does it keep going but start over? To keep this code operating like a traditional while statement and to be safe would a very large lookback number be used so the condition will be found before the lookback is reached?
i updated the link in my post #2.
in that code i ran a loop to 40, to look for a condition, that i thought should happen within 20 bars.
if you are unsure when a condition would become true to trigger the while statement, yes, you can loop to a big number. i would keep it < 500. experiment to find out what is realistic.
--------------------
lookback is a constant, it won't change. it will be 40 until the user types in a different number.
regarding this, and assuming there is no while statement,
input lookback = 40;
fold k = 1 to lookback...
with a to value of 40,
on each bar, k will count up to 39.
when k=39 , it will process the formulas within the loop, then stop. k won't reach 40. it won't process k being equal to 40.
if a while statement is used in a fold, and the while formula becomes false, the loop will stop and the program will procede to the next code line.