I have tried to create an alert when the RSI change color from Green to Red and Red to Lime. But have not succeeded. Can someone help me for that? Thank you in advance.
Here is the code:Pine V5
//@version=5
indicator(title='RSI Divergence', shorttitle='RSI Divergence')
src_fast = close
len_fast = input.int(5, minval=1, title='Length Fast RSI')
src_slow = close
len_slow = input.int(14, minval=1, title='Length Slow RSI')
up_fast = ta.rma(math.max(ta.change(src_fast), 0), len_fast)
down_fast = ta.rma(-math.min(ta.change(src_fast), 0), len_fast)
rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - 100 / (1 + up_fast / down_fast)
up_slow = ta.rma(math.max(ta.change(src_slow), 0), len_slow)
down_slow = ta.rma(-math.min(ta.change(src_slow), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - 100 / (1 + up_slow / down_slow)
divergence = rsi_fast - rsi_slow
plotdiv = plot(divergence, color=divergence > 0 ? color.lime : color.red, linewidth=2)
band = hline(0)
Have tried but unsuccessful.