
Đây là một chiến lược giao dịch kết hợp động lực và xu hướng để xác định xu hướng và động lực của thị trường thông qua nhiều chỉ số trung bình di chuyển (EMA), chỉ số tương đối mạnh (RSI) và chỉ số ngẫu nhiên (Stochastic). Chiến lược này cũng tích hợp hệ thống quản lý rủi ro dựa trên sóng trung bình thực tế (ATR), bao gồm các điểm dừng động, mục tiêu thu lợi nhuận và theo dõi điểm dừng lỗ, đồng thời sử dụng phương pháp quản lý vị trí dựa trên rủi ro.
Chiến lược sử dụng 5 EMA của các chu kỳ khác nhau (8, 13, 21, 34, 55) để xác định hướng xu hướng. RSI được sử dụng để xác nhận động lực, đặt các ngưỡng nhập và thoát khác nhau. Chỉ số ngẫu nhiên là bộ lọc thứ ba, giúp tránh mua hoặc bán quá mức. Hệ thống quản lý rủi ro sử dụng ATR để đặt mục tiêu dừng động (ATR 2 lần) và mục tiêu thu lợi (ATR 4 lần) và sử dụng tracking ATR 1.5 lần để bảo vệ lợi nhuận.
Chiến lược này cung cấp một giải pháp giao dịch toàn diện bằng cách kết hợp nhiều chỉ số kỹ thuật và hệ thống quản lý rủi ro tốt. Điểm mạnh cốt lõi của nó là cơ chế lọc nhiều lớp và quản lý rủi ro động, nhưng vẫn cần được tối ưu hóa cho các đặc điểm thị trường cụ thể. Việc thực hiện thành công của chiến lược cần được giám sát và điều chỉnh liên tục, đặc biệt là sự thích ứng của các tham số trong các môi trường thị trường khác nhau.
/*backtest
start: 2024-11-04 00:00:00
end: 2024-12-04 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Combined Strategy (Modernized)", overlay = true)
//----------//
// MOMENTUM //
//----------//
ema8 = ta.ema(close, 8)
ema13 = ta.ema(close, 13)
ema21 = ta.ema(close, 21)
ema34 = ta.ema(close, 34)
ema55 = ta.ema(close, 55)
// Plotting EMAs for visualization
plot(ema8, color=color.red, title="EMA 8", linewidth=1)
plot(ema13, color=color.orange, title="EMA 13", linewidth=1)
plot(ema21, color=color.yellow, title="EMA 21", linewidth=1)
plot(ema34, color=color.aqua, title="EMA 34", linewidth=1)
plot(ema55, color=color.lime, title="EMA 55", linewidth=1)
longEmaCondition = ema8 > ema13 and ema13 > ema21 and ema21 > ema34 and ema34 > ema55
exitLongEmaCondition = ema13 < ema55
shortEmaCondition = ema8 < ema13 and ema13 < ema21 and ema21 < ema34 and ema34 < ema55
exitShortEmaCondition = ema13 > ema55
// ---------- //
// OSCILLATORS //
// ----------- //
rsi = ta.rsi(close, 14)
longRsiCondition = rsi < 70 and rsi > 40
exitLongRsiCondition = rsi > 70
shortRsiCondition = rsi > 30 and rsi < 60
exitShortRsiCondition = rsi < 30
// Stochastic
k = ta.stoch(close, high, low, 14)
d = ta.sma(k, 3)
longStochasticCondition = k < 80
exitLongStochasticCondition = k > 95
shortStochasticCondition = k > 20
exitShortStochasticCondition = k < 5
//----------//
// STRATEGY //
//----------//
// ATR for dynamic stop loss and take profit
atr = ta.atr(14)
stopLossMultiplier = 2
takeProfitMultiplier = 4
stopLoss = atr * stopLossMultiplier
takeProfit = atr * takeProfitMultiplier
// Trailing stop settings
trailStopMultiplier = 1.5
trailOffset = atr * trailStopMultiplier
// Risk management: dynamic position sizing
riskPerTrade = 0.01 // 1% risk per trade
positionSize = strategy.equity * riskPerTrade / stopLoss
longCondition = longEmaCondition and longRsiCondition and longStochasticCondition and strategy.position_size == 0
exitLongCondition = (exitLongEmaCondition or exitLongRsiCondition or exitLongStochasticCondition) and strategy.position_size > 0
if (longCondition)
strategy.entry("LONG", strategy.long, qty=positionSize)
strategy.exit("Take Profit Long", "LONG", stop=close - stopLoss, limit=close + takeProfit, trail_offset=trailOffset)
if (exitLongCondition)
strategy.close("LONG")
shortCondition = shortEmaCondition and shortRsiCondition and shortStochasticCondition and strategy.position_size == 0
exitShortCondition = (exitShortEmaCondition or exitShortRsiCondition or exitShortStochasticCondition) and strategy.position_size < 0
if (shortCondition)
strategy.entry("SHORT", strategy.short, qty=positionSize)
strategy.exit("Take Profit Short", "SHORT", stop=close + stopLoss, limit=close - takeProfit, trail_offset=trailOffset)
if (exitShortCondition)
strategy.close("SHORT")