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

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参数里,按以下流程配置即可:

  1. 简化原有策略代码的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="空单入场")
  1. 把修改后的策略保存并加载到K线图后,点击TradingView顶部的「Alert」按钮新建提醒:
  • 触发条件选择你的策略,对应选择「策略执行订单」,如果需要区分多空单独触发,可选「策略执行多单」/「策略执行空单」
  • 提醒动作勾选「Webhook URL」,填入3commas提供的Webhook接收地址
  • 「消息」输入框直接粘贴你需要发送的完整JSON即可,无需转义:
{
"message_type": "bot",
"bot_id": 替换为你的实际bot_id数值,
"email_token": "替换为你的实际email_token字符串",
"delay_seconds": 0
}
  1. 保存Alert即可,后续策略触发对应订单时,TradingView会自动把你配置的JSON消息推送给3commas接口。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 17:06:03