如何在周期中进行一系列计算?

发布于 2025-02-05 09:32:58 字数 501 浏览 1 评论 0原文

我只需要更改一个参数,就必须进行一堆计算。

例如:

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脚本V5中起作用,而不是手动制作它们?

I have to make a bunch of calculations with only one parameter changing.

For example:

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

Or the same example in a more conceptual way:

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

How does it work in Pine Script V5, instead of making them manually?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

真心难拥有 2025-02-12 09:32:58

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

//@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)

If you can put those in an array, you can use a loop.

//@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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文