0

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.

1 Answers1

0

RSI will change its color to green from red when divergence crosses over 0, and from green to red if it cross under 0, so you can use:

if ta.crossover(divergence, 0)
    alert("RSI became green!")

if ta.crossunder(divergence, 0)
    alert("RSI became red!")

Don't forget to set the alerts.

mr_statler
  • 1,913
  • 2
  • 3
  • 14