gpt4 book ai didi

pine-script - Tradingview Pinescript 使用 := operator

转载 作者:行者123 更新时间:2023-12-05 00:59:38 28 4
gpt4 key购买 nike

我想了解 := 和 sum[1] 如何工作。这个总和返回 6093。但是总和是 0,也是 sum[1] = 0 ,对吗?它如何返回我 6093?我搜索了tradingview wiki,但我不明白。我想将此代码更改为另一种语言,例如 javascript、c#

testfu(x,y)=>
sum = 0.0
sum:= 1+ nz(sum[1])
sum

最佳答案

[]在 pine-script 中被称为 History Referencing Operator 。这样,就可以引用任何系列类型变量的历史值(该变量在前一根柱线上的值)。例如,close[1]返回昨天的收盘价 - 这也是一个系列。

所以,如果我们分解您的代码(从第一个小节开始):

testfu(x,y)=>
sum = 0.0 // You set sum to 0.0
sum:= 1+ nz(sum[1]) // You add 1 to whatever value sum had one bar ago
// which is 0, because it's the first bar (no previous value)
sum // Your function returns 1 + 0 = 1 for the very first bar

现在,第二个小节:

testfu(x,y)=>
sum = 0.0 // You set sum to 0.0
sum:= 1+ nz(sum[1]) // You add 1 to whatever value sum had one bar ago
// which is 1, because it was set to 1 for the first bar
sum // Your function now returns 1 + 1 = 2 for the second bar

等等。

看看下面的代码和图表。该图表有 62 个柱,和 sum开始于 1一直到 62 .

//@version=3
study("My Script", overlay=false)

foo() =>
sum = 0.0
sum:= 1 + nz(sum[1])
sum

plot(series=foo(), title="sum", color=red, linewidth=4)

enter image description here

关于pine-script - Tradingview Pinescript 使用 := operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52903577/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com