RSIインジケーターとボリンジャーバンド取引戦略の組み合わせ


作成日: 2023-12-21 11:17:19 最終変更日: 2023-12-21 11:17:19
コピー: 0 クリック数: 809
1
フォロー
1623
フォロワー

RSIインジケーターとボリンジャーバンド取引戦略の組み合わせ

戦略概要

この戦略は,RSIブリンバンドのストップ・ストラップ戦略 (RSI Bollinger Bands TP/SL Strategy) と呼ばれています.この戦略は,RSI指標とブリンバンドの指標を融合し,トレンドの位置付けと突破取引を実現します.RSI指標がオーバーバイのオーバーセール信号を発生させ,価格がブリンバンドを上線または下線に触れたり突破したりすると,多額の操作または空白操作を行います.同時に,戦略は,ストップ・ストラップ・ストラップを設定し,安定性を向上させます.

2. 戦略の原則

1. RSIが逆転する

RSI指標は,株式が超買超売区間にあるかどうかを判断する. RSIが設定された超買ラインより大きいときは超買,設定された超売区間より小さいときは超売である. この戦略では,超買ラインは50で,超売ラインは50である.

2. ブリンが判断する傾向

ブリン帯は,株価の標準差を計算することによって,株価の上下線を得る.上線は抵抗線であり,下線は支柱線である.株価が上線から下線に突入するときは買点であり,下線から上線に突入する時は売り点である.

3. RSIとブリン帯の組み合わせ

RSI指数が底の反転信号を発し,株価がブルリン帯を下回る時,下から上への反転が考えられ,多額の取引を行う.RSI指数が上からの反転信号を発し,株価がブルリン帯の上回る時,上から下への反転が考えられ,空白を行う.

3 戦略的優位性

1. 双指数フィルターにより信号の正確性が向上

RSI指標とブリン帯指標は,トレンドと逆転点を判断するために使用されます. 両方とも組み合わせて使用すると,本当の買い物シグナルの識別精度が向上し,偽の突破を防ぐことができます.

2. ストップ・ストップ・メカニズム リスク制御

ストップ・ストップ・ロスを設定し,入場価格にストップ・ストップを追加します.(1 + ストップスレート) ストップポイントは入場価格(1-ストップ・損失比率);空白は,利益を固定し,損失を最大限に回避し,リスクを制御する.

3. カスタマイズ可能な買取方向

戦略は,多,空,双方向の取引を選択できます. ユーザーは,市場環境に応じて異なる方向を選択し,リスクを柔軟に制御することができます.

4 戦略的リスク

1. ブリン帯はパラメータに敏感

ブリン帯の標準差の大きさはブリン帯の幅に影響し,取引信号の発生に影響する.パラメータが正しく設定されていない場合,大量の誤信号が生じる可能性がある.

2. ストップダスのリスク

市場がV型逆転した場合,止損設定が過度に激化し,不必要な損失を招く可能性があります.

3. RSI パラメータ 敏感

RSIのパラメータは,RSI曲線の形にも影響する.RSIのパラメータが誤って設定された場合,RSI反転信号の正確性が低下する.

5 戦略の最適化方向

1. RSIパラメータを最適化する

RSIの長さのパラメータをテストし,最適なパラメータの組み合わせを見つけることができます.

2. ブリン帯のパラメータを最適化

より多くのブリン帯長と標準差のパラメータをテストして,最適なパラメータの組み合わせを見つけることができます.

3. 異なるストップ・ストラストレートテスト

最適なストップ・ストップ・損失比率のパラメータは,反測によって見つけることができる.

VI. 結論

この戦略は,RSI指標とブリン帯の指標を総合的に使用して,トレンドと逆転を判断し,止まり止まりの仕組みのリスク制御を追加し,自動で買い売り点を認識し,タイミングで止まり止まりを停止することができます.この戦略には,一定のリスクがあります.この戦略は,主にパラメータ最適化などの方法によって改善することができます.全体的に,この戦略は,強力な実用性を持っています.

