I am getting this warning with my user function. Error is:
The function 'foo' should be called on each calculation for consistency. It is recommended to extract the call from this scope
This warning happens for many reasons it seems, one of which is doing a for loop on a series. For example:
foo()=>
for i = 0 to 5
if close[i] > 0 or close[i] < 0
break
if close < 10
foo()
This will throw the warning. However, it makes no sense! Because without the function call, there will be no consistency either!
For example, I can do:
if close < 10
for i = 0 to 5
if close[i] > 0 or close[i] < 0
break
And there won't be any consistency anyways! For loop will only run when close < 10, maybe alaways, maybe never! But for some reason, putting this into a function, now its inconsistent?
Please explain why is it so, and is it ever possible to use for loops on series in functions without such warnings?
EDIT:
Experimenting further, it seems even touching series is a no-no in functions?
foo()=>
a = close[1]
if close < 10
foo()
Is enough to give a warning. Is it documented somewhere? Why? Is there no work around?