
Strategi ini adalah berdasarkan pada indeks yang agak kuat (RSI) yang direka untuk menggunakan prinsip RSI untuk melakukan operasi terobosan dua arah. Apabila RSI melewati garis terobosan yang ditetapkan di atas RSI, ia adalah strategi perdagangan berbalik yang biasa.
Parameter RSI dikira berdasarkan tetapan input pengguna, termasuk panjang kitaran RSI, had overbought dan had oversold.
Berdasarkan hubungan kedudukan garis RSI terhadap garis overbuy dan garis oversold, untuk menentukan apakah anda berada di kawasan overbuy atau kawasan oversold.
Apabila penunjuk RSI menembusi garisan penurunan nilai yang sesuai dari kawasan oversold, lakukan operasi pembukaan posisi ke arah yang berlawanan. Sebagai contoh, apabila penembusan garisan beli-belah dari kawasan oversold dianggap sebagai pembalikan, dan kedudukan dibuka lebih banyak; apabila penembusan garisan beli-belah dari kawasan oversold dianggap sebagai pembalikan, dan kedudukan dibuka kosong.
Selepas membuka kedudukan, tetapkan garis hentian hentian. Lacak keadaan hentian hentian dan tutup kedudukan apabila syarat dipenuhi.
Strategi ini juga menawarkan pilihan untuk menggunakan EMA sebagai penapis. Hanya apabila RSI melakukan lebih banyak isyarat penyingkiran, harga perlu menembusi EMA untuk membuka kedudukan.
Strategi ini juga menyediakan fungsi untuk berdagang hanya pada masa perdagangan tertentu. Pengguna boleh menetapkan perdagangan hanya pada masa tertentu, dan keluar dari kedudukan selepas masa.
Penyelesaian risiko:
Strategi ini boleh dioptimumkan dalam beberapa aspek:
Mengoptimumkan parameter RSI, mencari kombinasi parameter terbaik untuk pelbagai jenis. Anda boleh mencari paras paras teratas untuk membeli dan menjual yang terbaik dengan menjelajah.
Cuba gantikan atau menggabungkan RSI dengan indikator yang berbeza untuk menghasilkan isyarat penghakiman yang lebih kuat. Contohnya MACD, KD, Bollinger Bands, dan sebagainya.
Mengoptimumkan strategi hentian kerugian, meningkatkan kestabilan strategi. Anda boleh menetapkan hentian bebas berdasarkan turun naik pasaran, atau dengan fungsi hentian kerugian yang dapat dikesan.
Optimumkan parameter penapis EMA atau uji penapis penunjuk lain untuk mengelakkan lebih banyak.
Tambah modul penghakiman trend, dan elakkan aksi berbalik-balik, atau aksi berbalik-balik.
Uji parameter masa dagangan yang berbeza untuk menentukan mana yang sesuai untuk strategi dan mana yang harus dielakkan.
Strategi RSI dua arah untuk memecahkan strategi keseluruhan jelas, menggunakan prinsip RSI overbought dan oversold klasik untuk berdagang. Anda boleh mengambil peluang berbalik di kawasan overbought dan oversold, dan anda boleh mengawal risiko dengan penapisan EMA dan stop loss. Dengan pengoptimuman parameter dan pengoptimuman modul, ruang yang lebih besar dapat menjadikannya strategi berbalik yang lebih stabil dan boleh dipercayai.
/*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)