RSIとストキャスティクスRSIに基づく取引戦略


作成日: 2024-02-18 16:13:50 最終変更日: 2024-02-18 16:13:50
コピー: 1 クリック数: 711
1
フォロー
1617
フォロワー

RSIとストキャスティクスRSIに基づく取引戦略

概要

この取引戦略は,相対的に弱い指標 ((RSI) とランダムに相対的に強い指標 ((Stochastic RSI) の2つの技術指標を組み合わせて取引信号を生成する.この戦略は,さらに高い時間枠の暗号通貨価格の動きを利用してトレンドを確認し,信号の信頼性を高める.

戦略名

マルチタイムフレーム RSI-SRSI取引戦略

戦略原則

この戦略は,RSI指標の値の高低に基づいて超買い超売り現象を判断する. RSIが30を下回ると超売り信号で,70を下回ると超買い信号である. ストキャスティックRSI指標は,RSI指標自体の変動状況を観察する.

策略は同時に,より高い時間枠 (例えば周回線) の暗号通貨価格の動きと結合する. 買い取引シグナルは,より高い時間枠のRSIが減值より高い場合 (例えば45),のみ生成されます. この設定は,全体的に下落傾向にあるときに発生する非持続的な超売りシグナルをフィルターします.

買出信号は,誘発後,一定の周期 (例えば8根のK線) を経て確認する必要があるので,誤導的な信号を発生させないようにする.

戦略的優位性

  • RSI指標を用いた超買超売の判断のクラシックなテクニカル分析方法
  • ストキャスティックRSI指標と組み合わせたRSI自体の反転信号
  • 多時間枠技術のフィルタリングにより,誤導信号の質が向上する.

戦略的リスクと解決策

  • RSIは誤った信号を発信しやすい
    • 他の指標と組み合わせたフィルタリング
    • トレンド確認技術
  • 値パラメータの設定が不適切で,取引信号が過剰に発生する
    • 最適化パラメータの組み合わせを最適化します.
  • 買い/売却のシグナルには確認の時間が必要です.
    • バランスのとれた確認サイクルを見つけ,誤った信号をフィルターし,チャンスを逃さない

戦略最適化の方向性

  • 複数の指標の組み合わせをテストし,より強力な信号を探します.
    • MACD指標を策略に追加するなど
  • 機械学習で最適なパラメータを試す
    • 遺伝的/進化的アルゴリズムによる自動最適化
  • 単一取引のリスクを制御するストップ・ロスの策略を増加させる
    • 価格がサポート値を下回ったときのストップ

要約する

この戦略は,主にRSIとStochastic RSIの2つのクラシック取引指標に依存して取引信号を生成する.同時に,より高い時間枠を導入してトレンド確認を行うことで,誤導信号を効果的にフィルターし,信号の質を向上させることができる.パラメータ最適化,止損戦略などの手段によって戦略のパフォーマンスをさらに強化することができる.この戦略の構想は,シンプルで直接で,容易に理解できる実装であり,取引を量化するための良い出発点である.

ストラテジーソースコード
/*backtest
start: 2023-02-11 00:00:00
end: 2024-02-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("RSI and Stochatic Strategy", overlay=true, use_bar_magnifier = false)


/////// Inputs ///////////////

// RSI and SRSI
rsiLength = input(14, title="RSI Length") 
stochLength = input(14, title="Stochastic Length")
kSmooth = input(3, title="K Smooth")
dSmooth = input(3, title="D Smooth")


//////// thresholds ///////////////
st_low = input(5, title="Low SRSI") // stochastic RSI low -- prepare to sell
st_hi = input(50, title="High SRSI") // stochastic RSI high -- prepare to buy
diff = input(5, title="difference") // minimum change in RSI
// inval_diff = input(12, title="difference") // invalidation difference: change in the oposite direction that invalidates rsi falling/rising
rsi_low = input(30, title="Low RSI") // RSI considered low
rsi_hi = input(60, title="High RSI") // RSI considered high
rsi_ht_hi = input(45, title="High higher time frame RSI") // RSI in higher time frame considered high


/// buy trigger duration 
tr_dur = input(8, title="Trigger duration")
low_dur = input(20, title="Monitoring last low")


///////////////// Higher time frame trend ///////////////////
// higher time frame resolution
res2 = input.timeframe("W", title="Higher time-frame")
// Input for the ticker symbol, default is an empty string
// For instance we could monitor BTC higher time frame trend
symbol = input("BTC_USDT:swap", "Input Ticker (leave empty for current)")

// Determine the symbol to use
inputSymbol = symbol == "" ? syminfo.tickerid : symbol
//////////////////////////////////////////////////////////

// Calculate RSI //
rsi = ta.rsi(close, rsiLength)

// Calculate Stochastic RSI //
rsiLowest = ta.lowest(rsi, stochLength)
rsiHighest = ta.highest(rsi, stochLength)
stochRsi = 100 * (rsi - rsiLowest) / (rsiHighest - rsiLowest)

// Apply smoothing
K = ta.sma(stochRsi, kSmooth)
D = ta.sma(K, dSmooth)

// Higher time Frame RSI
cl2 = request.security(inputSymbol, res2, close)
rsi2 = ta.rsi(cl2, 14)

// SRSI BUY/SELL signals 
sell_stoch = (ta.lowest(K, tr_dur) < st_low) or (ta.highest(rsi, tr_dur) < rsi_low)
buy_stoch = ((ta.lowest(K, tr_dur) > st_hi) or (ta.lowest(rsi, tr_dur) > rsi_hi)) and (rsi2 > rsi_ht_hi)

 // valitation / invalidation sell signal
ll = ta.barssince(not sell_stoch)+1
sell_validation = (ta.highest(rsi, ll)>rsi[ll]+diff and rsi < rsi[ll]) or (rsi < rsi[ll]-diff)

// valitation / invalidation buy signal
llb = ta.barssince(not buy_stoch)+1
buy_validation = (ta.lowest(rsi, llb)<rsi[llb]-diff and rsi > rsi[llb]) or (rsi > rsi_hi and rsi - rsi[tr_dur] > 0)

sell_signal = sell_stoch and sell_validation
buy_signal = buy_stoch and buy_validation 

// Define the start date for the strategy
startYear = input(2019, "Start Year")
startMonth = input(1, "Start Month")
startDay = input(1, "Start Day")

// Convert the start date to Unix time
startTime = timestamp(startYear, startMonth, startDay, 00, 00)

// Define the end date for the strategy
endYear = input(2030, "End Year")
endMonth = input(1, "End Month")
endDay = input(1, "End Day")

// Convert the end date to Unix time
endTime = timestamp(endYear, endMonth, endDay, 00, 00)


if true
    if buy_signal
        strategy.entry("buy", strategy.long, comment = "Buy")
    if sell_signal
        strategy.close("buy", "Sell")