Pine Script初学者问题与数组一起使用->从现有覆盖范围创建新值

时间:2020-06-01 11:44:36

标签: pine-script indicator

不知道,为什么我无法为我的简单问题在互联网上找到答案。 PineScript中的新功能,我唯一想做的就是基于一些指定值以及输入作为源来创建自己的数组,并从中获取sma:

src = input(close, title="Source")
length = 10
lastBar = 1234 //overwrite the last bar of the input source

newSource[0]=lastBar

for i = 1 to length-2
     newSource[i] = src[i]

newSMA= sma(foreCastSourceFull, length)
plot(newSMA, color=orange)

非常感谢您。

1 个答案:

答案 0 :(得分:1)

Pine中没有数组,有series,它们是不可变的。您可以使用barstate.islast覆盖最后一个栏:

await

更新

如果要复制最后一个柱线,请使用以下脚本(仅适用于活跃市场):

//@version=4
study("My Script")
newSource = barstate.islast ? 1234 : close
newSMA = sma(newSource, 10)
plot(newSMA)