简体   繁体   English

有没有办法在一次调用中将多个值 append 到 Pine Script 数组?

[英]Is there a way to append several values to a Pine Script array in a single call?

I want to have a function within which several if conditions looking for specific integer values.我想要一个 function 在其中几个if条件寻找特定的 integer 值。

The function in some situations might be called several times in sequence in order to return the resulting values of several different if conditions. function 在某些情况下可能会依次调用多次,以便返回几个不同if条件的结果值。

The idea I had for this, in order to reduce the code's bulkiness, was to have the portion of the script executing the function as required run through an integer array whose each stored value is sent to the function.为了减少代码的体积,我的想法是让执行 function 的脚本部分根据需要运行 integer 数组,其每个存储的值都发送到 ZC1C425268E683894F14ZA7。

But in order for this to reduce the amount of bulky code I need a way to add several values at once rather than having the values each added separately.但是为了减少庞大代码的数量,我需要一种方法来一次添加多个值,而不是分别添加每个值。

Is that possible in Pinescript?这在 Pinescript 中可能吗? Or perhaps you have a different solution for executing such function?或者您可能有不同的解决方案来执行这样的 function?

If I understand your question correctly you would like a single mass update (addition) to array elements?如果我正确理解您的问题,您是否希望对数组元素进行一次大规模更新(添加)? No such function exists, each element must be individually updated, ideally in a loop if you have a consistent calculation.不存在这样的 function,每个元素必须单独更新,如果您有一致的计算,理想情况下是在一个循环中。

To answer my own question, it seems a simple way to update an array to a set of new values is to use the built in function array.from.要回答我自己的问题,将数组更新为一组新值的简单方法似乎是使用内置的 function array.from。

var array<int> testArr = na

testArr := array.from(1, 4, 10)

It doesn't even require clearing and appending the new values as it simply replaces the testArr array with the new input.它甚至不需要清除和附加新值,因为它只是用新输入替换了 testArr 数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM