barstate.islast 无效系列[1]

barstate.islast invalidades series[1]

原问题

显然,当使用 barstate.islast 时,不会返回系列中零之前的值。

这是预期的行为吗?还是有问题?


//@version=5
indicator("barstate.islast invalidades series[1]", max_bars_back=5000)

index = bar_index

countNonNa(indices) =>
    count = 0
    for i = 0 to 4999 by 1
        index = indices[i]
        if not(na(index))
            count += 1
    count
    
    
count00 = countNonNa(index) 
plot(count00, "count00", color = color.blue) // ok

count01 = barstate.isconfirmed ?  countNonNa(index) : 0 
plot(count01, "count01", color = color.black) // ok

count02 = barstate.islast ?  countNonNa(index) : 0 
plot(count02, "count02", color = color.red) // error expected 5000 in the last bar, but gets 1

您应该按照控制台中的说明在每个柱上执行您的函数。
这将起作用:

//@version=5
indicator("barstate.islast invalidades series[1]", max_bars_back=5000)

index = bar_index

countNonNa(indices) =>
    count = 0
    for i = 0 to 4999 by 1
        idx = indices[i]
        if not(na(idx))
            count += 1
    count
    
c = countNonNa(index)     

count00 = c
plot(count00, "count00", color = color.blue) // ok

count01 = barstate.isconfirmed ?  c : 0 
plot(count01, "count01", color = color.black) // ok

count02 = barstate.islast ?  c : 0 
plot(count02, "count02", color = color.red) // error expected 5000 in the last bar, but gets 1