
この戦略は,相対的に強い弱指数 ((RSI)) と移動平均線散散指 ((MACD)) の2つの技術指標を組み合わせて,RSIが超買い状態を判断し,MACDがトレンド方向を判断し,完全な多空間の戦略を形成します. RSIが超買い時,売る信号を発信し,MACDは速速ラインを横切って上方平仓; RSIが超売り時,買入信号を発信し,MACDは速速ラインを横切って下方平仓. ストップポイントの設定は,その品種の平均落の半分を計算することによって決定されます.
RSIによって超買いと超売りを判断し,市場逆転初期に介入する.MACDを使用してトレンド方向を判断し,トレンド初期に平仓を取って,トレンドをよりよく把握することができる.この2つの指標は互いを補完し,完全な取引システムを形成する.
この戦略は,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")