0

I am using the following script taken from (https://in.tradingview.com/script/fH6e5TuN-RSI-Divergence/).

study(title="RSI Divergence", shorttitle="RSI Divergence") src_fast = close, len_fast = input(5, minval=1, title="Length Fast RSI") src_slow = close, len_slow = input(14,minval=1, title="Length Slow RSI") up_fast = rma(max(change(src_fast), 0), len_fast) down_fast = rma(-min(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 = rma(max(change(src_slow), 0), len_slow) down_slow = rma(-min(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 ? lime:red, linewidth = 2) band = hline(0) // ALERT section that I added which does not work: ------------------------------- divlong = divergence < 0 and divergence >=0 divshort = divergence > 0 and divergence <=0 alertcondition(divlong, title='Div Long', message='Div Long') alertcondition(divshort, title='Div Short', message='Div Short') data1 = divlong plotshape(data1, style=shape.triangleup,location=location.bottom, color=green , title="DivUp") data2 = divshort plotshape(data2, style=shape.triangledown, location=location.top, color=red,title="DivDown") 

[Q] Is it possible to set the alert so that it triggers when the signal line changes colors (red to green/green to red)?


I tried to show the points where the alerts could be triggered.

enter image description here

2
  • See Alert conditions and How do I make an alert available from my script? for how to add alerts to your script. If you need help with that, please post your entire code. This is just a snippet that doesn't compile. Commented Dec 9, 2020 at 21:20
  • Just paste it into Pine Editor section on the tradingview site and press to Add To Chart and also its the entire code. I added the alert approach that I tried which didn't work. Commented Dec 9, 2020 at 21:36

1 Answer 1

1

Your alerts are never triggered, because the values of divlong and divshort are always false:

divlong = divergence < 0 and divergence >=0 divshort = divergence > 0 and divergence <=0 

This will work:

study(title="RSI Divergence", shorttitle="RSI Divergence") src_fast = close, len_fast = input(5, minval=1, title="Length Fast RSI") src_slow = close, len_slow = input(14,minval=1, title="Length Slow RSI") up_fast = rma(max(change(src_fast), 0), len_fast) down_fast = rma(-min(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 = rma(max(change(src_slow), 0), len_slow) down_slow = rma(-min(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 ? lime:red, linewidth = 2) band = hline(0) // ALERT section that I added which does not work: ------------------------------- // divlong = divergence < 0 and divergence >=0 // divshort = divergence > 0 and divergence <=0 divergence_past = divergence[1] divlong = divergence >=0 and divergence_past <= 0 divshort = divergence <=0 and divergence_past >= 0 alertcondition(divlong, title='Div Long', message='Div Long') alertcondition(divshort, title='Div Short', message='Div Short') data1 = divlong plotshape(data1, style=shape.triangleup,location=location.bottom, color=green , title="DivUp") data2 = divshort plotshape(data2, style=shape.triangledown, location=location.top, color=red,title="DivDown") 
Sign up to request clarification or add additional context in comments.

2 Comments

This works perfectly on my end. I get an alert each time the color changes. Did you set an alert? Can you post a screenshot of the settings of that alert?
I have used divergence_past = divergence[1] divlong = divergence >=0 and divergence_past <= 0 divshort = divergence <=0 and divergence_past >= 0 in case for the line color change

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.