instrument { name = "Media_Rsi_Fibo", icon="jpg", overlay = true }
-- Configuração de cores
input_group { "Suporte, Resistência e Tendências",
suporte_color = input { default = "#008000", type = [Link] },
resistencia_color = input { default = "#FF0000", type = [Link] },
ltb_lta_color = input { default = "#0000FF", type = [Link] },
linha_largura = input { default = 2, type = input.line_width }
}
input_group { "Padrões de Candle",
call_color = input { default = "#00FF00", type = [Link] },
put_color = input { default = "#FF4500", type = [Link] }
}
input_group { "Médias Móveis e RSI",
ema_curta = input { default = 9, type = [Link] },
ema_media = input { default = 21, type = [Link] },
ema_longa = input { default = 200, type = [Link] },
rsi_period = input { default = 14, type = [Link] },
rsi_sobrecompra = input { default = 70, type = [Link] },
rsi_sobrevenda = input { default = 30, type = [Link] }
}
input_group { "Fibonacci",
fib_retracao_1 = input { default = 0.382, type = [Link] },
fib_retracao_2 = input { default = 0.618, type = [Link] }
}
-- Cálculo das médias móveis
EMA_Curta = ema(close, ema_curta)
EMA_Media = ema(close, ema_media)
EMA_Longa = ema(close, ema_longa)
-- Cálculo do RSI
RSI_Valor = rsi(close, rsi_period)
-- Suporte e resistência baseados nos últimos 20 candles
suporte = lowest(low, 20)
resistencia = highest(high, 20)
-- Identificação de tendência: LTB e LTA (usando máximas e mínimas)
LTB = linear_regression(high, 20, 0)
LTA = linear_regression(low, 20, 0)
-- Cálculo de retrações de Fibonacci com base nos últimos 20 candles
fib_high = highest(high, 20)
fib_low = lowest(low, 20)
fib_38 = fib_high - (fib_high - fib_low) * fib_retracao_1
fib_61 = fib_high - (fib_high - fib_low) * fib_retracao_2
-- Padrões de candle
bullish_engulfing = (close[1] < open[1]) and (close > open) and (close > high[1])
bearish_engulfing = (close[1] > open[1]) and (close < open) and (close < low[1])
martelo = (low < low[1]) and (close > open) and ((high - close) < (close - open) *
0.3)
estrela_cadente = (high > high[1]) and (close < open) and ((low - close) < (open -
close) * 0.3)
-- Confirmação de entrada
compra_confirmada = (EMA_Curta > EMA_Media) and (RSI_Valor > rsi_sobrevenda) and
(close > suporte or close > fib_38) and (bullish_engulfing or martelo)
venda_confirmada = (EMA_Curta < EMA_Media) and (RSI_Valor < rsi_sobrecompra) and
(close < resistencia or close < fib_61) and (bearish_engulfing or estrela_cadente)
-- Plotando suporte e resistência
plot(suporte, "Suporte", suporte_color, linha_largura)
plot(resistencia, "Resistência", resistencia_color, linha_largura)
-- Plotando médias móveis com as cores especificadas
plot(EMA_Curta, "EMA Curta", "#00FFFF", 2)
plot(EMA_Media, "EMA Média", "#FF00FF", 2)
plot(EMA_Longa, "EMA Longa", "#FF0000", 2) -- Vermelho
-- Plotando linhas de tendência (LTB e LTA)
plot(LTB, "LTB", ltb_lta_color, linha_largura)
plot(LTA, "LTA", ltb_lta_color, linha_largura)
-- Plotando retrações de Fibonacci
plot(fib_38, "Fibo 38.2%", "#FFA500", linha_largura)
plot(fib_61, "Fibo 61.8%", "#FFD700", linha_largura)
-- Plotando sinais de entrada
if compra_confirmada then
plot_shape(1, "Sinal de Compra", shape_style.arrowup, shape_size.huge,
call_color, shape_location.belowbar, 0, "COMPRA", "#00FF00")
end
if venda_confirmada then
plot_shape(1, "Sinal de Venda", shape_style.arrowdown, shape_size.huge,
put_color, shape_location.abovebar, 0, "VENDA", "#FF4500")
end