如何在条件满足时在指标状态栏显示变量值,不满足时隐藏?
Pine Script 状态栏显示控制问题
我希望当RSW_band_cross_final变量等于1时,在指标状态栏显示其值;当该变量等于0时,不显示任何内容,而非显示0.00。请问这是否可行?或有什么解决办法?谢谢。
相关代码片段
交叉条件判断
RSW_positive_band_cross = RSW >= band RSW_negative_band_cross = RSW <= -band
布尔转整数转换
int RSW_band_cross_final = na if RSW_positive_band_cross == true or RSW_negative_band_cross == true RSW_band_cross_final := 1 else RSW_band_cross_final := 0
报错的plot代码
以下plot代码返回错误:
"Cannot call 'operator ?:' with argument 'expr0'='call 'operator ==' (series bool)'. An argument of 'series bool' type was used but a 'const bool' is expected."
错误出现在"display = RSW_band_cross_final == 1"部分:
plot(RSW_band_cross_final, title = "Relative Strength / Weakness Status Line Value", color = RSW_positive_band_cross == true ? color.new(#00d99f, 0) : RSW_negative_band_cross == true ? color.new(#ff004d, 0) : na, editable = false, display = RSW_band_cross_final == 1 ? display.status_line : display.none)
可行解决办法
经验证,直接实现“等于0时完全不显示”的需求无法达成,可采用以下两种替代方案:
- 当条件不满足时返回
na而非0:此时状态栏会显示Ø字符,相比0.00占用更少空间。 - 条件不满足时仍返回
0:将文本颜色改为与图表背景色一致,让0.00几乎不可见(注意na对应的Ø字符颜色无法修改)。
内容的提问来源于stack exchange,提问作者cxrbon
相关产品推荐
相关产品推荐

