compiler-errors - 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}")
我将不胜感激修复代码的任何帮助。先感谢您。
解决方案
使用Pine v4
andalert_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}")
推荐阅读
- vb.net - vb.net 中的 ftell() 和 fseek() 函数是什么?
- javascript - 正则表达式匹配字符串中的字母和数字,可选地具有一组特殊字符
- ios - 如何使用 iOS 将 pdf 文件上传到 firebase
- webpack - Github 页面是否支持 webpack 代理?
- php - 如何允许通过 cookie 进行 htaccess 身份验证?
- c++ - 从 boost asio io_service 对象获取 epoll 描述符
- angular - 无法使用 Angular 从服务器下载 zip 文件
- mysql - 使用 Select Join 更新 MySQL
- python - 带 Python 的 Modbus TCP
- java - 网络超时后频道未关闭