由于变量不能修改,计数器等是由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;发布于 2019-04-28 03:36:56
这是一个错误,是thinkScript当前版本中的一个缺陷。Referencing Historical Data,即读取它会覆盖问题中描述的常见情况下的历史数据,导致数据损坏,数据丢失。值得注意的是,在功能强大但功能有限的thinkScript系统中,可以使用问题中的简单语句来检查包含历史数据的IDataHolder数组var中具有固定偏移量的单元格:
input offset = 0;
plot scan = GetValue(var, BarNumber() -1 + offset);https://stackoverflow.com/questions/55778141
复制相似问题