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

TradingView更新后strategy.order.action警报异常触发问题求助

解决TradingView策略平仓触发开单动作警报的问题

问题根源

TradingView的strategy.close()本质是生成反向订单来平仓(比如平多单生成sell订单,平空单生成buy订单),所以{{strategy.order.action}}会返回这个反向动作,导致警报误触发。

解决方案

1. 用订单注释区分开单/平仓

给开单和平仓订单添加自定义注释,然后在警报中过滤注释:

// 开多单,注释标记为Entry
strategy.entry("Long Entry", strategy.long, comment="Entry Long")
// 平多单,注释标记为Close
strategy.close("Long Entry", comment="Close Long")

// 开空单
strategy.entry("Short Entry", strategy.short, comment="Entry Short")
// 平空单
strategy.close("Short Entry", comment="Close Short")

设置警报时,在消息中加入{{strategy.order.comment}},并在警报触发条件里选择仅当注释包含"Entry"时(具体可在警报设置的"条件"中自定义过滤规则)。

2. 自定义开单动作变量

在脚本中单独记录开单动作,避免直接使用{{strategy.order.action}}:

var string entry_action = ""

// 开单逻辑
if (long_condition)
    strategy.entry("Long", strategy.long)
    entry_action := "buy"
if (short_condition)
    strategy.entry("Short", strategy.short)
    entry_action := "sell"

// 平仓逻辑
if (exit_long)
    strategy.close("Long")
if (exit_short)
    strategy.close("Short")

// 自定义警报条件,仅发送开单动作
alertcondition(strategy.order.action != na and str.match(strategy.order.comment, "Entry"), 
               title="Entry Alert", 
               message="Action: {{entry_action}}")

这种方式下,entry_action只会在开单时更新,平仓时不会改变,警报只会触发开单动作。

3. 检查警报触发模式

在TradingView警报设置中,确保触发模式选择**"一次当订单被提交或修改时"**,而非"每次脚本计算时",避免不必要的重复触发。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 13:03:08