pine-scriptalerts

Can't seem to trigger the RSI alerts that I have set ? Yet everthing seems to be working with Pinescript


I'm using the original source code for the tradingview RSI indicator and I'm trying to tweak it to send me alerts when the RSI signal is coming out of overbought or oversold. I feel like I'm almost there but I'm missing something to allow me to adjust the alerts? To be completely honest I don't know what I'm missing I need some help on this one big time.

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")

//Get Values
len = input(10, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
overbought = input(title="OB",defval=70)
oversold = input(title="OS",defval=30)

//RSI Value
rsiValue = rsi(src, len)
rsiOverbought = barstate.isconfirmed and crossunder(rsiValue, overbought)
rsiOversold = barstate.isconfirmed and crossover(rsiValue, oversold)

//Alerts
alertcondition(rsiOverbought, title = "Overbought", message = "{{close}}")
alertcondition(rsiOversold, title = "Oversold", message = "{{close}}")
    
// Plotted Values    
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")

Any help would be so awesome and thanks!

Paul


Solution

  • You also need to create an alert from the alert manager. You can do so by clicking the alert button on the top or right toolbar, or simply pressing ALT + A.

    https://www.tradingview.com/support/solutions/43000595315-how-to-set-up-alerts/

    Click this link to read more about how to set them up.

    This should fix it.

    rsiOverbought = barssince(rsiValue > overbought) == 1
    rsiOversold = barssince(rsiValue < oversold) == 1
    

    Edit 2:

    //@version=4
    study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
    
    //Get Values
    len = input(10, minval=1, title="Length")
    src = input(close, "Source", type = input.source)
    up = rma(max(change(src), 0), len)
    down = rma(-min(change(src), 0), len)
    rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
    overbought = input(title="OB",defval=70)
    oversold = input(title="OS",defval=30)
    
    //RSI Value
    rsiValue = rsi(src, len)
    rsiOverbought = barssince(rsiValue > overbought) == 1
    rsiOversold = barssince(rsiValue < oversold) == 1
    
    bgcolor(rsiOverbought ? color.green : na)
    bgcolor(rsiOversold ? color.blue : na)
    
    //Alerts
    alertcondition(rsiOverbought, title = "Overbought", message = "{{close}}")
    alertcondition(rsiOversold, title = "Oversold", message = "{{close}}")
        
    // Plotted Values    
    plot(rsi, "RSI", color=#7E57C2)
    band1 = hline(70, "Upper Band", color=#787B86)
    bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
    band0 = hline(30, "Lower Band", color=#787B86)
    fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")