How to pass index parameter from fold loop to other function


0
0

Hi,

This code breaks:

declare lower;

script getItem{
input offset = 0;
input index = 0;
plot output = offset + index;
}

script test{
input offset = 0;
def total = fold index = 0 to 10 with accumulator = 0 do
accumulator + getItem(offset, index);########## Error here
plot output = total;
}

plot output = test(3);

It is a simple as it gets, modified from
Example 2 in the manual at https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/fold.html

I need to pass the index parameter from the loop to the function.

Many thanks.

Marked as spam
Posted by (Questions: 3, Answers: 3)
Asked on April 11, 2019 4:50 pm
3 views
0
Private answer

It’s  defect.

 

Workaround is:

<pre>

script test{
input offset = 0;
def indexer = fold i = 0 to 10 do i;
def total = fold index = 0 to 10 with accumulator = 0 do
accumulator + getItem(offset, indexer);
plot output = total;
}

</pre>

Marked as spam
Posted by (Questions: 3, Answers: 3)
Answered on April 12, 2019 7:51 pm

It is not a solution, sorry. This was provided by Ameritrade support staff. While the code actually runs, it calls the function with the same value multiple times. This item would need to be re-opened as unresolved.

( at April 14, 2019 12:37 pm)