RSIインジケーターのロングとショート戦略


作成日: 2023-09-19 19:43:19 最終変更日: 2023-09-19 19:43:19
コピー: 0 クリック数: 746
1
フォロー
1617
フォロワー

概要

この戦略は,相対的な強弱指数 (RSI) の指標に基づいて判断され,RSIが上限を設定するときに空白し,RSIが下限を設定するときに多做し,典型的なRSI反転取引戦略の1つである. この戦略は,パラメータ最適化,ストップ損失戦略などの機能を持ち,パラメータを調整して異なる市場環境に適応することができます.

戦略原則

戦略の核心的な論理は以下の通りです.

  1. RSIを計算する
  2. RSI上限と下限を設定する
  3. RSIで上限を打つとき,空見入場
  4. RSIで下限を突破すると,
  5. ストップ・ダメージ・コンディションを設定する
  6. RSIが区画に再入ったときまたはストップ・ストップ条件を触発したときの平仓

RSI指標は,市場が超買または超売り状態にあるかを示すことができる. RSIが70を超えると超買とみなされ,RSIが30を下回ると超売りとみなされる. 取引戦略は,RSIの超買超売状態に基づいて空頭ポジションまたは多頭ポジションを確立することを判断することである.

この戦略は,RSI指標の古典的な論理を適用し,RSIの数値と設定された上下限との関係に基づいてポジションの方向を判断する.同時に,戦略は,RSIの上下限,ストップ・ストップ・損失幅などに最適化できる調整可能なパラメータを有し,市場の変化に適応する.

戦略的優位性

  • RSI指標は,市場が過買過売の状態を効果的に判断する.
  • RSI指標の理論は広く受け入れられています.
  • 戦略のパラメータは,種や市場環境に応じて調整できます.
  • リスク管理のための統合されたストップ・ストップ・メカニズム

戦略的リスクと対応

  • RSIが誤信号を発し,不必要な損失を招く可能性
  • RSIパラメータの範囲を継続的に最適化する必要があります.
  • 震災の停止はFrequentによって引き起こされる可能性がある.

対策:

  1. 他の指標と組み合わせた多因子確認により,偽信号を避ける
  2. RSIパラメータの範囲を,種別特性に合わせて最適化
  3. ストップポジションを調整して,被套リスクを低減する

戦略最適化の方向性

この戦略は,以下の側面から拡張され,最適化することができます.

  1. 機械学習によるRSIパラメータの範囲の自動最適化

  2. 偽の突破を避けるために取引の確認を増加させる

  3. 移動平均線などの指標と組み合わせた多要素検証

  4. 市場波動に応じてストップ幅を調整する自己適応ストップ戦略を設定する

  5. 取引量の変化を分析し,資金の流入と流出を判断します.

  6. 関連のない戦略を組み合わせて,全体的な撤退を減らす

要約する

この戦略は,RSI指標を用いて超買超売を判断し,シンプルで実用的な反転戦略である.戦略は,市場の変化に応じてパラメータを調整することができ,また,多次元拡張および最適化も可能です.パラメータ最適化,多要因検証,自律停止などの改善により,戦略をより安定して信頼性のあるものにすることができます.

ストラテジーソースコード
/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("4All V3", shorttitle="Strategy", overlay=true)

/////////////// Component Code Start ///////////////
testStartYear = input(2011, "Backtest Start Year") 
testStartMonth = input(8, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(9, "Backtest Stop Month")
testStopDay = input(29, "Backtest Stop Day")
// testStopDay = testStartDay + 1
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() => true
/////////////// Component Code Stop ///////////////

src = close
len = input(4, minval=1, title="Length")

up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

rsin = input(5)
sn = 100 - rsin
ln = 0 + rsin

/////////////// STRATEGY ///////////////
ts = input(99999, "Trailing Stop") / 10000
tp = input(15, "Take Profit") / 10000
sl = input(23, "Stop Loss") / 10000

pyr = input(1, "Pyramiding")

short = crossover(rsi, sn)
long = crossunder(rsi, ln)

totalLongs = 0
totalLongs := nz(totalLongs[1])
totalShorts = 0
totalShorts := nz(totalShorts[1])

totalLongsPrice = 0
totalLongsPrice := nz(totalLongsPrice[1])
totalShortsPrice = 0
totalShortsPrice := nz(totalShortsPrice[1])

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if long
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if short
    sectionLongs := 0
    sectionShorts := sectionShorts + 1

longCondition = long and sectionLongs >= pyr
shortCondition = short and sectionShorts >= pyr

last_long = na
last_short = na
last_long := longCondition ? time : nz(last_long[1])
last_short := shortCondition ? time : nz(last_short[1])

long_signal = crossover(last_long, last_short)
short_signal = crossover(last_short, last_long)

last_open_long_signal = na
last_open_short_signal = na
last_open_long_signal := long_signal ? open : nz(last_open_long_signal[1])
last_open_short_signal := short_signal ? open : nz(last_open_short_signal[1])

last_long_signal = na
last_short_signal = na
last_long_signal := long_signal ? time : nz(last_long_signal[1])
last_short_signal := short_signal ? time : nz(last_short_signal[1])

in_long_signal = last_long_signal > last_short_signal
in_short_signal = last_short_signal > last_long_signal

last_high = na
last_low = na
last_high := not in_long_signal ? na : in_long_signal and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_low := not in_short_signal ? na : in_short_signal and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])

long_ts = not na(last_high) and high <= (last_high - ts) //and high >= last_open_long_signal
short_ts = not na(last_low) and low >= (last_low + ts) //and low <= last_open_short_signal

long_tp = high >= (last_open_long_signal + tp)
short_tp = low <= (last_open_short_signal - tp)

long_sl = low <= (last_open_long_signal - sl)
short_sl = high >= (last_open_short_signal + sl)

leverage = input(1, "Leverage")
long_call = last_open_long_signal - (0.8 + 0.2 * (1/leverage)) / leverage * last_open_long_signal
short_call = last_open_short_signal + (0.78 + 0.2 * (1/leverage)) / leverage * last_open_short_signal
long_call_signal = low <= long_call
short_call_signal = high >= short_call

if testPeriod()
    strategy.entry("Long", strategy.long, when=longCondition)
    strategy.entry("Short", strategy.short, when=shortCondition)
    
    strategy.close("Long", when=long_call_signal)
    strategy.close("Short", when=short_call_signal)
    strategy.close("Long", when=long_tp)
    strategy.close("Short", when=short_tp)
    strategy.close("Long", when=long_sl)
    strategy.close("Short", when=short_sl)
    strategy.close("Long", when=long_ts)
    strategy.close("Short", when=short_ts)