
이 전략은 상대적으로 강하고 약한 지수 ((RSI) 와 이동 평균 분산 지수 ((MACD) 의 두 가지 기술 지표를 결합하여 RSI를 사용하여 과매매를 판단하고 MACD는 트렌드 방향을 판단하여 전체 다중 포지션 전략을 형성합니다. RSI가 과매를 할 때 판매 신호를 발산하면 MACD는 빠른 느린 선을 넘어서 상향 평정; RSI가 과매를 할 때 구매 신호를 발산하면 MACD는 빠른 느린 선을 넘어서 상향 평정.
RSI를 통해 과매매 상황을 판단하고, 시장이 반전 초기에는 개입한다. MACD를 사용하여 트렌드 방향을 판단하고, 트렌드 초기에는 평점으로, 트렌드를 더 잘 파악할 수 있다. 두 지표는 서로 보완하여 완전한 거래 시스템을 형성한다.
이 전략은 RSI가 과매매를 판단하고 MACD는 트렌드 방향을 판단하여 전체적인 다중 포지션 거래 시스템을 형성한다. 전략 논리는 명확하고 장점은 분명하며, 또한 위험이 존재한다. 매개 변수 최적화, 필터 조건, 포지션 관리 및 다른 전략과 결합하는 방법으로 전략의 성능을 더욱 향상시킬 수 있으며, 안정적인 거래 전략이 될 수 있다.
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="RSI & MACD Strategy", shorttitle="RSI & MACD", overlay=true)
// Définition des entrées
rsi_length = 14
rsi_overbought = 70
rsi_oversold = 30
macd_fast_length = 12
macd_slow_length = 26
macd_signal_length = 9
// Fonction pour calculer le RSI
calculate_rsi(source, length) =>
price_change = ta.change(source)
up = ta.rma(price_change > 0 ? price_change : 0, length)
down = ta.rma(price_change < 0 ? -price_change : 0, length)
rs = up / down
rsi = 100 - (100 / (1 + rs))
rsi
// Fonction pour calculer le MACD
calculate_macd(source, fast_length, slow_length, signal_length) =>
fast_ma = ta.ema(source, fast_length)
slow_ma = ta.ema(source, slow_length)
macd = fast_ma - slow_ma
signal = ta.ema(macd, signal_length)
hist = macd - signal
[macd, signal, hist]
// Calcul des indicateurs
rsi_value = calculate_rsi(close, rsi_length)
[macd_line, signal_line, _] = calculate_macd(close, macd_fast_length, macd_slow_length, macd_signal_length)
// Conditions d'entrée et de sortie
// Entrée en vente : RSI passe de >= 70 à < 70
sell_entry_condition = ta.crossunder(rsi_value, rsi_overbought)
// Sortie en vente : MACD fast MA croise au-dessus de slow MA
sell_exit_condition = ta.crossover(macd_line, signal_line)
// Entrée en achat : RSI passe de <= 30 à > 30
buy_entry_condition = ta.crossover(rsi_value, rsi_oversold)
// Sortie en achat : MACD fast MA croise en-dessous de slow MA
buy_exit_condition = ta.crossunder(macd_line, signal_line)
// Affichage des signaux sur le graphique
plotshape(series=sell_entry_condition, title="Sell Entry", location=location.belowbar, color=color.red, style=shape.triangleup, size=size.small)
plotshape(series=sell_exit_condition, title="Sell Exit", location=location.abovebar, color=color.green, style=shape.triangledown, size=size.small)
plotshape(series=buy_entry_condition, title="Buy Entry", location=location.abovebar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=buy_exit_condition, title="Buy Exit", location=location.belowbar, color=color.red, style=shape.triangledown, size=size.small)
// Entrées et sorties de la stratégie
if (sell_entry_condition)
strategy.entry("Short", strategy.short)
if (sell_exit_condition)
strategy.close("Short")
if (buy_entry_condition)
strategy.entry("Long", strategy.long)
if (buy_exit_condition)
strategy.close("Long")