TradingView策略对接3commas时strategy.entry函数调用报错如何解决?
TradingView Pine脚本对接3commas Webhook报错解决方案
报错根因说明
- 第一个报错
no viable alternative at character '{':Pine Script的strategy.entry函数的comment参数不支持直接传入包含大括号、转义符的复杂JSON字符串,语法解析时无法识别特殊字符触发报错。 - 第二个参数不匹配报错:
strategy.entry原生没有alert_message入参,自行添加不存在的参数会触发函数入参校验失败。
正确实现步骤
不要把Webhook要发送的JSON直接写在策略代码的strategy.entry参数里,按以下流程配置即可:
- 简化原有策略代码的
comment参数,修改后代码如下:
// Strategy if (not na(k) and not na(d)) if (crossover(k,d) and k < OverSold and crossover(delta, 0)) strategy.entry("Entrylong", strategy.long, comment="多单入场") if (crossunder(k,d) and k > OverBought and crossunder(delta, 0)) strategy.entry("Entryshort", strategy.short, comment="空单入场")
- 把修改后的策略保存并加载到K线图后,点击TradingView顶部的「Alert」按钮新建提醒:
- 触发条件选择你的策略,对应选择「策略执行订单」,如果需要区分多空单独触发,可选「策略执行多单」/「策略执行空单」
- 提醒动作勾选「Webhook URL」,填入3commas提供的Webhook接收地址
- 「消息」输入框直接粘贴你需要发送的完整JSON即可,无需转义:
{ "message_type": "bot", "bot_id": 替换为你的实际bot_id数值, "email_token": "替换为你的实际email_token字符串", "delay_seconds": 0 }
- 保存Alert即可,后续策略触发对应订单时,TradingView会自动把你配置的JSON消息推送给3commas接口。
内容的提问来源于stack exchange,提问作者monde120
相关产品推荐
相关产品推荐

