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

Pine Script警报触发时,如何向指定URL发送多浮点数据?

解决Pine Script触发条件时发送多个浮点数据的问题

方法1:利用TradingView警报Webhook(推荐,无需额外脚本权限)

TradingView内置的警报Webhook本身支持POST请求,你可以把多个浮点数据打包成JSON格式放进警报消息里,触发时会自动以POST方式发送到指定URL。

操作步骤:

  • 在Pine Script里定义好触发条件(比如RSI金叉、价格突破均线等),然后添加警报。
  • 警报设置中选择「Webhook URL」,填入你的目标接收地址。
  • 在「消息」框里用JSON格式拼接多个浮点数据,用{{变量名}}插入指标实时值,示例:
    {"current_price": {{close}}, "rsi_value": {{ta.rsi(close,14)}}, "macd_line": {{ta.macd(close,12,26,9)[0]}}, "signal_line": {{ta.macd(close,12,26,9)[1]}}}
    
  • 当条件触发时,Webhook会把这个JSON作为POST请求的Body发送,接收端直接解析JSON就能提取所有浮点数据。

方法2:使用Pine Script的request.send()函数(需脚本权限)

如果需要在脚本内直接触发请求,request.send()支持指定POST方法,手动构造JSON payload发送多个浮点数据:

示例代码:

//@version=5
indicator("POST Multiple Floats", overlay=true)

// 定义触发条件
trigger_condition = ta.crossover(ta.rsi(close, 14), 30)

if trigger_condition
    // 提取需要发送的浮点数据
    float current_close = close
    float rsi_val = ta.rsi(close, 14)
    float macd_val = ta.macd(close, 12, 26, 9)[0]
    
    // 构造JSON格式的请求体
    payload_str = '{"close": ' + str.tostring(current_close) + ', "rsi": ' + str.tostring(rsi_val) + ', "macd": ' + str.tostring(macd_val) + '}'
    
    // 发送POST请求
    request.send(
        url="https://your-target-url-here.com",
        method=request.method_post,
        body=payload_str,
        headers={"Content-Type": "application/json"}
    )

注意事项

  • 使用request.send()时,要确保脚本发布时勾选了「允许Web请求」的权限。
  • TradingView对请求频率有严格限制,避免短时间内多次触发导致请求被拦截。
  • 接收端需要配置好解析POST请求Body的逻辑,比如用Python Flask、Node.js Express等框架直接读取JSON数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 21:05:22