I am learning Pine Script and I just "finished" my first indicator.
Everything seems to be doing it's job, except for the alerts.
I want to get just 1 alert when it triggers and then wait for the close. However, right now I seem to be getting multiple "open" alerts in a row and also multiple "close" alerts in a row.
What am I missing?
//@version=5
indicator("SMA + ATR Bands with RSI and Alerts", overlay=true)
// Calculate SMA over the past 200 bars
smaValue = ta.sma(close, 200)
// Calculate ATR over the past 7 bars
atrValue = ta.atr(7)
// Calculate upper and lower band values
upperBand = smaValue + (2 * atrValue)
lowerBand = smaValue - (2 * atrValue)
// Calculate RSI over the past 6 bars
rsiValue = ta.rsi(close, 6)
// Calculate buy and close buy signals
buySignal = ta.crossover(close, lowerBand) and (rsiValue > 50)
closeBuySignal = ta.crossunder(close, upperBand)
// Plot SMA, upper band, lower band, and RSI on the chart
plot(smaValue, "SMA", color = color.blue)
plot(upperBand, "Upper Band", color = color.green)
plot(lowerBand, "Lower Band", color = color.red)
plot(rsiValue, "RSI", color = color.purple)
// Plot buy and close buy signals
plotshape(
buySignal ? high : na,
title = 'Long Label',
text = 'Long',
textcolor = color.white,
color = color.new(color.green, 0),
style = shape.labelup,
size = size.normal,
location = location.belowbar)
plotshape(
closeBuySignal ? high : na,
title = 'Close Long Label',
text = 'Close Long',
textcolor = color.white,
color = color.new(#ff3131, 0),
style = shape.labeldown,
size = size.normal,
location = location.abovebar)
Here's the image of how it looks on chart:
Would really appreciate some help.
Thanks in advance!
Regards,
Molle