计算在 x 条柱内交叉了多少次系列

Counting how many times series crossed within x amount of bars

我正在尝试计算最后 150 个柱线中序列相互交叉的次数,下面的代码给我完全随机的数字,这些数字没有任何意义。 ta.cross() 函数是否不处理 [] 运算符??这是我唯一想到的。

var crossCount = 0

for i = 0 to 150
    if ta.cross(series1[i], series2[i])
        crossCount += 1

plotchar(crossCount, "Cross Count", "", location = location.top)

//zero the cross count at the end of execution
crossCount := 0

不建议在局部范围内使用某些函数,例如 for 循环或 if 块。还有另一种更简单的方法来完成你想要的。

int crossed = ta.cross(series1, series2) ? 1 : 0
int crossCount = math.sum(crossed, 150)