
この戦略は,相対的に強い指数 ((RSI)) の指標設計に基づいて,RSIの超買超売原理を利用して,双方向の突破操作を行う. RSIの指標上での設定された超買線を突破する際に多做し,RSIの指標下での設定された超売線を突破する際に空きを取ることは,典型的な反転取引戦略である.
RSI指標のパラメータは,RSI周期長さ,超買線値,超売り線値を含む,ユーザの入力設定に基づいて計算されます.
RSI曲線に対する超買線と超売線の位置関係によって,超買線か超売線か判断する.
RSI指標が超売区から対価値下げ線を突破したとき,逆方向の開場操作を行う.例えば,超買区から超買線を突破したとき,市場が逆転すると考え,その時に多額のポジションを開く.超売区から超売線を突破したとき,市場が逆転すると考え,その時に空きポジションを開く.
ポジション開設後,ストップ・ストップ・ラインを設定する.ストップ・ストップの状況を追跡し,条件が満たされると平仓する.
この戦略は,EMAをフィルターとして使用するオプション機能も提供しています. RSIが空調信号を多めにすると,価格がEMAを破る必要があります.
戦略は,特定の取引時間でのみ取引する機能も提供している.ユーザーは,特定の時間帯でのみ取引を設定し,時間を超えると平仓を退場することができる.
リスクの解決:
この戦略は以下の点で最適化できます.
RSIのパラメータを最適化して,異なる品種の最適なパラメータの組み合わせを探します.
異なる指標をRSIと組み合わせて,より強力な判断信号を形成しようとします. 例えば,MACD,KD,ブリン帯など.
ストップ・ストップ戦略を最適化し,戦略の安定性を向上させる.市場変動率に応じて移動ストップを設定するか,トラッキング・ストップ機能を持つ戦略である.
EMAフィルターパラメータを最適化するか,他の指標フィルターを試すことで,さらに入を避ける.
トレンド判断モジュールを追加し,反逆空頭多頭行動や反逆空頭多頭行動を避ける.
異なる取引時間パラメータをテストし,どのタイミングが戦略に適しているか,どのタイミングを避けるべきかを判断します.
このRSI双方向突破策の全体的な考え方は明確で,クラシックRSI超買超売原理を利用して反転取引を行う. 超買超売区の反転機会を掴むだけでなく,EMAフィルタリングと止損ストップを使用してリスクを制御することができる. パラメータ最適化とモジュール最適化により大きなスペースがあり,より安定した信頼性の高い反転策にすることができます.
/*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)