I got the Calculation error: ‘Error in the indicator… A positive integer field is expected with Count’
Decrease = Close < Close[1]
Count = 0
FOR i = 1 TO BarIndex DO
IF Decrease[Count] THEN
Count = Count - 1
ELSE
BREAK
ENDIF
NEXT
RETURN Count
I have to re-code it as
Decrease = Close < Close[1]
Count = 0
FOR i = 1 TO BarIndex DO
IF Decrease[Count] THEN
Count = Count + 1
ELSE
BREAK
ENDIF
NEXT
n = 0 - Count
RETURN n
Why ?
If you discovered how to work it out correctly it’s because you got the hang of it!
You answered your own question. If a negative integer is not allowed then don’t use one and use a positive one that is allowed instead!
Because COUNT variable is sometimes negative! 😉 Not possible to use a variable with a negative offset!
Decrease[-1] will flash that error.
Haha. Now I realized my mistake. I copy this example somewhere without realizing that it use the Count to index. I ‘assume’ it use the variable i to index.
The correct code should be
Decrease = Close < Close[1]
Count = 0
FOR i = 0 TO BarIndex - 1 DO
IF Decrease[i] THEN
Count = Count - 1
ELSE
BREAK
ENDIF
NEXT
RETURN Count
I learn the danger pf copy/paste code.
Thks everyone for taking interest and interesting comments. Cheers.