'长度的pinescript errorInvalid值' ta.highest()和ta.highestbars()中的参数(0.0)

发布于 2025-01-23 21:17:32 字数 387 浏览 0 评论 0原文

参考以下代码 绘制temp1给出了错误,而绘制temp2 plottest OK ???任何建议

//@version=5
indicator("HighBar Test", overlay=false)

var temp1 = 0
var temp2 = 0
var length_1 = 0
var length_2 = 0
length_1 := bar_index - bar_index[50]
length_2 := 50

// eample 1
temp1 := ta.highestbars(length_1)
//plot(temp1)

// example 2
temp2 := ta.highestbars(length_2)
plot(temp2)

plot(length_2)

referring to the code below
plotting temp1 gives the error whereas plotting temp2 plottest OK
??? any suggestions

//@version=5
indicator("HighBar Test", overlay=false)

var temp1 = 0
var temp2 = 0
var length_1 = 0
var length_2 = 0
length_1 := bar_index - bar_index[50]
length_2 := 50

// eample 1
temp1 := ta.highestbars(length_1)
//plot(temp1)

// example 2
temp2 := ta.highestbars(length_2)
plot(temp2)

plot(length_2)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-30 21:17:32

运行时错误在ta.highestbars()函数的长度=参数值的问题上指示该问题,该值应该是超过零的整数值。

在图表上的第一个49个bar中,bar_index [50]呼叫将返回 na ,因为参考尚不存在,因此bar_index -na == na,请注意,数学运算符不支持 na 值的计算。您可以使用内置的nz()函数进行替换:

//@version=5
indicator("HighBar Test", overlay=false)
length_1 = bar_index - nz(bar_index[50], -1)
temp1 = ta.highestbars(length_1)
plot(temp1)

The runtime error indicates on the issue with the ta.highestbars() function's length= argument value, which should be an integer value above zero.

enter image description here

During the first 49 bars on the chart, the bar_index[50] call would return na, as the reference is not existing yet, hence the bar_index - na == na, note that math operators do not support calculations with na values. You can protect it using the built-in nz() function with replacement:

//@version=5
indicator("HighBar Test", overlay=false)
length_1 = bar_index - nz(bar_index[50], -1)
temp1 = ta.highestbars(length_1)
plot(temp1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文