如何在警报生成后延迟 TradingView 警报

问题描述 投票:0回答:1

我试图在 TradingView 中生成警报一段时间(例如 15 秒)后延迟警报。但警报未存储在变量中。它们同时触发。还有其他方法可以做到这一点吗?.

//@version=5
indicator("Delayed Alert Example", overlay=true)

delay = input(15, 'Time Delay')*1000 // convert seconds to milliseconds

// Define a variable to store the time of the last alert
var lastBuySignalTime = 0
var lastSellSignalTime = 0


// Condition for the signals
BUY = open < close 
SELL = open > close 

plotshape(BUY , title='Long', style=shape.labelup, location=location.belowbar)
plotshape(SELL , title='Short', style=shape.labeldown, location=location.abovebar)

// Delay the alert by given time
if BUY 
    alert("Buy Signal", alert.freq_once_per_bar)
    lastBuySignalTime := timenow

if BUY and (lastBuySignalTime >= delay)
    alert("Delayed Buy Signal", alert.freq_once_per_bar)
    
if SELL 
    alert("SELL Signal", alert.freq_once_per_bar)
    lastSellSignalTime := timenow

if SELL and (lastSellSignalTime >= delay)
    alert("Delayed SELL Signal", alert.freq_once_per_bar)

感谢您的宝贵时间。

pine-script pine-script-v5 tradingview-api algorithmic-trading
1个回答
0
投票

我认为延迟申报有问题。尝试以下操作:

if BUY and (timenow - lastBuySignalTime >= delay)
    alert("Delayed Buy Signal", alert.freq_once_per_bar)
    
if SELL and (timenow - lastSellSignalTime >= delay)
    alert("Delayed SELL Signal", alert.freq_once_per_bar)
© www.soinside.com 2019 - 2024. All rights reserved.