Tabela de conteúdos

Alertas em Study()

Eventos de Alertas

alert

Chamada alert() Exemplo RSI

//@version=4
study("Todas as chamadas Alert")
 
r = rsi(close, 20)
 
// Detectar cruzamento
xUp = crossover(r, 50)
xDn = crossunder(r, 50)
 
// Disparar alerta no cruzamento
if xUp
    alert("Comprar (RSI é " + tostring(r, "#.00)"))
else if xDn
    alert("Vender (RSI é " + tostring(r, "#.00)"))
 
plotchar(xUp, "Compra", "▲", location.bottom, color.lime, size = size.tiny)
plotchar(xDn, "Venda", "▼", location.top, color.red, size = size.tiny)
 
hline(50)
plot(r)
// Disparar alerta no cruzamento
if xUp or xDn
    firstPart = (xUp ? "Comprar" : "Vender") + " (RSI é "
alert(firstPart + tostring(r, "#.00)"))

Chamada alert() seletiva

//@version=4
study("Chamadas Seletivas Alert")
 
// Parâmetros
detecCompra = input(true,  "Alertar Compra")
detecVenda  = input(true,  "Alertar Venda")
 
r = rsi(close, 20)
 
// Detectar cruzamento.
xUp = crossover(r, 50)
xDn = crossunder(r, 50)
 
// Apenas gerar alertas para as direções configuradas.
alC = detecCompra and xUp
alV  = detecVenda and xDn
 
// Disparar o alerta apenas quando o grupo de condições são satisfeitas.
if alC
    alert("Compra (RSI é " + tostring(r, "#.00)"))
else if alV
    alert("Vender (RSI é " + tostring(r, "#.00)"))
 
plotchar(alC, "Compra", "▲", location.bottom, color.lime, size = size.tiny)
plotchar(alV, "Venda", "▼", location.top, color.red, size = size.tiny)
 
hline(50)
plot(r)