使用Pinescript4.0的WebHooks发送策略数据 [英] sending Strategy data using Webhooks for Pinescript 4.0

查看:13
本文介绍了使用Pinescript4.0的WebHooks发送策略数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tradingview Pinescript 4.0.

此消息是根据以下内容发出的: https://stackoverflow.com/questions/66926863/combining-data-from-different-tradingview-4-0-indicators-for-the-purpose-of-crea

基本上,我想做的是在Tradingview Webhook Alert系统中使用Tradingview 4.0 Pinescript Strategies

我见过的最接近的视频是在这个特定的视频中(针对不同的产品),它提供了如何做到这一点的提示: https://support.mudrex.com/hc/en-us/articles/360050211072-Automating-an-alert-from-a-Strategy-on-TradingView

它将使用类似以下注释的内容:

//Strategy y.Entry(id=tostring(随机数),long=False, COMMENT=&Q;{&Q;ID&Q;:&Q;+TO字符串(随机数字)+&Q;,&Q;操作&Q;: ";Reverse_Short_to_Long";})

我需要将The Strategy中的JSON作为Web警报的一部分发送。根据这段视频,人们会使用这样的东西:

{{ strategy.comment }}

有没有具体的例子说明如何做到这一点?

TradingView

推荐答案如果字符串格式为json,则以json格式发送警报。我建议使用alert()函数,而不是警报条件。然后,就可以随心所欲地构造JSON格式的字符串了。下面是我用来生成警报的一个讨厌的函数。

customalert(_name, _symbol, _type, _asset_type, _action, _risk_value, _risk_percent, _sl, _tp1,_tp1_percent, _tp2, _tp2_percent, _message) =>
    alert_array = array.new_string()
    if _name != ''
        array.push(alert_array, '"Name": "' + _name + '"')
    if _symbol != ''
        array.push(alert_array, '"Symbol": "' + _symbol + '"')
    if _type != ''
        array.push(alert_array, '"Type": "' + _type + '"')
    if _asset_type != ''
        array.push(alert_array, '"Asset Type": "' + _asset_type + '"')
    if _action != ''
        array.push(alert_array, '"Action": "' + _action + '"')
    if _risk_value != 0
        array.push(alert_array, '"Risk Value": "' + tostring(_risk_value) + '"')
    if _risk_percent != 0
        array.push(alert_array, '"Risk Percentage": "' + tostring(_risk_percent) + '"')
    if _tp1 != 0
        array.push(alert_array, '"Take Profit 1 Level": "' + tostring(_tp1) + '"')
    if _tp1_percent != 0
        array.push(alert_array, '"Take Profit 1 Percent": "' + tostring(_tp1_percent) + '"')
    if _tp2 != 0
        array.push(alert_array, '"Take Profit 2 Level": "' + tostring(_tp2) + '"')
    if _tp2_percent != 0
        array.push(alert_array, '"Take Profit 2 Percent": "' + tostring(_tp2_percent) + '"')
    if _sl != 0
        array.push(alert_array, '"Stop Loss Level": "' + tostring(_sl) + '"')
    if _message != ''
        array.push(alert_array, '"Message": "' + _message + '"')
    
    alertstring = '{' + array.join(alert_array,', ') + '}'
    alert(alertstring, alert.freq_once_per_bar_close)

您不需要做任何复杂的事情,但最重要的一行是alertstring = '{' + array.join(alert_array,', ') + '}'

您只需确保字符串以大括号开头和结尾,并且JSON格式正确。

同样容易:

alert('{"Symbol": "' + syminfo.ticker + '", "Action": "Entry"}', alert.freq_once_per_bar_close)

您只需小心使用双引号和单引号。

此外,如果您要设置警报并单击该选项以了解有关警报的更多信息,则会解释这一点,至少JSON格式是决定警报是以文本还是JSON格式发送的这一事实。至于{{}},它们用于发送一组有限的值,以便与alertcondition()函数一起使用,与tostring()alert()相比,我真的看不出使用它们有什么好处。

另一件要记住的事情是,这需要将数据作为字符串发送,因此您需要确保在服务器端根据需要转换回整数和浮点数。

这篇关于使用Pinescript4.0的WebHooks发送策略数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