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

这段Pine Script示例代码报‘input '('处语法错误’,原因是什么?

Pine Script语法错误原因分析

错误根源

你遇到的input '('处语法错误,本质是**table.cell_set_text函数的text参数使用了Pine Script不支持的语法**:
原代码中用连续冒号:串联变量的写法txt_example_1 : txt_example_1 : txt_example_1 : txt_example_1 : txt_example_1 : txt_example_1 : na完全不符合Pine Script的语法规则,这种写法会让编译器解析代码时逻辑混乱,误判括号的语法结构,从而抛出错误。

修复方案

根据不同需求,可选择以下两种合法写法修正:

1. 拼接所有非空文本

若需要将所有非na的文本内容拼接显示,使用str.cat()函数(或直接用+运算符),搭配str.trim()去除冗余空白:

table.cell_set_text(watermark, 0, 0, text = str.trim(str.cat(txt_example_1, txt_example_2, txt_example_3, txt_example_4, txt_example_5, txt_example_6)))

2. 显示第一个非na的文本

若仅需展示第一个不为na的文本内容,使用coalesce()函数依次匹配:

table.cell_set_text(watermark, 0, 0, text = coalesce(txt_example_1, txt_example_2, txt_example_3, txt_example_4, txt_example_5, txt_example_6, na))

额外注意

代码中indi_example和indi_example_2变量需提前定义(比如通过input.string()等方式),否则后续会触发未定义变量的错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 17:31:04