...mod note: moved from the quoted thread
So basically look forward (to a pre-determined max # of bars) until our condition equals true and retrieve that bar number. Is that doable?
Does anyone know if we can use fold to traverse 'the future'? I'm looking at a problem where I am trying to find the next time in the future a condition will be met and grab that bar number. But fold wants to start at zero and forward by default...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.
So basically look forward (to a pre-determined max # of bars) until our condition equals true and retrieve that bar number. Is that doable?
Last edited by a moderator: