【发布时间】:2019-04-20 22:03:15
【问题描述】:
由于变量无法修改,计数器等由 IDataHolder 数组实现,其中计数器通过将一个值与前一个值相加来获取值,然后将其存储在当前位置,然后再前进到下一个位置。这种机制在以下扫描脚本中部分中断,读取变量似乎会更改其值,我想了解原因:
# Sum Test
# Build sum starting at the left end
def sum;
if (BarNumber() < 5) {
if (BarNumber() == 1) {
sum = 1;
} else {
sum = sum[1] + 1;
}
} else {
sum = sum[1]; # This causes the problem.
#sum = Double.NaN;# alternative: does not change previous value but useless.
}
# Test that the first sum entry is 1 as expected
plot scan = GetValue(sum, BarNumber() -1) == 1;
【问题讨论】:
标签: thinkscript