//@version=6 indicator("My Script", overlay = true) src = close a = ta.sma(src, 5) b = ta.sma(src, 50) c = ta.cross(a, b) plot(a, color = color.blue) plot(b, color = color.black) plotshape(c, color = color.red)
函数历史值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//@version=6 indicator("My script") // 将前一根K线索引值加1,来计算当前索引,第一根K线索引是0 calcBarIndex() => int index = na // nz()函数用指定值替换na值。在脚本的第一个条形图上,当系列没有历史记录时,na值将替换为-1,然后再加1以返回初始值 0 index := nz(index[1], replacement = -1) + 1 // 为偶数索引时候返回true condition = bar_index % 2 == 0 int customIndex = na // 当condition为true时候调用calcBarIndex(),这条语句编译时会有警告 if condition customIndex := calcBarIndex() plot(bar_index, "Bar index", color = color.green) plot(customIndex, "Custom index", color = color.red, style = plot.style_cross)