Reputation: 119
I have two consecutive alerts which occur randomly at any time within the bar based on a condition. It executes perfectly, but the consecutive alert doesn't trigger in coded hierarchy. It triggers randomly, so I need a time gap between like 5 secs btw triggering of those two alerts so that I can control its trigger time. Please suggest any ideas or code.
Here is the code snippet - unfortunately only one alert is triggered not the second consecutive one.
I probably need a timer.wait
for some secs until the next line of code is executed.
Can anyone help achieving it?
Here is the code:
//@version=6
strategy("Delay Alerts", overlay=true,calc_on_every_tick = true, fill_orders_on_standard_ohlc = true)
varip int counter1 = 0
varip int counter2 = 0
varip int counter3 = 0
varip int counter4 = 0
varip bool lup = false
varip bool ldown = false
varip bool long1 = false
varip bool long12 = false
varip bool long2 = false
varip bool long21 = false
varip secs = time(na)
varip float calsecs = 0
varip float calsecs2 = 0
varip bool timesecs = false
if barstate.isnew
counter1 := 0
counter2 := 0
counter3 := 0
counter4 := 0
lup := false
ldown := false
secs := 0
calsecs := 0
calsecs2 := 0
timesecs := false
secs := timeframe.in_seconds(timeframe.period) * 1000
calsecs := math.round((time_close - timenow) / secs * 1000, 0)
long1 := close < open ? true : false
long12 := not long1 ? true : false
long2 := close > open ? true : false
long21 := not long2 ? true : false
if not lup
if long1
counter1 += 1
lup := true
ldown := false
if counter1 < 10
alert('Close < Open', freq = alert.freq_all)
calsecs2 := calsecs-5
timesecs := calsecs <= calsecs2 ? true : false
if timesecs
alert('Short May Open', freq = alert.freq_all)
if not ldown
if long2
counter2 += 1
lup := false
ldown := true
if counter2 < 10
alert('Close > open', freq = alert.freq_all)
calsecs2 := calsecs-5
timesecs := calsecs <= calsecs2 ? true : false
if timesecs
alert('Long May Open', freq = alert.freq_all)
plotshape(long1 , '', shape.triangledown, location.abovebar, color.red)
plotshape(long2 , '', shape.triangleup, location.belowbar, color.lime)
I tried using timer function but no luck only one alert trigger
Upvotes: 0
Views: 41