
Chiến lược này là một hệ thống giao dịch tổng hợp kết hợp theo dõi xu hướng và kiểm soát rủi ro. Nó sử dụng chỉ số di chuyển 200 chu kỳ ((EMA) làm bộ lọc xu hướng, chỉ số tương đối mạnh ((RSI) làm tín hiệu đầu vào, đồng thời tích hợp các cơ chế kiểm soát dừng lỗ, dừng và rút lui tối đa. Đặc điểm chính của chiến lược là duy trì lợi thế theo dõi xu hướng đồng thời kiểm soát rủi ro nghiêm ngặt bằng cách theo dõi hồi phục động.
Logic cốt lõi của chiến lược bao gồm các thành phần quan trọng sau:
Chiến lược này xây dựng một hệ thống giao dịch hoàn chỉnh bằng cách kết hợp theo dõi xu hướng và kiểm soát rủi ro nghiêm ngặt. Ưu điểm cốt lõi của nó là tính toàn vẹn của quản lý rủi ro và sự rõ ràng của logic chiến lược.
/*backtest
start: 2024-11-19 00:00:00
end: 2024-12-19 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Disruptor Trend-Following (Drawdown < 30%)", shorttitle="DisruptorStrategyDD", overlay=true)
//-----------------------------------------------------
// User Inputs
//-----------------------------------------------------
emaLen = input.int(200, "Long EMA Length", minval=1)
rsiLen = input.int(14, "RSI Length", minval=1)
rsiThreshold = input.float(50, "RSI Buy Threshold", minval=1, maxval=100)
stopLossPerc = input.float(20, "Stop-Loss %", minval=0.1, step=0.1)
takeProfitPerc = input.float(40, "Take-Profit %", minval=0.1, step=0.1)
ddLimit = input.float(30, "Max Drawdown %", minval=0.1, step=0.1)
//-----------------------------------------------------
// Indicators
//-----------------------------------------------------
emaValue = ta.ema(close, emaLen)
rsiValue = ta.rsi(close, rsiLen)
//-----------------------------------------------------
// Conditions
//-----------------------------------------------------
longCondition = close > emaValue and rsiValue > rsiThreshold
exitCondition = close < emaValue or rsiValue < rsiThreshold
//-----------------------------------------------------
// Position Tracking
//-----------------------------------------------------
var bool inTrade = false
if longCondition and not inTrade
strategy.entry("Long", strategy.long)
if inTrade and exitCondition
strategy.close("Long")
inTrade := strategy.position_size > 0
//-----------------------------------------------------
// Stop-Loss & Take-Profit
//-----------------------------------------------------
if inTrade
stopPrice = strategy.position_avg_price * (1 - stopLossPerc / 100)
takeProfitPrice = strategy.position_avg_price * (1 + takeProfitPerc / 100)
strategy.exit("Exit", from_entry="Long", stop=stopPrice, limit=takeProfitPrice)
//-----------------------------------------------------
// Dynamic Drawdown Handling
//-----------------------------------------------------
var float peakEquity = strategy.equity
peakEquity := math.max(peakEquity, strategy.equity)
currentDrawdownPerc = (peakEquity - strategy.equity) / peakEquity * 100
if currentDrawdownPerc > ddLimit
strategy.close_all("Max Drawdown Exceeded")
//-----------------------------------------------------
// Plotting
//-----------------------------------------------------
plot(emaValue, title="EMA 200", color=color.yellow, linewidth=2)
plotchar(rsiValue, title="RSI", char='•', location=location.bottom, color=color.new(color.teal, 60))