
Chiến lược này được thiết kế dựa trên chỉ số RSI tương đối mạnh, sử dụng nguyên tắc mua và bán quá mức của chỉ số RSI để thực hiện các hoạt động phá vỡ hai chiều. Làm nhiều khi vượt qua đường mua quá mức được thiết lập trên chỉ số RSI và bỏ đi khi vượt qua đường bán quá mức được thiết lập dưới chỉ số RSI, là chiến lược giao dịch đảo ngược điển hình.
Các tham số của chỉ số RSI được tính dựa trên các thiết lập đầu vào của người dùng, bao gồm độ dài chu kỳ RSI, ngưỡng vượt mức mua và ngưỡng vượt mức bán.
Theo đường cong RSI, mối quan hệ giữa vị trí của đường mua và đường bán cao hơn để xác định khu vực mua hoặc bán cao hơn.
Khi chỉ số RSI phá vỡ đường giảm giá tương ứng từ khu vực bán tháo, thực hiện các hoạt động mở vị trí theo hướng ngược lại. Ví dụ: khi phá vỡ đường mua tháo từ khu vực mua tháo, cho rằng thị trường đã đảo ngược, lúc này mở nhiều vị trí; khi phá vỡ đường bán tháo từ khu vực bán tháo, cho rằng thị trường đã đảo ngược, lúc này mở vị trí trống.
Sau khi mở vị trí, thiết lập đường dừng lỗ. Theo dõi tình trạng dừng lỗ và thanh toán khi đáp ứng các điều kiện.
Chiến lược này cũng cung cấp các tính năng tùy chọn sử dụng EMA như là bộ lọc. Chỉ khi chỉ số RSI làm nhiều tín hiệu giảm giá, giá phải phá vỡ EMA để mở vị trí.
Chiến lược cũng cung cấp các chức năng chỉ giao dịch trong một khoảng thời gian giao dịch nhất định. Người dùng có thể thiết lập giao dịch chỉ trong một khoảng thời gian nhất định, sau khi vượt quá thời gian, họ sẽ thoát khỏi vị trí.
Giải quyết rủi ro:
Chiến lược này có thể được tối ưu hóa theo các khía cạnh sau:
Tối ưu hóa các tham số RSI, tìm kiếm sự kết hợp tốt nhất của các tham số khác nhau. Bạn có thể tìm thấy ngưỡng thềm bán tháo tốt nhất bằng cách đi qua.
Thử các chỉ số khác nhau thay thế hoặc kết hợp RSI để tạo ra tín hiệu phán đoán mạnh hơn. Ví dụ: MACD, KD, Bollinger Bands, v.v.
Tối ưu hóa chiến lược dừng lỗ và tăng sự ổn định của chiến lược. Các chiến lược có thể được thiết lập để dừng lỗ theo biến động của thị trường hoặc có chức năng theo dõi dừng lỗ.
Tối ưu hóa các tham số bộ lọc EMA hoặc thử nghiệm các bộ lọc chỉ số khác để tránh bị mắc kẹt hơn nữa.
Thêm mô-đun đánh giá xu hướng, tránh làm ngược các hành động đa đầu, hoặc làm ngược các hành động đa đầu.
Kiểm tra các tham số thời gian giao dịch khác nhau để xác định thời gian nào phù hợp với chiến lược và thời gian nào nên tránh.
Chiến lược phá vỡ hai chiều của RSI có ý tưởng tổng thể rõ ràng, sử dụng nguyên tắc mua bán vượt quá RSI cổ điển để giao dịch đảo ngược. Bạn có thể nắm bắt cơ hội đảo ngược trong khu vực mua bán vượt quá và có thể kiểm soát rủi ro thông qua lọc EMA và dừng lỗ.
/*backtest
start: 2023-10-08 00:00:00
end: 2023-11-07 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © REV0LUTI0N
//@version=4
strategy("RSI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)
// Strategy Backtesting
startDate = input(timestamp("2021-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')
time_cond = true
// Strategy
Length = input(12, minval=1)
src = input(close, title="Source")
overbought = input(70, minval=1)
oversold = input(30, minval=1)
xRSI = rsi(src, Length)
rsinormal = input(true, title="Overbought Go Long & Oversold Go Short")
rsiflipped = input(false, title="Overbought Go Short & Oversold Go Long")
// EMA Filter
noemafilter = input(true, title="No EMA Filter")
useemafilter = input(false, title="Use EMA Filter")
ema_length = input(defval=15, minval=1, title="EMA Length")
emasrc = input(close, title="Source")
ema = ema(emasrc, ema_length)
plot(ema, "EMA", style=plot.style_linebr, color=#cad850, linewidth=2)
//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = (time(timeframe.period, startendtime))
timetoclose = na(time(timeframe.period, startendtime))
// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100
longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)
plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")
// Alert messages
message_enterlong = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
// Strategy Execution
if (xRSI > overbought and close > ema and time_cond and timetobuy and rsinormal and useemafilter)
strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (xRSI < oversold and close < ema and time_cond and timetobuy and rsinormal and useemafilter)
strategy.entry("Short", strategy.short, alert_message = message_entershort)
if (xRSI < oversold and close > ema and time_cond and timetobuy and rsiflipped and useemafilter)
strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (xRSI > overbought and close < ema and time_cond and timetobuy and rsiflipped and useemafilter)
strategy.entry("Short", strategy.short, alert_message = message_entershort)
if (xRSI > overbought and time_cond and timetobuy and rsinormal and noemafilter)
strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (xRSI < oversold and time_cond and timetobuy and rsinormal and noemafilter)
strategy.entry("Short", strategy.short, alert_message = message_entershort)
if (xRSI < oversold and time_cond and timetobuy and rsiflipped and noemafilter)
strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (xRSI > overbought and time_cond and timetobuy and rsiflipped and noemafilter)
strategy.entry("Short", strategy.short, alert_message = message_entershort)
if strategy.position_size > 0 and timetoclose and enableclose
strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose
strategy.close_all(alert_message = message_closeshort)
if strategy.position_size > 0 and enablesl and time_cond
strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
if strategy.position_size > 0 and enabletp and time_cond
strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)