
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng dựa trên nhiều chỉ số kỹ thuật. Nó kết hợp đường trung bình (EMA), chỉ số tương đối mạnh (RSI), khối lượng giao dịch (Volume) và chỉ số sóng thực (ATR) để xác định thời gian vào và sử dụng ATR để thiết lập các vị trí dừng và dừng động.
Chiến lược sử dụng giao thoa của EMA (9 chu kỳ) và EMA (21 chu kỳ) để nắm bắt sự thay đổi của xu hướng. Dựa trên đó, kết hợp với chỉ số RSI (14 chu kỳ) để lọc các khu vực quá mua và bán, yêu cầu các giá trị RSI nằm ngoài vùng quá mua (70) và quá bán (30). Trong khi đó, chiến lược yêu cầu giao dịch lớn hơn đường trung bình giao dịch 20 chu kỳ và yêu cầu giá mua bán phá vỡ một đường K trước để xác nhận thêm.
Ghi tham số cho chỉ số tự điều chỉnh: Có thể tự động điều chỉnh thiết lập chu kỳ của EMA và RSI theo biến động của thị trường, giúp chiến lược thích ứng tốt hơn với các môi trường thị trường khác nhau.
Thêm bộ lọc môi trường thị trường: Thêm chỉ số cường độ xu hướng như ADX, tự động giảm vị trí hoặc tạm dừng giao dịch trên thị trường ngang.
Tối ưu hóa phương án dừng lỗ: Có thể cân nhắc việc thiết lập dừng lỗ kết hợp với vị trí kháng cự hỗ trợ để tăng hiệu quả của dừng lỗ.
Quản lý khối lượng giao dịch: Điều chỉnh quy mô nắm giữ tùy theo biến động của thị trường và tính thanh khoản.
Đây là một chiến lược theo dõi xu hướng có cấu trúc, logic nghiêm ngặt. Bằng cách sử dụng nhiều chỉ số kỹ thuật, nó đảm bảo độ tin cậy của tín hiệu giao dịch và có thể kiểm soát rủi ro hiệu quả. Các thiết lập dừng lỗ động cung cấp tỷ lệ lợi nhuận tốt hơn so với rủi ro.
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"TRB_USDT"}]
*/
//@version=6
strategy("15m EMA RSI Strategy with ATR SL/TP and Candle Break Confirmation", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// INPUTS
fastLength = input.int(9, title="Fast EMA Length")
slowLength = input.int(21, title="Slow EMA Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
volLength = input.int(20, title="Volume MA Length")
atrLength = input.int(14, title="ATR Length")
atrMultiplierSL = input.float(1.5, title="ATR Multiplier for Stop Loss")
atrMultiplierTP = input.float(3.0, title="ATR Multiplier for Take Profit")
trailingStopMultiplier = input.float(1.0, title="ATR Multiplier for Trailing Stop")
// INDICATOR CALCULATIONS
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
rsiValue = ta.rsi(close, rsiLength)
volMA = ta.sma(volume, volLength)
atr = ta.atr(atrLength)
// Candle Breakout Conditions for Confirmation
longCandleBreak = close > high[1]
shortCandleBreak = close < low[1]
// Plot EMAs for visual reference
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.orange, title="Slow EMA")
// ENTRY CONDITIONS
longCondition = ta.crossover(fastEMA, slowEMA) and (rsiValue < rsiOverbought) and (volume > volMA) and longCandleBreak
shortCondition = ta.crossunder(fastEMA, slowEMA) and (rsiValue > rsiOversold) and (volume > volMA) and shortCandleBreak
// Plot Buy/Sell Signals on the Chart
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, size=size.normal)
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, size=size.normal)
// TRADE EXECUTION WITH ATR-BASED STOP LOSS, TAKE PROFIT, AND TRAILING STOP
if longCondition
longStop = close - atrMultiplierSL * atr
longTP = close + atrMultiplierTP * atr
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry="Long", stop=longStop, limit=longTP, trail_points=atr * trailingStopMultiplier)
if shortCondition
shortStop = close + atrMultiplierSL * atr
shortTP = close - atrMultiplierTP * atr
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", from_entry="Short", stop=shortStop, limit=shortTP, trail_points=atr * trailingStopMultiplier)
// OPTIONAL: Plot RSI for reference
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
plot(rsiValue, color=color.purple, title="RSI")