I am getting too many alerts in one second (same code/indicator applied to different stocks/symbols) and i want to delay each alert by at least 5 second. I have tried using this indicator code provided by the pinecoders.com https://www.pinecoders.com/faq_and_code/#how-can-i-implement-a-time-delay-between-orders to give delay(5sec) to my 10m strategy but its not working because I am using 10m chart for and i want to get alert delayed by 5sec.
can anyone help in delaying alerts by 1-5 seconds?
@e2e4 thank you for replying, i want to test that in higher timeframe(even having inconsistency) . The link containing the code is designed to give delay only in between the bar, but i want to delay 5 sec when after the close of the candle. I tried the following code
//@version=4
strategy("Strat with time delay", overlay=true)
i_qtyTimeUnits = - input(5, "Quantity", minval = 0)
i_timeUnits = input("seconds", "Delay ", options = ["seconds", "minutes", "hours", "days", "months", "years"])
int _timeFrom_ = na
_year_ = (i_timeUnits == "year" ? int(i_qtyTimeUnits) : 0)
_month_ =(i_timeUnits == "month" ? int(i_qtyTimeUnits) : 0)
_day_ = (i_timeUnits == "day" ? int(i_qtyTimeUnits) : 0)
_hour_ = (i_timeUnits == "hour" ? int(i_qtyTimeUnits) : 0)
_minute_ = (i_timeUnits == "minute" ? int(i_qtyTimeUnits) : 0)
_second_ = (i_timeUnits == "second" ? int(i_qtyTimeUnits) : 0)
// Return the resulting time in ms Unix time format.
_timeFrom_ := timestamp(_year_, _month_, _day_, _hour_, _minute_, _second_)
// Entry conditions.
ma = sma(close, 5)
goLong = close > ma?1:0
goShort = close < ma?1:0
// Time delay filter
var float lastTradeTime = na
if nz(change(goLong), time)
// An order has been executed; save the bar's time.
lastTradeTime := timenow
var float lastTradeTime_s = na
if nz(change(goShort), time)
// An order has been executed; save the bar's time.
lastTradeTime_s := timenow
delayElapsed_long = timenow > (lastTradeTime+_timeFrom_)
delayElapsed_short = timenow > (lastTradeTime_s+_timeFrom_)
if goLong==1 and delayElapsed_long and barstate.isconfirmed
strategy.entry("Long", strategy.long, comment="Long")
if goShort==1 and delayElapsed_short and barstate.isconfirmed
strategy.entry("Short", strategy.short, comment="Short")
plot(ma, "MA", goLong ? color.lime : color.red)
i just want to delay the alert by 5 seconds. but the above code does not seems to work. please help.