You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PineScript出现mismatched input 'if'错误,请求排查代码问题

错误原因排查

这个错误源于Pine Script的自定义函数语法规则:

  • 若函数仅返回单个表达式,可直接用=>后跟表达式;
  • 但当函数包含多分支逻辑(比如你写的if/else if结构)时,必须用{}包裹整个函数体。否则解析器会默认你要编写单表达式函数,遇到if时就会判定语法不匹配。
修复后的代码
arrow(direction, bar, color) =>
    {
        if direction == "up"
            plotchar(bar, high, "\u2191", color, size = size.normal)
        else if direction == "down"
            plotchar(bar, low, "\u2193", color, size = size.normal)
    }

额外说明:如果使用Pine Script v5版本,虽然对函数语法容错性稍高,但用大括号包裹多语句函数体是更规范的写法,能彻底避免这类语法错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 07:25:18