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

TradingView每日最后30分钟EDT警报不触发问题排查

问题:未触发的Pine Script收盘警报排查

想要创建一个警报,当满足特定条件时,在EDT时间每日最后30分钟触发:当前5分钟K线收盘价减去当日最低价除以(当日最高价减当日最低价)大于0.7,即(close - Low)/(High - Low) > 0.7。以下是未触发的代码:

//@version=5
indicator("ClosingAlert")

High = request.security(syminfo.tickerid, "D", high)
Low = request.security(syminfo.tickerid, "D", low)
Open = request.security(syminfo.tickerid, "D", open)
HL = High - Low
InSession(sess) => not na(time("5", sess, "America/New_York")[1])
sellClose = ((close - Low)/HL > 0.7) and InSession("1530-1600") 

alertcondition(condition=sellClose, message="Sell Signal")

请问遗漏了什么?是否是不同时间框架的编码有误?


问题排查与修正

你的代码存在两个关键问题,导致警报无法触发:

1. 时间范围判断逻辑延迟

InSession函数里的time("5", sess, "America/New_York")[1]引用的是前一根5分钟K线的时间,这会让判断逻辑滞后一根K线,错过当日最后30分钟的实时触发时机。

修正方式:去掉[1],直接检查当前K线是否处于目标时间范围:

InSession(sess) => not na(time("5", sess, "America/New_York"))

2. 日线高低价未实时更新

默认的request.security会返回已完成的日线Bar数据,在交易日未结束时(比如最后30分钟),你拿到的会是上一个交易日的高低价,而非当日实时更新的数据。

修正方式:添加barmerge.gaps_on和barmerge.lookahead_on参数,确保实时获取当日最新高低价:

High = request.security(syminfo.tickerid, "D", high, barmerge.gaps_on, barmerge.lookahead_on)
Low = request.security(syminfo.tickerid, "D", low, barmerge.gaps_on, barmerge.lookahead_on)

修正后的完整代码

//@version=5
indicator("ClosingAlert")

// 实时获取当日最新高低价
High = request.security(syminfo.tickerid, "D", high, barmerge.gaps_on, barmerge.lookahead_on)
Low = request.security(syminfo.tickerid, "D", low, barmerge.gaps_on, barmerge.lookahead_on)
HL = High - Low

// 正确判断当前K线是否处于目标时间范围
InSession(sess) => not na(time("5", sess, "America/New_York"))
sellClose = ((close - Low)/HL > 0.7) and InSession("1530-1600") 

alertcondition(condition=sellClose, message="Sell Signal")

补充说明:America/New_York时区设置符合EDT要求,1530-1600的时间范围也准确对应美股收盘前30分钟,无需调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 05:47:08