[]
在松树的脚本中称为
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)