pine-script - Pinscript 警报变量
问题描述
我正在寻找一种在 webhook 消息中发送用户标识的方法。用户应该能够输入他们的 ID,并且应该在触发 webhook 警报时在消息中发送。到目前为止,我还不能在消息中使用自定义变量,而且似乎不支持。
myID = input(title="myID", type=input.string, defval="1000")
//===============================
// Alert to trigger Buy
//===============================
alertcondition([YourAlertCondition], title = "Buy", message = "{\"side\": \"Buy\", \"symbol\": \"ASSETNAME\", \"type\": \"Market\", \"amount\": \"20\", \"takeProfit\": \"1\", \"stopLoss\": \"1\", \"trailingStop\": \"None\", \"new_trailing_active\": \"None\", \"Leverage\": \"1\", \"TelegramID\":"+{{myID}}}+"")
预期输出:
{"side": "Sell", "symbol": "ASSETNAME", "type": "Market", "amount": "20", "takeProfit": "1", "stopLoss": "1", "trailingStop": "None", "new_trailing_active": "None", "Leverage": "1", "myID": "1000" }
上面的方法是我尝试过的一些变化。如果不能使用变量,有没有办法在消息中输出用户的 TradingView 用户名?如果可能,TradingView 用户名可以用作接收服务器上的 ID。
解决方案
您可以使用该alert
功能而不是alertcondition
,在您的情况下,您可以使用:
msg = '{' + str.format('\"side\": \"Buy\", \"symbol\": \"ASSETNAME\", \"type\": \"Market\", \"amount\": \"20\", \"takeProfit\": \"1\", \"stopLoss\": \"1\", \"trailingStop\": \"None\", \"new_trailing_active\": \"None\", \"Leverage\": \"1\", \"TelegramID\":"{0}"',myID) + '}'
if YourAlertCondition
alert(msg,alert.freq_once_per_bar_close)
见警戒员。
推荐阅读
- maven - 通过命令提示符运行黄瓜 || 测试运行:0,失败:0,错误:0,跳过:0
- sql - 在 SQL Server 2005 中添加总行?
- docker - 如何在使用 docker 时为多个项目共享(公开)端口 80
- scala - Couchbase 计数器给出 NOT_EXISTS 错误
- esp8266 - 如何在 esp8266 上进行智能配置后设置静态 IP
- python - matplotlib:刻度标签位置没有得到一致执行
- kotlin - 带有 BindingAdapter 的 AndroidX
- c# - XSL FO 在具体注释之后读取第一个 fo:table 节点
- html - break-after 后 div 的最后一部分不想占用屏幕高度的 100%
- javascript - angular2 日期选择器中 owl-date-time 的时间字段是否有任何事件?