问题描述
我在使用 if 语句时遇到了一些挑战。我希望仅当代码 (plotshape) 为假时才绘制下面的代码 (plotchar)。如果代码 (plotshape) 为真,则不应绘制代码 (plotchar)。
plotshape (show_atr_rule ? atrchecklocation : na,style=shape.circle,location=absolute,size=tiny,color=color.yellow,transp=20)
plotchar(codiff_long,color=color.green,location=location.abovebar,text="BUY",transp=0)
plotchar(codiff_short,color=color.red,location=location.belowbar,text="SELL",transp=0)
解决方法
在 series
函数的 plotchar
参数中创建一个三元条件,与使用 plotshape
的方式相同:
plotshape (show_atr_rule ? atrchecklocation : na,style=shape.circle,location=absolute,size=tiny,color=color.yellow,transp=20)
plotchar(show_atr_rule ? na : codiff_long,color=color.green,location=location.abovebar,text="BUY",transp=0)
plotchar(show_atr_rule ? na : codiff_short,color=color.red,location=location.belowbar,text="SELL",transp=0)