0

试图绘制所有先前柱的累积变化百分比获取错误:获取未声明的标识符'accum'

indicator("Accumalated Change Percentage")
change = (close - close[1]) / close * 100 // change of current bar in percentage
accum = nz(accum + change)
plot(accum)

如果我在使用它之前声明 accum 它不会累积这是我想要做的

4

2 回答 2

1
//@version=5
indicator("Accumalated Change Percentage")

var float   accum = na

change = ta.change(close) / close * 100
accum := nz(accum + change)

plot(accum)
于 2021-12-18T13:27:41.500 回答
0

我喜欢 Bjorn 的第一个答案,因为它可以适应累积其他运算而不仅仅是加法,我试图了解它如何产生累积效应。

到目前为止,我一直在使用下面的ta.cum内置函数,它似乎适用于累积加法的特定目的。

//@version=5
indicator("Accumulated Change Percentage")
change = ta.change(close) / close * 100
accum = ta.cum(change) 
plot(accum)
于 2021-12-18T18:21:28.663 回答