
Chiến lược chéo EMA/MACD/RSI là một chiến lược giao dịch định lượng kết hợp nhiều chỉ số kỹ thuật. Chiến lược này chủ yếu sử dụng tín hiệu chéo của chỉ số di chuyển trung bình (EMA), chỉ số phân tán xu hướng trung bình di chuyển (MACD) và chỉ số phân tán xu hướng tương đối mạnh (RSI) để đánh giá xu hướng thị trường và tạo ra tín hiệu giao dịch. Chiến lược cũng giới thiệu sóng trung bình thực tế (ATR) để thiết lập dừng động, kiểm soát rủi ro hiệu quả.
Nguyên tắc cốt lõi của chiến lược này là xác định thời gian vào và ra sân thông qua sự giao thoa và phối hợp của nhiều chỉ số:
Điều kiện mua là EMA nhanh trên đường EMA chậm hoặc MACD trên đường tín hiệu, trong khi RSI cao hơn mức bán quá. Điều kiện bán ngược lại. Chiến lược cũng giúp tránh mở vị trí lặp lại bằng cách kiểm tra trạng thái giữ vị trí hiện tại và tăng hiệu quả sử dụng vốn.
Chiến lược giao dịch chéo EMA/MACD/RSI là một hệ thống giao dịch phân tích kỹ thuật tổng hợp mạnh mẽ để xác định cơ hội giao dịch và quản lý rủi ro thông qua sự phối hợp của nhiều chỉ số. Ưu điểm chính của chiến lược này là tầm nhìn phân tích thị trường đa chiều và cơ chế quản lý rủi ro linh hoạt. Tuy nhiên, người dùng cần chú ý đến sự khác biệt về hiệu suất của chiến lược trong các môi trường thị trường khác nhau và tối ưu hóa các tham số cho các loại giao dịch và tình trạng thị trường cụ thể.
/*backtest
start: 2024-10-06 00:00:00
end: 2024-10-13 00:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Mister Buy / sell signals", overlay=true, shorttitle="Mister Buy / sell signals")
// ─────────────────────────────────────────────────────────────
// Paramètres des EMA et adaptation selon le timeframe
ema_fast_length = input(3, title="EMA Rapide (12)")
ema_slow_length = input(4, title="EMA Lente (26)")
ema_long_length = input(5, title="EMA Longue (50)")
// Paramètres MACD
macd_fast_length = input(1, title="MACD Période Rapide")
macd_slow_length = input(2, title="MACD Période Lente")
macd_signal_length = input(3, title="MACD Signal (9)")
// Paramètres RSI
rsi_length = input(42, title="RSI Période")
rsi_overbought = input(70, title="RSI Zone de surachat")
rsi_oversold = input(30, title="RSI Zone de survente")
// Paramètres ATR
atr_length = input(12, title="ATR Période")
atr_multiplier = input(1.0, title="Multiplicateur ATR pour Stop")
// ─────────────────────────────────────────────────────────────
// Calcul des EMA
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
ema_long = ta.ema(close, ema_long_length)
// Calcul du RSI
rsi = ta.rsi(close, rsi_length)
// Calcul du MACD
[macdLine, signalLine, _] = ta.macd(close, macd_fast_length, macd_slow_length, macd_signal_length)
// Calcul de l'ATR pour gérer les stops
atr_value = ta.atr(atr_length)
// ─────────────────────────────────────────────────────────────
// Conditions d'achat et de vente basées sur MACD, EMA et RSI
buy_condition = (ta.crossover(ema_fast, ema_slow) or ta.crossover(macdLine, signalLine)) and rsi > rsi_oversold
sell_condition = (ta.crossunder(ema_fast, ema_slow) or ta.crossunder(macdLine, signalLine)) and rsi < rsi_overbought
// ─────────────────────────────────────────────────────────────
// Vérification des positions ouvertes pour éviter les doublons
long_position = strategy.position_size > 0 // Position d'achat ouverte
short_position = strategy.position_size < 0 // Position de vente ouverte
// ─────────────────────────────────────────────────────────────
// Gestion des positions et Stop Loss
long_stop = close - atr_value * atr_multiplier
short_stop = close + atr_value * atr_multiplier
// Entrer les positions uniquement si aucune position n'est ouverte dans la même direction
if (buy_condition and not long_position)
strategy.entry("Buy", strategy.long)
strategy.exit("Exit Buy", from_entry="Buy", stop=long_stop)
if (sell_condition and not short_position)
strategy.entry("Sell", strategy.short)
strategy.exit("Exit Sell", from_entry="Sell", stop=short_stop)
// ─────────────────────────────────────────────────────────────
// Affichage des EMA et du MACD sur le graphique
plot(ema_fast, color=color.green, linewidth=2, title="EMA Rapide (12)")
plot(ema_slow, color=color.red, linewidth=2, title="EMA Lente (26)")
plot(ema_long, color=color.blue, linewidth=1, title="EMA Longue (50)")
plot(macdLine, color=color.green, title="MACD Line")
plot(signalLine, color=color.red, title="MACD Signal Line")
// ─────────────────────────────────────────────────────────────
// Signaux graphiques pour les points d'entrée et de sortie
// Affichage des signaux d'achat si aucune position Buy n'est active
plotshape(series=buy_condition and not long_position, title="Signal Achat", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", textcolor=color.white)
// Affichage des signaux de vente si aucune position Sell n'est active
plotshape(series=sell_condition and not short_position, title="Signal Vente", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", textcolor=color.white)