RSI ボリンガーバンド TP/SL戦略

作者: リン・ハーンチャオチャン, 日付: 2023-12-21 11:17:19
タグ:

img

I. 戦略の概要

この戦略は,RSIボリンジャーバンドTP/SL戦略と呼ばれています.RSIインジケーターとボリンジャーバンドを組み合わせて,トレンドと取引信号を特定します.RSIインジケーターがオーバーバイトまたはオーバーセールシグナルを示し,価格がボリンジャーバンドに触れたり,または突破した場合,ロングまたはショートポジションが開かれます.また,リスクを管理するために,利益とストップロスのポイントも設定されています.

戦略の論理

1. RSI インディケーター

RSIインジケーターは,株が過買いまたは過売れているかどうかを判断する.過買い線上のRSI表示は過買い条件を示し,過売線下の表示は過売条件を示します.この戦略では,過買い線は50で,過売線は50で設定されています.

2. トレンド用ボリンジャー帯

ボリンジャー帯は,単純な移動平均線の上下を標準偏差線で描画する.上部帯は抵抗として,下部帯はサポートとして機能する.下部帯の上横断は購入信号であり,上部帯の下横断は販売信号である.

3. RSI と ボリンジャー帯の組み合わせ

RSIインジケーターが底部逆転信号を示し,価格がボリンジャーバンドの下部帯を突破すると,それは上向き逆転とみなされ,したがってロングになります.RSIインジケーターが上向き逆転信号を示し,価格が上部帯を突破すると,それは下向き逆転とみなされ,したがってショートになります.

III. 利点

1. 二重 指示 器 で 精度 が 向上 し た

RSI と ボリンジャー帯は,トレンドと逆転を決定するために使用されます.この組み合わせは,信号認識の精度を向上させ,偽のブレイクを回避します.

2. TP/SL を使ったリスク管理

戦略セットは,利益を固定し,損失を最大限に軽減するために,利益 (TP) とストップ・ロスト (SL) ポイントを設定します.

3. 調整 できる 指示

利用者は市場状況に基づいて,ロングのみ,ショートのみ,または両方向に行うことができ,柔軟なリスク管理が可能になります.

IV リスク

1. 敏感ボリンガー帯のパラメータ

標準偏差の大きさは帯幅と取引信号に影響を与える.不適切な設定は過剰な誤った信号を生む可能性があります.

2. TP/SL のリスク

V型逆転は,TP/SL設定が攻撃的すぎるため,不必要な損失を引き起こす可能性があります.

3. 敏感な RSI パラメーター

RSIパラメータの設定が間違っている場合,逆転信号の精度が低下します.

V.最適化の方向性

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

最適なパラメータの組み合わせを見つけるために,より多くのRSI長値をテストすることができます.

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

最適なパラメータ組み合わせを見つけるために,より多くの長さと標準偏差を試験することができる.

3. 異なるTP/SL比を試験する

バックテストは,最適なTP/SL比を見つけるのに役立ちます.

結論

この戦略は,RSIとボリンジャーバンドを活用してトレンドと逆転を特定し,TP/SLをリスク制御に設定する.取引信号を自動的に検出し,出口を管理することができます.パラメータ最適化によって改善できるリスクはまだあります.一般的に,これは強力な適用性のある実践的な戦略です.


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



















もっと