Page 1 of 1

Alerts on TradingView with the EMA and RSI

Posted: Fri Sep 30, 2022 9:38 am
by Zeus1997
Hello everyone, I would like to create an alert that is triggered under certain conditions:
 
I'm using the RSI and the EMA, but the EMA is not on the chart, it's in the bottom box on the RSI. I also created an indicator myself that shows certain percentage lines.
 
indicator(title="Short and Long Indicator")
length = input( 14 )
price = close
vrsi = plot(pine_rsi(close, 7)) (maybe this is a source of error)
plot(90, title = "Short Line", color = red, transp = 70, linewidth = 2)
plot(80, title = "Line at 80", color = white, transp = 70, linewidth = 2)
plot(70, title = "Line at 70", color = white, transp = 70, linewidth = 2)
plot(50, title = "Line at 50", color = white, transp = 70, linewidth = 2)
plot(30, title = "Line at 30", color = white, transp = 70, linewidth = 2)
plot(20, title = "Line at 20", color = white, transp = 70, linewidth = 2)
plot(10, title = "Long Line", color = red, transp = 70, linewidth = 2)
plot(vrsi, title = "RSI", color=aqua, linewidth = 2)
plot(close)
 
(This indicator doesn't always work, there must be a bug ;) )
 
Regarding my question: The alarm should be triggered when the EMA crosses the RSI upwards from the "short line" (for a short position). The same applies to the long line and the long position.
 
The problem is that even simple alerts with the EMA indicator don't work!
 
Is it possible to create such an alarm?

 
Thank you for your effort and I hope you can help me.
 
Many greetings :cool:

Re: Alerts on TradingView with the EMA and RSI

Posted: Sun Oct 16, 2022 10:47 pm
by purplemint22
Zeus1997 wrote:
Fri Sep 30, 2022 9:38 am
Hello everyone, I would like to create an alert that is triggered under certain conditions:
 
I'm using the RSI and the EMA, but the EMA is not on the chart, it's in the bottom box on the RSI. I also created an indicator myself that shows certain percentage lines.
 
indicator(title="Short and Long Indicator")
length = input( 14 )
price = close
vrsi = plot(pine_rsi(close, 7)) (maybe this is a source of error)
This is part of the problem. So it looks like you have created two variables that you are not using, which are "length" and "price". I'm thinking these are supposed to be combined in some way to create the variable "pine_rsi" because this is also not declared outside of the "vsi" variable.

In general, it is a good rule of thumb to review your code to remove any variables that you are not using.

Since the "pine_rsi" variable is not declared, you can't pass "close, 7" as the parameters.

you could create the vrsi variable by saying

vrsi = ta.rsi(price, length)

or

vrsi = ta.rsi(close, 7)

Then you would plot the vrsi variable

plot(vrsi, title = "RSI", color= color.aqua, linewidth = 2)

I'm new so I don't know how to explain why you can't create a variable with the plot function. Maybe you can, but I wouldn't know when this would be possible or necessary, but if looks like you are using it twice, and I'm not quite sure what you are trying to accomplish by doing this.

The next issue that is going to come up is with the colors. All the colors have to be changed to include the color namespace, like color.red. However, the transparency attribute has been replaced with the color.new() function too, and pinescript will suggest changing colors that include a transparency setting to say, color.new(color.red, 70) instead.

I hope this will help get an alert working for you.