ストラテジーソースコード
/*backtest
start: 2023-11-20 00:00:00
end: 2023-12-20 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/
// © BigCoinHunter

//@version=5
strategy(title="RSI_Boll-TP/SL", overlay=true, 
     pyramiding=0, default_qty_type=strategy.percent_of_equity, 
     default_qty_value=100, initial_capital=1000, 
     currency=currency.USD, commission_value=0.05, 
     commission_type=strategy.commission.percent, 
     process_orders_on_close=true)

//----------- get the user inputs --------------

//---------- RSI -------------
price = input(close, title="Source")

RSIlength = input.int(defval=6,title="RSI Length") 
RSIoverSold = input.int(defval=50, title="RSI OverSold", minval=1)
RSIoverBought = input.int(defval=50, title="RSI OverBought", minval=1)

//------- Bollinger Bands -----------
BBlength = input.int(defval=200, title="Bollinger Period Length", minval=1)
BBmult = input.float(defval=2.0, minval=0.001, maxval=50, step=0.1, title="Bollinger Bands Standard Deviation")
BBbasis = ta.sma(price, BBlength)
BBdev = BBmult * ta.stdev(price, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
source = close
buyEntry = ta.crossover(source, BBlower)
sellEntry = ta.crossunder(source, BBupper)
plot(BBbasis, color=color.aqua, title="Bollinger Bands SMA Basis Line")
p1 = plot(BBupper, color=color.silver, title="Bollinger Bands Upper Line")
p2 = plot(BBlower, color=color.silver, title="Bollinger Bands Lower Line")
fill(plot1=p1, plot2=p2, title="Bollinger BackGround", color=color.new(color.aqua,90), fillgaps=false, editable=true)

//---------- input TP/SL ---------------
tp = input.float(title="Take Profit:", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01
sl = input.float(title="Stop Loss:  ", defval=0.0, minval=0.0, maxval=100.0, step=0.1) * 0.01

longEntry = input.bool(defval=true, title= 'Long Entry', inline="11")
shortEntry = input.bool(defval=true, title='Short Entry', inline="11")

//---------- backtest range setup ------------
fromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear  = input.int(defval = 2021, title = "From Year", minval = 2010)
toDay     = input.int(defval = 30, title = "To Day", minval = 1, maxval = 31)
toMonth   = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear    = input.int(defval = 2042, title = "To Year", minval = 2010)

//------------ time interval setup -----------
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)  // backtest start window
finish    = timestamp(toYear, toMonth, toDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false // create function "within window of time"

//------- define the global variables ------
var bool long = true
var bool stoppedOutLong = false
var bool stoppedOutShort = false
//--------- Colors ---------------

TrendColor = RSIoverBought and (price[1] > BBupper and price < BBupper) and BBbasis < BBbasis[1] ? color.red : RSIoverSold and (price[1] < BBlower and price > BBlower) and BBbasis > BBbasis[1] ? color.green : na
//bgcolor(switch2?(color.new(TrendColor,50)):na)


//--------- calculate the input/output points -----------
longProfitPrice  = strategy.position_avg_price * (1 + tp)     // tp -> take profit percentage
longStopPrice = strategy.position_avg_price * (1 - sl)        // sl -> stop loss percentage

shortProfitPrice  = strategy.position_avg_price * (1 - tp)
shortStopPrice = strategy.position_avg_price * (1 + sl)


//---------- RSI + Bollinger Bands Strategy -------------
vrsi = ta.rsi(price, RSIlength)

rsiCrossOver = ta.crossover(vrsi, RSIoverSold)
rsiCrossUnder = ta.crossunder(vrsi, RSIoverBought)

BBCrossOver = ta.crossover(source, BBlower)
BBCrossUnder = ta.crossunder(source, BBupper)

if (not na(vrsi))

    if rsiCrossOver and BBCrossOver
        long := true
        
    if rsiCrossUnder and BBCrossUnder
        long := false

//------------------- determine buy and sell points ---------------------
buySignall = window() and long  and (not stoppedOutLong)
sellSignall = window() and (not long)  and (not stoppedOutShort)

//---------- execute the strategy -----------------
if(longEntry and shortEntry)
    if long 
        strategy.entry("LONG", strategy.long, when = buySignall, comment = "ENTER LONG")
        stoppedOutLong := true
        stoppedOutShort := false
    else 
        strategy.entry("SHORT", strategy.short, when = sellSignall, comment = "ENTER SHORT")
        stoppedOutLong  := false
        stoppedOutShort := true

else if(longEntry)
    strategy.entry("LONG", strategy.long,  when = buySignall)
    strategy.close("LONG", when = sellSignall)
    if long 
        stoppedOutLong := true
    else
        stoppedOutLong  := false

else if(shortEntry)
    strategy.entry("SHORT", strategy.short, when = sellSignall)
    strategy.close("SHORT", when = buySignall)
    if not long
        stoppedOutShort := true
    else
        stoppedOutShort := false
    

//----------------- take profit and stop loss -----------------
if(tp>0.0 and sl>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG", limit=longProfitPrice, stop=longStopPrice, comment="Long TP/SL Trigger")

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT", limit=shortProfitPrice, stop=shortStopPrice, comment="Short TP/SL Trigger")

else if(tp>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG", limit=longProfitPrice, comment="Long TP Trigger")

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT", limit=shortProfitPrice, comment="Short TP Trigger")
        
else if(sl>0.0)
    if ( strategy.position_size > 0 )
        strategy.exit(id="LONG",  stop=longStopPrice, comment="Long SL Trigger")

    else if ( strategy.position_size < 0 )
        strategy.exit(id="SHORT",  stop=shortStopPrice, comment="Short SL Trigger")