
Đây là một chiến lược giao dịch đảo ngược dựa trên chỉ số RSI và khối lượng giao dịch. Chiến lược này xác nhận khối lượng giao dịch bằng cách xác định trạng thái mua bán quá mức trong thị trường, kết hợp với xác nhận khối lượng giao dịch, và thực hiện giao dịch ngược khi giá xuất hiện ở trạng thái cực. Ý tưởng cốt lõi của chiến lược là giao dịch khi có tín hiệu mua hoặc bán quá mức trong chỉ số RSI và khối lượng giao dịch cao hơn mức trung bình, thông qua đường trung tâm RSI ((50) làm tín hiệu thoát.
Chiến lược này dựa trên các thành phần cốt lõi sau:
Chiến lược này được xây dựng bằng cách kết hợp các chỉ số RSI và phân tích khối lượng giao dịch để xây dựng một hệ thống giao dịch đảo ngược hoàn chỉnh. Chiến lược được thiết kế hợp lý, có khả năng hoạt động tốt và linh hoạt. Với hướng tối ưu hóa được đề xuất, chiến lược có thể được nâng cao hơn nữa.
/*backtest
start: 2025-01-01 00:00:00
end: 2025-02-19 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("RSI & Volume Contrarian Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0)
//---------------------------
// Inputs and Parameters
//---------------------------
rsiPeriod = input.int(14, title="RSI Period", minval=1)
oversold = input.int(30, title="RSI Oversold Level", minval=1, maxval=50)
overbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=100)
volMAPeriod = input.int(20, title="Volume MA Period", minval=1)
//---------------------------
// Indicator Calculations
//---------------------------
rsiValue = ta.rsi(close, rsiPeriod)
volMA = ta.sma(volume, volMAPeriod)
//---------------------------
// Trade Logic
//---------------------------
// Long Entry: Look for oversold conditions (RSI < oversold)
// accompanied by above-average volume (volume > volMA)
// In an uptrend, oversold conditions with high volume may signal a strong reversal opportunity.
longCondition = (rsiValue < oversold) and (volume > volMA)
// Short Entry: When RSI > overbought and volume is above its moving average,
// the temporary strength in a downtrend can be exploited contrarily.
shortCondition = (rsiValue > overbought) and (volume > volMA)
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
// Exit Logic:
// Use a simple RSI midline crossover as an exit trigger.
// For longs, if RSI crosses above 50 (indicating a recovery), exit the long.
// For shorts, if RSI crosses below 50, exit the short.
exitLong = ta.crossover(rsiValue, 50)
exitShort = ta.crossunder(rsiValue, 50)
if strategy.position_size > 0 and exitLong
strategy.close("Long", comment="RSI midline exit")
log.info("strategy.position_size > 0 and exitLong")
if strategy.position_size < 0 and exitShort
strategy.close("Short", comment="RSI midline exit")
log.info("strategy.position_size > 0 and exitLong")
//---------------------------
// Visualization
//---------------------------
// Plot the RSI on a separate pane for reference
plot(rsiValue, title="RSI", color=color.blue, linewidth=2)
hline(oversold, title="Oversold", color=color.green)
hline(overbought, title="Overbought", color=color.red)
hline(50, title="Midline", color=color.gray, linestyle=hline.style_dotted)
// Optionally, you may plot the volume moving average on a hidden pane
plot(volMA, title="Volume MA", color=color.purple, display=display.none)