Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
2
Indexable
Never
//@version=4
strategy("Estrategia EMA + RSI + MACD Bitcoin", shorttitle="EMA RSI MACD BTC", overlay=true)

// Parámetros EMA
fast_length = input(9, title="EMA rápida", type=input.integer)
slow_length = input(21, title="EMA lenta", type=input.integer)

// Parámetros RSI
rsi_length = input(14, title="Longitud del RSI", type=input.integer)
lookback = input(5, title="Divergencia de lookback", type=input.integer)

// Parámetros MACD
macd_short_length = input(12, title="MACD Longitud corta", type=input.integer)
macd_long_length = input(26, title="MACD Longitud larga", type=input.integer)
macd_signal_length = input(9, title="MACD Longitud de la señal", type=input.integer)

// Calcular medias móviles exponenciales
fast_ema = ema(close, fast_length)
slow_ema = ema(close, slow_length)

// Calcular el RSI
rsi = rsi(close, rsi_length)

// Calcular el MACD
[macdLine, signalLine, _] = macd(close, macd_short_length, macd_long_length, macd_signal_length)

// Detectar divergencias alcistas
bull_div = (close[lookback] < close and rsi[lookback] > rsi)

// Detectar divergencias bajistas
bear_div = (close[lookback] > close and rsi[lookback] < rsi)

// Detectar cruces del MACD
macd_cross_above = crossover(macdLine, signalLine)
macd_cross_below = crossunder(macdLine, signalLine)

// Generar señales de compra y venta
longCondition = crossover(fast_ema, slow_ema) or bull_div or macd_cross_above
shortCondition = crossunder(fast_ema, slow_ema) or bear_div or macd_cross_below

if (longCondition)
    strategy.entry("Long", strategy.long)

if (shortCondition)
    strategy.entry("Short", strategy.short)

// Dibujar medias móviles exponenciales
plot(fast_ema, title="EMA rápida", color=color.blue, linewidth=2)
plot(slow_ema, title="EMA lenta", color=color.red, linewidth=2)