松脚本初学者问题使用数组 -->创建一个新的现有覆盖一些值



不知道,为什么我在互联网上找不到我的简单问题的答案。 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)

提前非常感谢你。

Pine 中没有数组,有系列并且它们是不可变的。您可以使用 barstate.islast 覆盖最后一个条形图:

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

更新

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

//@version=4
study("My Script")
plot(close)
LastClose = barstate.islast and not barstate.isconfirmed ? close : na
plot(LastClose, offset=1)

最新更新