instrument {
name = "Suporte e Resistência com Liquidez Ajustada",
short_name = "SR Liquidez Ajustada",
overlay = true
}
period = input(30, "Período SMA", input.integer, 1)
input_group {
"Linhas de Suporte e Resistência",
sr_color = input { default = "white", type = input.color },
sr_width = input { default = 1, type = input.line_width }
}
input_group {
"Linhas de Liquidez",
compra_color = input { default = "green", type = input.color },
venda_color = input { default = "red", type = input.color },
liquidez_width = input { default = 1, type = input.line_width }
}
-- Calculando as médias e as bandas de suporte e resistência
sma_value = sma(close, period)
high_band = sma_value + (stdev(close, period) * 2)
low_band = sma_value - (stdev(close, period) * 2)
-- Plotando as linhas de suporte e resistência (fixas)
plot(high_band, "Resistência", sr_color, sr_width)
plot(low_band, "Suporte", sr_color, sr_width)
-- Variáveis para armazenar os níveis de liquidez
nivel_liquidez_compra = na
nivel_liquidez_venda = na
-- Verificação e definição dos níveis de liquidez
if close > high_band and isnan(nivel_liquidez_compra) then
nivel_liquidez_compra = high_band
elseif close < low_band and isnan(nivel_liquidez_venda) then
nivel_liquidez_venda = low_band
end
-- Plotando as linhas de liquidez apenas quando atingidas e mantendo fixas
if not isnan(nivel_liquidez_compra) then
plot(nivel_liquidez_compra, "Liquidez Compra", compra_color, liquidez_width)
end
if not isnan(nivel_liquidez_venda) then
plot(nivel_liquidez_venda, "Liquidez Venda", venda_color, liquidez_width)
end