简体   繁体   中英

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.

The function in some situations might be called several times in sequence in order to return the resulting values of several different if conditions.

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.

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? Or perhaps you have a different solution for executing such 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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