Reputation: 1
I have created a simple Pine Script RSI strategy for stocks on Daily Timeframe with the alert function, the issue is the alert get triggered at the end of the close bar, I want to be trigerred at the beginning of the next bar. I use is_new_bar = ta.change(time("D")) != 0 but didn't work.
What function do I need to use to achieve that?
//@version=6
strategy("RSI Strategy", overlay=true)
length = input(14)
price = close
vrsi = ta.rsi(price, length)
co = ta.crossover(vrsi, 50)
cu = ta.crossunder(vrsi, 50)
is_new_bar = ta.change(time("D")) != 0
if (not na(vrsi))
if (co)
strategy.entry("RsiLE", strategy.long, comment="RsiLE")
if (is_new_bar)
alert("Buy", alert.freq_once_per_bar)
if (cu)
strategy.entry("RsiSE", strategy.short, comment="RsiSE")
alert("Sell", alert.freq_once_per_bar)
Upvotes: 0
Views: 35