長期間のRSI-SRSI取引戦略

作者: リン・ハーンチャオチャン,日付: 2024-02-18 16:13:50
タグ:

img

概要

この取引戦略は,トレードシグナルを生成するために,相対強度指数 (RSI) とストカスティック相対強度指数 (Stochastic RSI) の技術指標を組み合わせます.さらに,傾向を確認し,信号の信頼性を高めるために,より高いタイムフレームで暗号通貨の価格傾向を利用します.

戦略名

長期間のRSI-SRSI取引戦略

戦略の論理

この戦略は,RSI値に基づいて過剰購入および過剰販売状態を判断する.RSI値30未満は過剰販売信号であり,RSI値70を超える値は過剰購入信号とみなされる.ストカスティックRSI指標は,RSI値の変動を観察する.ストカスティックRSI値5以下は過剰販売であり,ストカスティックRSI値50を超える値は過剰購入である.

この戦略は,より高いタイムフレーム (例えば週) で暗号通貨の価格傾向も組み込む.より高いタイムフレームRSIが限界値 (例えば45) を上回ったときのみ,ロングシグナルが起動する.これは,全体的なトレンドが低下しているときに持続しない過剰販売信号をフィルタリングする.

偽の信号を避けるため,実際の取引信号が生成される前に,購入・売却信号は数時間 (例えば8バー) 確認する必要があります.

利点

  • RSI を用いた従来の技術分析方法により,過買い/過売りレベルを特定する
  • RSIの逆転を把握するためにストカスティックRSIを組み込む.
  • 偽信号をフィルタリングし,品質を改善するために多時間枠技術を適用します

リスク と 解決策

  • RSIは誤った信号を生成する傾向がある
    • 偽信号をフィルタリングするために他の指標を組み合わせる
    • トレンド 確認 技術 を 適用 する
  • 誤った限界設定では,信号が多すぎます.
    • 最適な組み合わせを見つけるためにパラメータを最適化
  • 信号は確認時間が必要です
    • バランス確認期間 - 誤った信号をフィルタリングし,機会を逃さない

強化 分野

  • より強い信号のためにより多くの指標組み合わせをテストする
    • 例えば MACD インジケーターを組み込む
  • 最適なパラメータを見つけるために機械学習方法を活用する
    • 例えば,自動最適化のための遺伝子アルゴリズム/進化アルゴリズム
  • 単一の取引リスクを制御するためにストップ損失戦略を追加
    • 価格がサポートレベルを突破するとストップロスを設定する

結論

この戦略は,主に2つのクラシックな技術指標であるRSIとストカスティックRSIに依存し,取引シグナルを生成する.さらに,より高いタイムフレームからトレンド確認の導入は,偽のシグナルを効果的にフィルタリングし,シグナル品質を改善するのに役立ちます.パラメータを最適化し,ストップロスを追加し,その他の手段でパフォーマンスをさらに改善することができます.論理はシンプルで理解が簡単です.これは量子取引の良い出発点です.


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

もっと