You need to enable JavaScript to run this app. 如何在alertcondition()中校验布尔结果并修复类型不匹配编译错误
优惠活动
大模型
产品
解决方案
定价
更多

如何在alertcondition()中校验布尔结果并修复类型不匹配编译错误

问题原因

报错触发的核心原因是你定义的alertDistanceLevel变量为字符串类型,不支持与数字0执行大小比较运算:

  • 你调用input()时传入的初始值为带单引号的'0',Pine Script会自动将该输入识别为字符串类型,而>运算符要求两侧参数均为数值类型。
修复方案

将input()的初始值改为不带引号的数值0,也可显式指定输入类型保证变量为数值类型,修改后的完整代码如下:

//@version=4
study(title="myindi", shorttitle="myindi")
alertDistanceLevel = input(0, title="Alert distance level (0 = disabled)", type=input.float)
alertcondition((alertDistanceLevel > 0), title="distancelevel", message="distancelevel")
可选优化

如果要求输入的预警距离为整数,可以将type参数调整为input.integer,限制用户仅能输入整数值。

内容的提问来源于stack exchange,提问作者Mapletree

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 05:36:02