
Chiến lược này là một hệ thống giao dịch phức tạp kết hợp chéo hai đường ngang, RSI mua quá bán và lọc tỷ lệ biến động ATR. Hệ thống sử dụng các trung bình di chuyển ngắn hạn và dài hạn để tạo ra tín hiệu giao dịch, lọc tình trạng thị trường thông qua chỉ số RSI, sử dụng chỉ số ATR để đánh giá tỷ lệ biến động và quản lý vị trí và kiểm soát rủi ro kết hợp tỷ lệ dừng lỗ và lợi nhuận rủi ro. Chiến lược này có khả năng thích ứng mạnh mẽ và có thể điều chỉnh các tham số một cách linh hoạt theo môi trường thị trường.
Logic cốt lõi của chiến lược này dựa trên các khía cạnh sau:
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 bằng cách kết hợp nhiều chỉ số kỹ thuật. Chiến lược có khả năng kiểm soát rủi ro tốt và hoạt động tốt trong thị trường xu hướng. Chiến lược có thể thích ứng với các môi trường thị trường khác nhau bằng cách đặt các tham số hợp lý và thêm các điều kiện lọc cần thiết.
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-20 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("Simplified MA Crossover Strategy with Disable Options", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Inputs
shortLength = input.int(9, title="Short MA Length", minval=1)
longLength = input.int(21, title="Long MA Length", minval=1)
// RSI Filter
enableRSI = input.bool(true, title="Enable RSI Filter")
rsiLength = input.int(14, title="RSI Length", minval=1)
rsiOverbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=100)
rsiOversold = input.int(30, title="RSI Oversold Level", minval=0, maxval=50)
// ATR Filter
enableATR = input.bool(true, title="Enable ATR Filter")
atrLength = input.int(14, title="ATR Length", minval=1)
minATR = input.float(0.005, title="Minimum ATR Threshold", minval=0)
// Risk Management
stopLossPerc = input.float(0.5, title="Stop Loss (%)", minval=0.1) / 100
riskRewardRatio = input.float(2, title="Risk-Reward Ratio", minval=1)
riskPercentage = input.float(2, title="Risk Percentage", minval=0.1) / 100
// Indicators
shortMA = ta.sma(close, shortLength)
longMA = ta.sma(close, longLength)
rsi = ta.rsi(close, rsiLength)
atr = ta.atr(atrLength)
// Conditions
longCondition = ta.crossover(shortMA, longMA)
shortCondition = ta.crossunder(shortMA, longMA)
// Apply RSI Filter (if enabled)
if (enableRSI)
longCondition := longCondition and rsi < rsiOverbought
shortCondition := shortCondition and rsi > rsiOversold
// Apply ATR Filter (if enabled)
if (enableATR)
longCondition := longCondition and atr > minATR
shortCondition := shortCondition and atr > minATR
// Risk Management
positionSize = strategy.equity * riskPercentage / (stopLossPerc * close)
takeProfitLevel = strategy.position_avg_price * (1 + stopLossPerc * riskRewardRatio)
stopLossLevel = strategy.position_avg_price * (1 - stopLossPerc)
// Execute Trades
if (longCondition)
strategy.entry("Long", strategy.long, qty=positionSize)
strategy.exit("Take Profit/Stop Loss", "Long", limit=takeProfitLevel, stop=stopLossLevel)
if (shortCondition)
strategy.entry("Short", strategy.short, qty=positionSize)
strategy.exit("Take Profit/Stop Loss", "Short", limit=strategy.position_avg_price * (1 - stopLossPerc * riskRewardRatio), stop=strategy.position_avg_price * (1 + stopLossPerc))
// Plotting
plot(shortMA, color=color.blue, title="Short MA")
plot(longMA, color=color.red, title="Long MA")
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
plot(atr, color=color.orange, title="ATR")
plotshape(series=longCondition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")