首页 > 解决方案 > Tradingview 和 Pine Script:代码问题

问题描述

我对编码的经验为零。我在 TradingView 上使用公开可用的策略(Pine Script v2),我想使用 TradingView 的自定义信号将其连接到我的 3Commas 机器人。

我需要做的是在需要多头或空头头寸的代码行中添加注释,以便在触发警报时,它与我的机器人进行通信。

我遵循了在线教程和 3Commas 的文档。下面的评论参数是我卡住的地方:我一直收到“在字符'{'处没有可行的替代方案”错误。它们将位于下面的第 7 行和第 11 行:

//============ signal Generator ==================================//
period = input('720')
ch1 = security(tickerid, period, open)
ch2 = security(tickerid, period, close)
longCondition = crossover(security(tickerid, period, close),security(tickerid, period, open))
if (longCondition)
    strategy.entry("BUY", strategy.long, comment="{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0\n}")
    
shortCondition = crossunder(security(tickerid, period, close),security(tickerid, period, open))
if (shortCondition)
    strategy.entry("SELL", strategy.short, comment="{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0,\n\"action\": \"close_at_market_price\"\n}")

我将不胜感激修复代码的任何帮助。先感谢您。

标签: compiler-errorscommentspine-script

解决方案


使用Pine v4andalert_message参数代替comment.

//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)

period = input('720')
ch1 = security(syminfo.tickerid, period, open)
ch2 = security(syminfo.tickerid, period, close)

longCondition = crossover(security(syminfo.tickerid, period, close),security(syminfo.tickerid, period, open))
shortCondition = crossunder(security(syminfo.tickerid, period, close),security(syminfo.tickerid, period, open))

if (longCondition)
    strategy.entry("BUY", strategy.long, alert_message = "{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0\n}")
if (shortCondition)
    strategy.entry("SELL", strategy.short, alert_message = "{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0,\n\"action\": \"close_at_market_price\"\n}")

推荐阅读