Tabela de conteúdos

Alertas em Strategy()

Eventos de Alertas

alert

//@version=4
strategy("Chamadas Seletivas Alert - Strategy")
 
r = rsi(close, 20)
 
// Detectar cruzamento.
xUp = crossover(r, 50)
xDn = crossunder(r, 50)
 
// Enviar ordem no cruzamento.
if xUp
    strategy.entry("Compra", strategy.long)
else if xDn
    strategy.entry("Venda", strategy.short)
 
// Disparar alertar quando o trade vai na direção contrária.
dirCompra  = strategy.position_size > 0 and falling(r, 3)
dirVenda = strategy.position_size < 0 and rising(r, 3)
 
if dirCompra
    alert("AVISO: RSI Caindo", alert.freq_once_per_bar_close)
if dirVenda
    alert("AVISO: RSI Subindo", alert.freq_once_per_bar_close)
 
plotchar(xUp, "Compra", "▲", location.bottom, color.lime, size = size.tiny)
plotchar(xDn, "Venda", "▼", location.top, color.red, size = size.tiny)
 
plotchar(dirCompra, "AVISO: RSI Caindo", "•", location.top, color.red, size = size.tiny)
plotchar(dirVenda, "AVISO: RSI Subindo",  "•", location.bottom, color.lime, size = size.tiny)
 
hline(50)
plot(r)

Eventos de Envio de Ordens (Order fill events)

Customizar mensagem de alerta

//@version=4
strategy("Estratégia usando alert_message")
 
r = rsi(close, 20)
 
// Detectar cruzamento
xUp = crossover(r, 50)
xDn = crossunder(r, 50)
 
// Enviar ordens no cruzamento usando alert_message customizado
if xUp
    strategy.entry("Compra", strategy.long, stop = high, alert_message = "Compra-Stop execuata (stop foi em " + tostring(high) + ")")
else if xDn
    strategy.entry("Venda", strategy.short, stop = low, alert_message = "Venda-Stop executada (stop foi em " + tostring(low) + ")")
 
plotchar(xUp, "Comprar", "▲", location.bottom, color.lime, size = size.tiny)
plotchar(xDn, "Vender", "▼", location.top, color.red, size = size.tiny)
 
hline(50)
plot(r)