
Đây là chiến lược giao dịch trong ngày dựa trên hệ thống đường trung bình động kép (EMA) và chỉ số sức mạnh tương đối (RSI). Chiến lược này sử dụng các tín hiệu giao nhau của đường trung bình động hàm mũ nhanh và chậm kết hợp với chỉ báo động lượng RSI để xác định xu hướng thị trường và cơ hội giao dịch, đồng thời tích hợp cơ chế dừng lỗ và chốt lời để quản lý rủi ro. Chiến lược này sử dụng mô hình quản lý tiền và sử dụng một tỷ lệ phần trăm cố định của vốn chủ sở hữu tài khoản để giao dịch.
Logic cốt lõi của chiến lược bao gồm các yếu tố chính sau:
Chiến lược này xây dựng một hệ thống giao dịch hoàn chỉnh bằng cách kết hợp hệ thống xu hướng EMA và chỉ báo động lượng RSI. Ưu điểm của nó nằm ở logic giao dịch có hệ thống và cơ chế quản lý rủi ro hoàn hảo, nhưng vẫn cần phải chú ý đến tác động của môi trường thị trường đến hiệu suất chiến lược. Thông qua việc tối ưu hóa và điều chỉnh liên tục, các chiến lược có thể thích ứng tốt hơn với các điều kiện thị trường khác nhau và cải thiện kết quả giao dịch.
/*backtest
start: 2024-12-17 00:00:00
end: 2025-01-16 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("Estrategia Intradía - Cruce EMA + RSI - Optimizado", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=20)
// Parámetros CON rangos de optimización
ema_fast_length = input.int(title="Período EMA Rápida", defval=12, minval=5, maxval=30, step=1)
ema_slow_length = input.int(title="Período EMA Lenta", defval=26, minval=15, maxval=50, step=1)
rsi_length = input.int(title="Período RSI", defval=14, minval=7, maxval=21, step=1)
rsi_overbought = input.int(title="Nivel de Sobrecompra RSI", defval=70, minval=60, maxval=80, step=1)
rsi_oversold = input.int(title="Nivel de Sobreventa RSI", defval=30, minval=20, maxval=40, step=1)
stop_loss_percent = input.float(title="Stop Loss (%)", defval=1.0, minval=0.1, maxval=3.0, step=0.1)
take_profit_percent = input.float(title="Take Profit (%)", defval=2.0, minval=0.5, maxval=5.0, step=0.1)
// Cálculos
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
rsi = ta.rsi(close, rsi_length)
// Condiciones de entrada
longCondition = ta.crossover(ema_fast, ema_slow) and rsi > 50
shortCondition = ta.crossunder(ema_fast, ema_slow) and rsi < 50
// Gestión de entradas y salidas
var float longQty = na
var float shortQty = na
if longCondition
longQty := 20 / close
strategy.entry("Long", strategy.long, qty=longQty)
if stop_loss_percent > 0 and take_profit_percent > 0
strategy.exit("Exit Long", "Long", stop=close * (1 - stop_loss_percent / 100), limit=close * (1 + take_profit_percent / 100))
if strategy.position_size > 0 and ta.crossunder(ema_fast, ema_slow)
strategy.close("Long")
longQty := na
if shortCondition
shortQty := 20 / close
strategy.entry("Short", strategy.short, qty=shortQty)
if stop_loss_percent > 0 and take_profit_percent > 0
strategy.exit("Exit Short", "Short", stop=close * (1 + stop_loss_percent / 100), limit=close * (1 - take_profit_percent / 100))
if strategy.position_size < 0 and ta.crossover(ema_fast, ema_slow)
strategy.close("Short")
shortQty := na
// Visualizaciones
plot(ema_fast, color=color.blue, title="EMA Rápida")
plot(ema_slow, color=color.orange, title="EMA Lenta")
plot(rsi, color=color.purple, title="RSI")
hline(50, color=color.gray)