应该在每次计算时调用该函数以保持一致性,控制台输出



当我添加到图表或保存时,我的脚本最近刚刚开始在控制台中显示这些行。

"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." 

需要一些帮助来理解这一点,是代码的准确性受到了损害,还是这可能是未来的一个问题?有什么解决方案可以解决这个问题?

// @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

最后一行是有问题的。。。

如果您的代码是这样的,则很可能会出现此错误。

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

试着这样。。。

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

涉及系列变量的函数需要在每个小节执行,因此函数具有完整的系列历史;否则函数内的系列索引将不正确。因此,当这些函数嵌入到条件表达式中时,Pine会对它们发出警告,这可能会导致它们不能在每个小节中执行。

若要解决此问题,请在任何条件表达式之外的全局范围内执行函数,或者重新定义函数以接受单独的序列值作为函数参数。

后一种解决方案适用于OP。

参见";Pine函数的执行和函数块内部的历史背景";在https://www.tradingview.com/pine-script-docs/en/v4/language/Functions_and_annotations.html

f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0
Below is alternative
f_fractalize(_src)=>
bool rhign = f_top_fractal(_src)
bool rlow = f_bot_fractal(_src)
if rhign
1
else if  rlow
-1
else
0

相关内容

最新更新