Hi Everybody,
I’ve used the forum as a guest for a long time but first post.
I am trying to build an indicator that increments a value everytime (eachbar) that the IF statement is TRUE and de-increments the value on each bar it is FALSE.
So for example if the condition had been TRUE for 5 bars the value would equal 5, then if the next bar was FALSE value = 4 and so on.
Attempt 1 – using IF statements:
IF LOW > LowPointave THEN
LowAdd = LowAdd + 1
ELSE
LowAdd = LowAdd - 1
ENDIF
Result was the indicator just flipped between 1 and -1.
Attempt 2 – Using Loops
IF LOW > LowPointave THEN
i = 1
ELSE
i = 0
ENDIF
LowAdd = 0
WHILE i = 1 DO
LowAdd = LowAdd + 1
WEND
Result – “An infinite loop or loop with too many iterations was detected….”
What does this mean and is there any way I can meet my goal?
Thanks kindly ,
Jon
Your first example works. I tested this:
LowPointave = average[200](low)
IF LOW > LowPointave THEN
LowAdd = LowAdd + 1
ELSE
LowAdd = LowAdd - 1
ENDIF
return lowadd
and got this:
[attachment file=74309]
So it must be whatever your LowPointAve is that is the problem.
You are stuck in the loop between lines 4 and 8, it will never break because your variable i remains 1 infinitely…