I have a working strategy in trading view and I would like to add alerts to.
I simply need a 'buy' alert on strategy.entry(long) and a 'sell' alert on strategy.entry(short).
The conditions can't be the same. One of the conditions for long is that there are 2 consecutive green bars. So once the long alert triggers, and the next bar is also green, the long alert will trigger again on the third bar. It triggers every time there are 2 consecutive green bars. What I need is so that it triggers once (go long) and then has to wait for a sell alert before it is allowed to trigger again.
Here is example code on the problem, thanks for any help.
study("Consecutive Up/Down Strategy", overlay=true)
consecutiveBarsUp = input(1)
consecutiveBarsDown = input(1)
price = close
ups = 0.0
ups := price > price[1] ? nz(ups[1]) + 1 : 0
dns = 0.0
dns := price < price[1] ? nz(dns[1]) + 1 : 0
// Strategy Execution, this WORKS because once you go long, you can't go long again until you have gone short.
// if (ups >= consecutiveBarsUp)
// strategy.entry("ConsUpLE", strategy.long, comment="ConsUpLE")
// if (dns >= consecutiveBarsDown)
// strategy.entry("ConsDnSE", strategy.short, comment="ConsUpLE")
// Alert conditions, this doesn't work because it triggers the alert multiple times in a buy/sell cycle. After it goes long for the first time, the condition can be met before it can go short. Ex. 2 Consecuative green bars triggers long alert, but then the third consecuative green bar also triggers the long alert, before it closes the position.
alertcondition(ups >= consecutiveBarsUp, title='long', message='long')
alertcondition(dns >= consecutiveBarsDown, title='short', message='short')
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)