2

In pine script I have a funtion that returns a tuple:

calcSomething(val1, val2) =>
    ...
    [val3, val4]

And I'm calling the function from a loop where the val1 and val2 change:

while i < 5
    [val5, val6] = calcSomething(val1, val2)
    val1 += 1
    val2 += 1
    i += 1

Unfortunately the values from val5 and val6 remain the same every time the loop runs.

I tried to change "="

[val5, val6] = calcSomething(val1, val2)

to ":="

[val5, val6] := calcSomething(val1, val2)

But it returns a Syntax error at input ':='.

How can the tuple change values from inside a loop.

1 Answers1

3

Unfortunately, you cannot use the := operator with tuples yet.

A workaround is to use two temporary variables:

while i < 5
    [_val5, _val6] = calcSomething(val1, val2)
    val5 := _val5
    val6 := _val6
    val1 := val1 + 1
    val2 := val2 + 1
    i := i + 1
vitruvius
  • 15,740
  • 3
  • 16
  • 26