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

Pinescript中如何将两个平仓操作的警报合并为单个Webhook警报?

解决Pinescript两次平仓触发重复Webhook警报的问题

核心思路是用一个布尔变量标记警报发送状态,确保满足平仓条件时只触发一次Webhook,同时正常完成两个订单的平仓操作。

具体实现步骤

  • 声明全局布尔变量记录警报是否已发送,避免重复触发
  • 先执行两次平仓操作确保订单都被处理
  • 仅在警报未发送时触发一次Webhook,随后标记为已发送
  • 仓位清零后重置标记,保证后续信号能正常触发

修改后的代码示例

// 全局标记变量,仅初始化一次
var bool alert_sent = false

if (_tp_price >= close)
    // 正常执行两次平仓,确保两个订单都被平掉
    strategy.close(id=str.tostring(last_order_id))
    strategy.close(id=str.tostring(first_order_id))
    
    // 仅触发一次Webhook警报
    if not alert_sent
        // 替换为你的Webhook内容,可包含合并后的仓位信息
        strategy.alert("批量平仓:合并仓位总量", alert.freq_once_per_bar_close, webhook_url="你的Webhook地址")
        alert_sent := true

// 仓位清零时重置标记,避免影响后续信号
if strategy.position_size == 0
    alert_sent := false

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 11:30:56