
Chiến lược này là một hệ thống theo dõi xu hướng kết hợp nhiều chỉ số kỹ thuật, chủ yếu là tích hợp năm chu kỳ khác nhau của chỉ số di chuyển trung bình (EMA), chỉ số tương đối mạnh (RSI) và hai chu kỳ khác nhau của kênh Donchian (Channel Donchian). Hệ thống này nắm bắt xu hướng thị trường bằng cách kết hợp nhiều chỉ số và sử dụng các mục tiêu dừng lỗ và lợi nhuận động để quản lý rủi ro và lợi nhuận.
Chiến lược sử dụng nhiều lớp chỉ số kỹ thuật để xác nhận tín hiệu: Đầu tiên, sử dụng 5 EMA ((9, 21, 55, 89, 144 chu kỳ) để xây dựng khung xu hướng, xác định hướng xu hướng ban đầu bằng cách giao chéo EMA nhanh với EMA chậm. Tiếp theo, sử dụng RSI ((chu kỳ 14) làm bộ lọc xu hướng, yêu cầu RSI ở vùng quá mua ((60 trở lên) chỉ được phép làm nhiều hơn và ở vùng quá bán ((40 dưới) chỉ được phép làm rỗng, để tránh giao dịch thường xuyên trong thị trường tròn. Cuối cùng, xác định phạm vi biến động giá thông qua kênh Đường Chi Minh của chu kỳ 21 và chu kỳ 74, cung cấp thêm cấu trúc thị trường để giao dịch.
Chiến lược này xây dựng một hệ thống giao dịch tương đối hoàn chỉnh thông qua sự kết hợp của nhiều chỉ số kỹ thuật. Mặc dù có một số chậm trễ, nhưng có thể đạt được lợi nhuận ổn định trong thị trường xu hướng thông qua lọc tín hiệu và quản lý rủi ro nghiêm ngặt.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-04 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA RSI Donchian Strategy", overlay=true)
// Input parameters
fastEmaLength = input(9, title="Fast EMA Length")
midEmaLength = input(21, title="Mid EMA Length")
slowEmaLength = input(55, title="Slow EMA Length")
ema89Length = input(89, title="89 EMA Length")
ema144Length = input(144, title="144 EMA Length")
rsiPeriod = input(14, title="RSI Period")
rsiOverbought = input(60, title="RSI Overbought Level")
rsiOversold = input(40, title="RSI Oversold Level")
donchianLength1 = input(21, title="Donchian Channel Length 1")
donchianLength2 = input(74, title="Donchian Channel Length 2")
// EMA calculations
fastEma = ta.ema(close, fastEmaLength)
midEma = ta.ema(close, midEmaLength)
slowEma = ta.ema(close, slowEmaLength)
ema89 = ta.ema(close, ema89Length)
ema144 = ta.ema(close, ema144Length)
// RSI calculation
rsi = ta.rsi(close, rsiPeriod)
// Donchian Channel calculations
donchianUpper1 = ta.highest(high, donchianLength1)
donchianLower1 = ta.lowest(low, donchianLength1)
donchianUpper2 = ta.highest(high, donchianLength2)
donchianLower2 = ta.lowest(low, donchianLength2)
donchianMid1 = (donchianUpper1 + donchianLower1) / 2
donchianMid2 = (donchianUpper2 + donchianLower2) / 2
// Plot EMAs
plot(fastEma, color=color.green, linewidth=2, title="Fast EMA")
plot(midEma, color=color.blue, linewidth=2, title="Mid EMA")
plot(slowEma, color=color.orange, linewidth=2, title="Slow EMA")
plot(ema89, color=color.red, linewidth=2, title="89 EMA")
plot(ema144, color=color.purple, linewidth=2, title="144 EMA")
// Plot Donchian Channels
plot(donchianUpper1, color=color.new(color.blue, 0), title="Donchian Upper 1")
plot(donchianLower1, color=color.new(color.blue, 0), title="Donchian Lower 1")
plot(donchianMid1, color=color.new(color.blue, 80), title="Donchian Mid 1")
plot(donchianUpper2, color=color.new(color.red, 0), title="Donchian Upper 2")
plot(donchianLower2, color=color.new(color.red, 0), title="Donchian Lower 2")
plot(donchianMid2, color=color.new(color.red, 80), title="Donchian Mid 2")
// Entry Conditions
longCondition = ta.crossover(fastEma, slowEma) and rsi > rsiOverbought
shortCondition = ta.crossunder(fastEma, slowEma) and rsi < rsiOversold
// Stop Loss and Take Profit
var float longStopLoss = na
var float longTakeProfit1 = na
var float longTakeProfit2 = na
var float shortStopLoss = na
var float shortTakeProfit1 = na
var float shortTakeProfit2 = na
if longCondition
longStopLoss := high * 0.99
longTakeProfit1 := longStopLoss * 1.02618
longTakeProfit2 := longStopLoss * 1.036185
strategy.entry("Long", strategy.long)
if shortCondition
shortStopLoss := low * 1.01
shortTakeProfit1 := shortStopLoss * 0.97382
shortTakeProfit2 := shortTakeProfit1 * 0.96381
strategy.entry("Short", strategy.short)
// Exit Conditions
if not na(longStopLoss)
strategy.exit("Take Profit 1", "Long", limit=longTakeProfit1)
strategy.exit("Take Profit 2", "Long", limit=longTakeProfit2)
strategy.exit("Stop Loss", "Long", stop=longStopLoss)
if not na(shortStopLoss)
strategy.exit("Take Profit 1", "Short", limit= shortTakeProfit1)
strategy.exit("Take Profit 2", "Short", limit=shortTakeProfit2)
strategy.exit("Stop Loss", "Short", stop=shortStopLoss)
// Labels for buy and sell signals
if longCondition
label.new(bar_index, low, "Buy", color=color.green, style=label.style_label_up, textcolor=color.white)
if shortCondition
label.new(bar_index, high, "Sell", color=color.red, style=label.style_label_down, textcolor=color.white)
// Alerts
alertcondition(longCondition, title="Long Entry Alert", message="Long entry signal")
alertcondition(shortCondition, title="Short Entry Alert", message="Short entry signal")