
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng dựa trên nhiều chỉ số kỹ thuật, kết hợp ba chỉ số kỹ thuật cổ điển là moving average (EMA), moving average convergence (MACD) và tương đối mạnh (RSI) để giao dịch bằng cách nắm bắt sự thay đổi và động lực của xu hướng thị trường. Chiến lược này sử dụng các tham số thiết lập như EMA (9 chu kỳ) và EMA (21 chu kỳ), MACD (12,26,9) và RSI (14) để phát ra tín hiệu giao dịch khi chỉ số vượt qua và phá vỡ ngưỡng.
Lập luận cốt lõi của chiến lược là xác định các điểm biến của xu hướng thị trường thông qua xác nhận đồng bộ của nhiều chỉ số kỹ thuật. Cụ thể, xác nhận tín hiệu bao gồm ba khía cạnh sau:
Chiến lược này được kiểm chứng chéo của nhiều chỉ số kỹ thuật để nắm bắt sự thay đổi của xu hướng thị trường, có độ tin cậy và khả năng thích ứng tốt hơn. Tuy nhiên, trong ứng dụng thực tế, vẫn cần chú ý đến các vấn đề như trễ tín hiệu và giao dịch quá mức, khuyến nghị tối ưu hóa bằng cách giới thiệu các tham số thích ứng, cơ chế dừng lỗ và nhận diện môi trường thị trường để nâng cao tính ổn định và khả năng lợi nhuận của chiến lược. Trong quá trình sử dụng, khuyến nghị kiểm tra dữ liệu lịch sử đầy đủ và tối ưu hóa tham số và liên tục điều chỉnh và hoàn thiện theo hiệu quả giao dịch thực tế.
/*backtest
start: 2024-02-20 00:00:00
end: 2025-02-17 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA + MACD + RSI Strategy with Long and Short", overlay=true)
// Input parameters for MACD, EMA, and RSI
fast_ema_length = input.int(9, title="Fast EMA Length", minval=1)
slow_ema_length = input.int(21, title="Slow EMA Length", minval=1)
macd_short_length = input.int(12, title="MACD Short Length", minval=1)
macd_long_length = input.int(26, title="MACD Long Length", minval=1)
macd_signal_length = input.int(9, title="MACD Signal Length", minval=1)
rsi_length = input.int(14, title="RSI Length", minval=1)
rsi_oversold_level = input.int(30, title="RSI Oversold Level", minval=1)
rsi_overbought_level = input.int(70, title="RSI Overbought Level", minval=1)
// Calculate the MACD line and Signal line
[macdLine, signalLine, _] = ta.macd(close, macd_short_length, macd_long_length, macd_signal_length)
// Calculate the EMAs
fast_ema = ta.ema(close, fast_ema_length)
slow_ema = ta.ema(close, slow_ema_length)
// Calculate the RSI
rsi = ta.rsi(close, rsi_length)
// Conditions for long entry (bullish)
macd_bullish_crossover = ta.crossover(macdLine, signalLine) // MACD line crosses above Signal line
ema_bullish_crossover = ta.crossover(fast_ema, slow_ema) // Fast EMA crosses above Slow EMA
rsi_above_30 = rsi > rsi_oversold_level // RSI above 30 (not oversold)
long_condition = macd_bullish_crossover and ema_bullish_crossover and rsi_above_30
// Conditions for short entry (bearish)
macd_bearish_crossover = ta.crossunder(macdLine, signalLine) // MACD line crosses below Signal line
ema_bearish_crossover = ta.crossunder(fast_ema, slow_ema) // Fast EMA crosses below Slow EMA
rsi_below_70 = rsi < rsi_overbought_level // RSI below 70 (not overbought)
short_condition = macd_bearish_crossover and ema_bearish_crossover and rsi_below_70
// Execute long trade
if (long_condition)
strategy.entry("Long", strategy.long)
// Execute short trade
if (short_condition)
strategy.entry("Short", strategy.short)
// Plot the EMAs and MACD for visualization
plot(fast_ema, color=color.green, linewidth=2, title="Fast EMA")
plot(slow_ema, color=color.red, linewidth=2, title="Slow EMA")
plot(macdLine, color=color.blue, linewidth=2, title="MACD Line")
plot(signalLine, color=color.red, linewidth=2, title="Signal Line")
hline(30, "RSI 30", color=color.green)
hline(70, "RSI 70", color=color.red)
plot(rsi, color=color.purple, linewidth=2, title="RSI")