-- === DAM Trader Script (Versión Mejorada) ===
-- Autor: Adaptado por ChatGPT
-- Descripción: Indicador modular con lógica clara de trading, sin duplicaciones
instrument {
name = 'DAM Trader Script Mejorado',
short_name = 'DAM Trader',
icon = "None",
overlay = true
}
-- === INPUTS GENERALES ===
MaFast_period = input(3, "Periodo MA Rápida", input.integer, 1, 1000, 1)
MaSlow_period = input(50, "Periodo MA Lenta", input.integer, 1, 1000, 1)
Signal_period = input(5, "Periodo Señal", input.integer, 1, 1000, 1)
MaFast_type = input(4, "Tipo MA Rápida", input.string_selection, averages.titles)
MaSlow_type = input(4, "Tipo MA Lenta", input.string_selection, averages.titles)
Source_input = input(1, "Fuente de datos", input.string_selection, inputs.titles)
-- === FILTROS ADICIONALES ===
trend_tf = input("1H", "Marco temporal de tendencia", input.string_selection,
{"1m","5m","15m","1H","4H","1D"})
trend_ema_len = input(100, "EMA de tendencia", input.integer, 10, 200)
rsi_len = input(14, "Periodo del RSI", input.integer, 2, 50)
rsi_buy_level = input(50, "Nivel mínimo de RSI para comprar", input.integer, 1,
100)
rsi_sell_level = input(50, "Nivel máximo de RSI para vender", input.integer, 1,
100)
-- === INPUTS DE VISUALIZACIÓN ===
input_group {
"Colores y visibilidad",
colorBuy = input { default = "green", type = input.color },
colorSell = input { default = "red", type = input.color },
widthFast = input { default = 1, type = input.line_width },
widthSlow = input { default = 2, type = input.line_width },
visibleFast = input { default = true, type = input.plot_visibility },
visibleSlow = input { default = true, type = input.plot_visibility },
visibleBuy = input { default = true, type = input.plot_visibility },
visibleSell = input { default = true, type = input.plot_visibility }
}
-- === CÁLCULO DE MEDIAS ===
local source = inputs[Source_input]
local maFastFunc = averages[MaFast_type]
local maSlowFunc = averages[MaSlow_type]
local maFast = maFastFunc(source, MaFast_period)
local maSlow = maSlowFunc(source, MaSlow_period)
-- === CÁLCULO DE SEÑAL ===
local diff = maFast - maSlow
local signal = wma(diff, Signal_period)
-- === FILTRO DE TENDENCIA Y CONFIRMACIÓN RSI ===
local trend_ema = security(current_ticker_id, trend_tf, ema(close, trend_ema_len))
local isUpTrend = close > trend_ema
local isDnTrend = close < trend_ema
local rsi_val = rsi(close, rsi_len)
-- === CONDICIONES DE COMPRA Y VENTA ===
local buyCondition = diff > signal and diff[1] < signal[1] and isUpTrend and
rsi_val > rsi_buy_level
local sellCondition = diff < signal and diff[1] > signal[1] and isDnTrend and
rsi_val < rsi_sell_level
-- === ALERTAS ===
alertcondition(buyCondition, "Alerta de Compra", "Condición de compra activada")
alertcondition(sellCondition, "Alerta de Venta", "Condición de venta activada")
-- === PLOTEO DE FLECHAS ===
if visibleBuy then
plot_shape(buyCondition, "Compra", shape_style.arrowup, shape_size.normal,
colorBuy, shape_location.belowbar)
end
if visibleSell then
plot_shape(sellCondition, "Venta", shape_style.arrowdown, shape_size.normal,
colorSell, shape_location.abovebar)
end
-- === PLOTEO DE MEDIAS ===
if visibleFast then
plot(maFast, "MA Rápida", colorBuy, widthFast)
end
if visibleSlow then
plot(maSlow, "MA Lenta", colorSell, widthSlow)
end
-- === OPCIONAL: BANDAS DE BOLLINGER Y EMA ===
bb_period = 20
ema_period = 100
sma_bb = sma(close, bb_period)
std_dev = stdev(close, bb_period)
upper_band = sma_bb + std_dev * 2
lower_band = sma_bb - std_dev * 2
ema_line = ema(close, ema_period)
plot(upper_band, "Banda Superior", "#cccccc")
plot(lower_band, "Banda Inferior", "#cccccc")
plot(ema_line, "EMA", "#999999")