Pine Script - Create Time Delay In Between Alerts

Viewed 132

I've been banging my head against the wall trying to code this.

I have one simple indicator which is working just fine, but I don't want it to be triggering too often.

I want to create a condition so it can only start triggering alerts a minimum 15 minutes after the last alert (meaning that if it triggers 1 or even 10 times in those 15 minutes no alerts should be sent).

How can I do that?

Thanks.

//@version=4
study(title='Test Bullish & Bearish', overlay=true)

//Get user input
rsiLength = input(title='RSI Length', defval=14)
rsiOB = input(title='RSI Overbought', defval=80.0)
rsiOS = input(title='RSI Oversold', defval=30.0)

//Get RSI values & check condition
rsi = rsi(close, rsiLength)
rsiBearish = rsi >= rsiOB or rsi[1] >= rsiOB
rsiBullish = rsi <= rsiOS or rsi[1] <= rsiOS

//Detect trading setups
bearishSetup = rsiBearish
bullishSetup = rsiBullish

//Draw data to chart
plotshape(bearishSetup ? 1 : na, style=shape.triangledown, color=color.red, size=size.small, location=location.abovebar, title='Bearish Signal')
plotshape(bullishSetup ? 1 : na, style=shape.triangleup, color=color.green, size=size.small, location=location.belowbar, title='Bullish Signal')

//Create trading alert
alertcondition(condition=bearishSetup, title='Bearish Signal', message='Paste Signal Message Here')
alertcondition(condition=bullishSetup, title='Bullish Signal', message='Paste Signal Message Here')
0 Answers
Related