
Chiến lược này kết hợp hai chỉ số kỹ thuật là chỉ số tương đối mạnh (RSI) và chỉ số phân tán đường trung bình di chuyển (MACD) để sử dụng RSI để đánh giá tình trạng quá mua quá bán và MACD để đánh giá hướng xu hướng, tạo thành một bộ chiến lược đa luồng hoàn chỉnh. Khi RSI quá mua, nó phát ra tín hiệu bán, MACD nhanh chóng cắt ngang lên; khi RSI quá bán, nó phát ra tín hiệu mua, MACD nhanh chóng cắt ngang xuống.
Sử dụng RSI để đánh giá tình trạng quá mua quá bán, can thiệp vào thời điểm thị trường đảo ngược; Sử dụng MACD để đánh giá xu hướng xu hướng, trong khi xu hướng bắt đầu bằng phẳng, có thể nắm bắt xu hướng tốt hơn. Hai chỉ số bổ sung cho nhau, tạo thành một hệ thống giao dịch hoàn chỉnh.
Chiến lược này tạo thành một hệ thống giao dịch đa chiều hoàn chỉnh bằng cách đánh giá RSI về tình trạng quá mua quá bán và MACD về hướng xu hướng. Lập luận của chiến lược là rõ ràng, lợi thế rõ ràng, nhưng cũng có một số rủi ro. Bằng cách tối ưu hóa tham số, thêm điều kiện lọc, quản lý vị trí và kết hợp với các chiến lược khác, bạn có thể nâng cao hiệu suất của chiến lược hơn nữa, làm cho nó trở thành một chiến lược giao dịch vững chắc.
/*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")