The function should be called on each calculation for consistency, console output?

Viewed 7868

My script has just recently started to show these lines in console, when I add to chart or save.

"The function 'anonym_function_10' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope."
"The function 'anonym_function_11' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope." 

Need some help understanding this, wheather the code is compromised for accuracy, or this could be a possible problem in the future? What would be a solution to fix this?

// @version=4
f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]
f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]
f_fractalize(src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0

The last line is the one in question...

2 Answers

If your code is like this, you are likely to get this error.

mav = na(xem[1]) ? sma(src, len) : (xem[1] / len)`

try it like this ...

_sma= sma(src, len)
mav = na(xem[1]) ? _sma : (xem[1] / len)

Functions involving series variables need to be executed every bar so the function has a complete series history; otherwise series indexes inside the function will be incorrect. So Pine issues a warning for such functions when they are embedded inside a conditional expression, which might cause them not to be executed every bar.

To solve this, either execute the function at global scope, outside any conditional expressions, or redefine the function to accept individual series values as function arguments.

The latter solution would work in the OP's case.

See the explanation at "Execution of Pine functions and historical context inside function blocks" at https://www.tradingview.com/pine-script-docs/en/v4/language/Functions_and_annotations.html

Related