Pine Script v5布尔变量赋值非布尔值的严重Bug及求助
Pine Script v5布尔值转换严重Bug反馈及求助
Bug详情
按Pine Script v5语言规范,布尔变量应支持接收float/int类型值并自动转换为布尔值(0对应false,非0对应true),且存储转换后的结果,但实际存在以下异常:
- 布尔变量赋值非布尔值时,实际存储的是原数值而非转换后的布尔值(例如给bool变量赋值2.5,用
str.tostring()输出结果为2.5); - 这类变量在不同场景表现矛盾:与true/false直接比较时均不相等,但在三元运算符中会被判定为true;
- 使用
input.bool()传入非布尔值时,界面显示为勾选状态(true),但代码内判定为false; - 仅通过
FLOAT ? true : false或bool(FLOAT)的方式赋值才能正常触发布尔转换,使用FLOAT ? 1 : 0仍会触发该Bug。
示例代码
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © AVAndronov // CONSTS OVERLAY = false BUG_CONST = 2.5 //@version=5 indicator("My script", overlay = OVERLAY) bool bug_input = input.bool(BUG_CONST, "Display Close 1") bool bug_free_input = input.bool(BUG_CONST ? true : false, "Display Close 2") bool bug_var = BUG_CONST //this one will bug out plot(bug_input ? close : 0, color = color.red) //these two will work plot(bug_free_input ? -close : 0, color = color.green) plot(BUG_CONST ? close : 0, color = color.purple) if barstate.islast label.new(bar_index, 0, str.tostring(bug_input) +"\n"+str.tostring(bug_input == true ? "true" : "not == true") +"\n"+str.tostring(bug_input == false ? "== false" : "not == false") +"\n"+str.tostring(bug_input ? "? true" : ": false") +"\n"+str.tostring(bug_var) +"\n"+str.tostring(bug_var == true ? "true" : "not == true") +"\n"+str.tostring(bug_var == false ? "false" : "not == false") +"\n"+str.tostring(bug_var ? "? true" : ": false") +"\n"+str.tostring(bug_free_input) )
运行结果
1. 脚本输入窗口中,两个复选框均显示为勾选状态。 2. 红色线条为水平0线,绿色和紫色线条正常显示价格走势。 3. 标签内容: false not == true == false : false 2.5 not == true not == false ? true true
作为Pine Script新手,已发现3个此类严重Bug,每次都耗费大量时间调试。此前尝试联系TradingView官方支持,但非付费用户无法得到回复,求助:不付费的情况下,如何联系官方解决该问题?
内容的提问来源于stack exchange,提问作者Alexei Andronov
相关产品推荐
相关产品推荐

