munsifk

strategy MACD and RSI alert

2422
This is a script I created by combining parts of other scripts I looked at. It uses RSI and MACD to give entrance signals for longs or shorts. When the color changes from red to green it signifies a buy, from green to red signifies a short.

The problem that I am having is that I cannot set up the alert script properly, Using the code :
alert1 = (xRSI > Overbought and signal < macd) ? 1: 0

gives repeat signals every time the criteria reasserts itself, and I only want it to show an alert at the same time the bar color changes.
If I could get some advice on how to set up the alert so it only alerts me at the same time that the bars change color, it would be much appreciated.
Thankyou
Script de código aberto

Dentro do verdadeiro espírito TradingView, o autor deste script publicou ele como um script de código aberto, para que os traders possam compreender e checar ele. Um viva ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.

Quer usar esse script no gráfico?
////////////////////////////////////////////////////////////
study(title="Strategy MACD and RSI alert", shorttitle="Strategy MACD and RSI alert", overlay = false )
fastLength = input(8, minval=1)
slowLength = input(16,minval=1)
signalLength=input(11,minval=1)
hline(0, color=purple, linestyle=dashed)
fastMA = ema(close, fastLength)
slowMA = ema(close, slowLength)
macd = fastMA - slowMA
signal = sma(macd, signalLength)

Length = input(10, minval=1)
Oversold = input(49, minval=1)
Overbought = input(51, minval=1)
xRSI = rsi(close, Length)



pos = iff(xRSI > Overbought and signal < macd, 1,
        iff(xRSI < Oversold and signal > macd, -1, nz(pos[1], 0))) 
barcolor(pos == -1 ? red: pos == 1 ? green : blue)


plot(pos, title="pos", style=line, linewidth=1, color=red )