
EMA/MACD/RSIクロス戦略は,複数の技術指標を組み合わせた量化取引戦略である.この戦略は,市場動向を判断し取引信号を生成するために,主にインデックス移動平均 ((EMA),移動平均の相似散乱指数 ((MACD) と相対的に強いインデックス ((RSI) のクロス信号を使用する.この戦略は,動的ストップ損失を設定し,リスクを効果的に制御するために平均真波幅 ((ATR) も導入している.この複数の指標を組み合わせる方法は,取引信号の正確性と信頼性を向上させることを目的としている.
この戦略の核心となる原則は,複数の指標の交差と配合によって,出場と入場のタイミングを決定することである:
買い条件は,急速EMA上での遅いEMAまたはMACD線上での信号線を穿え,同時にRSIが超売りレベルより高い.売る条件は,その逆である.戦略は,現在のポジション保有状態をチェックすることで,繰り返しポジション開設を回避し,資金利用の効率性を高める.
EMA/MACD/RSI交差策略は,多指標の協同作用によって取引機会を識別し,リスクを管理するための総合的な技術分析取引システムである.この戦略の主要な優点は,多次元的な市場分析の視点と柔軟なリスク管理機構である.しかし,ユーザーは,異なる市場環境における戦略のパフォーマンスの違いに注意し,特定の取引品種と市場状況に合わせてパラメータを最適化する必要があります.
/*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)