如何在FOR循环中进行一系列计算?



我必须做一堆计算,只有一个参数改变。

例如:

Calculation100 = Something100 + SomethingElse100[1] * Other100 / Another100
Calculation110 = Something110 + SomethingElse110[1] * Other110 / Another110
.
.
.
Calculation1120 = Something1120 + SomethingElse1120[1] * Other1120 / Another1120

或者同样的例子,用更概念化的方式:

for n = 10 to 112 
Calculation(n*10) = Something(n*10) + SomethingElse(n*10)[1] * Other(n*10) / Another(n*10)

如何在Pine Script V5中工作,而不是手动制作它们?

如果你可以把它们放在数组中,你可以使用循环。

//@version=5
indicator("My script")
Calculation100 = Something100 + SomethingElse100[1] * Other100 / Another100
var calculation = array.new_float()
var something = array.new_float()
var somethingElse = array.new_float()
var other = array.new_float()
var another = array.new_float()
len = array.size(something)
for i=0 to len-1
sth = array.get(something, i)
sthe = array.get(somethingElse, i)
oth = array.get(other, i)
anoth = array.get(another, i)

val = sth + sthe * oth / anoth

array.push(calculation, val)
plot(close)