Strategi RSI Reversal Breakout

Penulis:ChaoZhang, Tanggal: 2023-11-08 12:11:03
Tag:

img

Gambaran umum

Strategi ini didasarkan pada indikator Relative Strength Index (RSI) dan memanfaatkan prinsip overbought/oversold dari RSI untuk melakukan perdagangan breakout.

Logika Strategi

  1. Tentukan parameter indikator RSI berdasarkan input pengguna, termasuk periode RSI, ambang overbought dan ambang oversold.

  2. Tentukan apakah RSI berada di zona overbought atau oversold berdasarkan posisinya relatif terhadap ambang batas.

  3. Ketika RSI keluar dari zona overbought/oversold dan melintasi garis ambang yang sesuai, buat perdagangan ke arah yang berlawanan. Misalnya, ketika RSI keluar dari zona overbought, pasar dianggap terbalik, pergi panjang pada titik ini. Ketika RSI keluar dari zona overbought, pasar dianggap terbalik, pergi pendek di sini.

  4. Setelah masuk, atur stop loss dan ambil garis keuntungan.

  5. Strategi ini juga menyediakan opsi untuk menggunakan EMA sebagai filter. Hanya mengambil sinyal perdagangan ketika baik sinyal RSI dan harga pecah terhadap arah EMA terpenuhi.

  6. Hal ini juga memungkinkan perdagangan hanya dalam kerangka waktu tertentu Posisi akan ditutup pada akhir kerangka waktu.

Analisis Keuntungan

  • Menggunakan prinsip RSI klasik dengan hasil backtest yang baik.

  • Pengaturan ambang overbought/oversold yang fleksibel yang cocok untuk produk yang berbeda.

  • Filter EMA opsional menghindari perdagangan yang berlebihan.

  • Mendukung SL/TP untuk meningkatkan stabilitas.

  • Mendukung filter kerangka waktu untuk menghindari periode yang tidak cocok.

  • Mendukung baik panjang dan pendek untuk memanfaatkan sepenuhnya perubahan harga dua arah.

Analisis Risiko

  • Perbedaan RSI sering terjadi, hanya mengandalkan RSI dapat menghasilkan sinyal yang tidak akurat.

  • Pengaturan ambang batas yang tidak benar menyebabkan perdagangan terlalu sering atau tidak terjadi.

  • Pengaturan SL / TP yang buruk menyebabkan terlalu agresif atau terlalu konservatif.

  • Pengaturan filter EMA yang tidak benar dapat melewatkan perdagangan yang valid atau menyaring sinyal yang baik.

Solusi Risiko:

  • Mengoptimalkan parameter RSI untuk produk yang berbeda.

  • Gabungkan dengan indikator tren untuk mengidentifikasi perbedaan.

  • Uji dan optimalkan parameter SL/TP.

  • Uji dan optimalkan parameter EMA.

Arahan Optimasi

Strategi ini dapat ditingkatkan dalam hal berikut:

  1. Mengoptimalkan parameter RSI untuk menemukan pengaturan terbaik untuk produk yang berbeda melalui backtest yang komprehensif.

  2. Cobalah indikator yang berbeda yang dikombinasikan dengan atau menggantikan RSI untuk menghasilkan sinyal yang lebih kuat, misalnya MACD, KD, Bollinger Bands dll.

  3. Mengoptimalkan stop loss dan mengambil strategi keuntungan untuk meningkatkan stabilitas.

  4. Optimalkan parameter filter EMA atau percobaan dengan filter lain untuk lebih menghindari whipsaws.

  5. Tambahkan modul filter tren untuk menghindari perdagangan terhadap tren utama.

  6. Uji kerangka waktu yang berbeda untuk menemukan sesi perdagangan terbaik untuk strategi ini.

Ringkasan

Strategi RSI reversal breakout memiliki logika yang jelas berdasarkan prinsip overbought / oversold klasik. Ini bertujuan untuk menangkap reversi rata-rata pada ekstrem dengan filter kontrol risiko yang tepat. Ada potensi yang baik untuk mengubahnya menjadi strategi yang stabil melalui penyesuaian parameter dan peningkatan modular.


/*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)
    



Lebih banyak