Bollinger Bands と RSI の組み合わせ戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-30 15:15:32
タグ:

img

概要

この戦略は,ボリンジャー・バンドと相対強度指数 (RSI) を組み合わせて,ボリンジャー・バンドが収縮し,RSIが上昇する機会を特定し,リスクを制御するためにストップ・ロスを追跡します.

戦略の論理

この戦略の主な論理は,RSIが上昇傾向にあるときにボリンジャーバンドの圧縮を特定し,価格のブレイクを予測することです.特に,20期間のBBの中央帯標準偏差がATR*2未満の場合,BB圧縮が起こることを決定します.一方,10期と14期間のRSIの両方が上昇している場合,価格はすぐにBB上部帯を超え,ロングに行く可能性があります.

市場に入ると,ATRセーフティディスタンス+アダプティブストップロスを使って利益をロックし,リスクを管理します.価格がストップロスの値に達したり,RSIが過買いになったとき (14期RSIが70を超え,10期RSIが14を超えると) ポジションは閉鎖されます.

利点分析

この戦略の最大の利点は,BB圧縮で統合期間を特定し,RSIでブレイクアウト方向を予測することです.また,固定ストップ損失ではなく市場の変動に基づいた適応ストップ損失を使用することで,リスクを制御しながら利益をよりうまくロックすることができます.

リスク分析

この戦略の主なリスクは,BB圧縮とRSI上昇傾向の誤認であり,誤ったブレイクアウトにつながる可能性があります.また,適応ストップ損失は,高い変動の間,ポジションを間に合って閉鎖できない可能性があります.カーブストップ損失などのストップ損失方法を改善することで,このリスクを軽減することができます.

最適化ガイドライン

この戦略は,次の側面でさらに最適化できます.

  1. BB パラメータを改良し,より正確に圧縮を識別する

  2. RSI 期間における異なる値をテストする

  3. カーブ SL や 振り返る SL などの他のストップ・ロスのテクニックを調べる.

  4. シンボルの特性に基づいてパラメータを調整する

結論

この戦略は,BBとRSIの互いを補完し,リスク調整された良いリターンを達成する.ストップ損失やパラメータ調整などの側面のさらなる最適化により,異なる取引手段により適している.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
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/
// © DojiEmoji
// 

//@version=4
strategy("[KL] BOLL + RSI Strategy",overlay=true,pyramiding=1)

// Timeframe {
backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)
USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")
backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)
within_timeframe = true
// }

// Bollinger bands (sdv=2, len=20) {
BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)
BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2
plot(SMA20, "Basis", color=#872323, offset = 0)
BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)
BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)
fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)
// }

// Volatility Indicators {
ATR_x2 = atr(BOLL_length) * 2 // multiplier aligns with BOLL
avg_atr = sma(ATR_x2, input(1,title="No. of candles to lookback when determining ATR is decreasing"))
plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)
plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)
plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)
//}

// Trailing stop loss {
TSL_source = low
var entry_price = float(0), var stop_loss_price = float(0)

trail_profit_line_color = color.green
if strategy.position_size == 0 or not within_timeframe
    trail_profit_line_color := color.black
    stop_loss_price := TSL_source - ATR_x2
else if strategy.position_size > 0
    stop_loss_price := max(stop_loss_price, TSL_source - ATR_x2)
plot(stop_loss_price, color=trail_profit_line_color)

if strategy.position_size > 0 and stop_loss_price > stop_loss_price[1]
	alert("Stop loss limit raised", alert.freq_once_per_bar)

// } end of Trailing stop loss

//Buy setup - Long positions {
is_squeezing = ATR_x2 > BOLL_sDEV_x2
if is_squeezing and within_timeframe and not is_squeezing[1]
	alert("BOLL bands are squeezing", alert.freq_once_per_bar)
else if not is_squeezing and within_timeframe and is_squeezing[1]
	alert("BOLL bands stopped squeezing", alert.freq_once_per_bar)

ema_trend = ema(close, 20)

concat(a, b) =>
	concat = a
	if a != ""
		concat := concat + ", "
	concat := concat + b
	concat
// }

// Sell setup - Long position {
rsi_10 = rsi(close, 10), rsi_14 = rsi(close, 14)
overbought = rsi_14 > input(70,title="[Exit] RSI(14) value considered as overbought") and rsi_10 > rsi_14
// } end of Sell setup - Long position

// MAIN: {
if within_timeframe
	entry_msg = ""
	exit_msg = ""

    // ENTRY {
	conf_count = 0	
    volat_decr = avg_atr <= avg_atr[1]
	rsi_upslope = rsi_10 > rsi_10[1] and rsi_14 > rsi_14[1]

	if volat_decr and rsi_upslope and is_squeezing and strategy.position_size == 0
		strategy.entry("Long",strategy.long, comment=entry_msg)
		entry_price := close
		stop_loss_price := TSL_source - ATR_x2
	// }

    // EXIT	{
	if strategy.position_size > 0
		bExit = false
		if close <= entry_price and TSL_source <= stop_loss_price
            exit_msg := concat(exit_msg, "stop loss [TSL]")
			bExit := true
        else if close > entry_price and TSL_source <= stop_loss_price
            exit_msg := concat(exit_msg, "take profit [TSL]")
            bExit := true
		else if overbought
			exit_msg := concat(exit_msg, "overbought")
			bExit := true

        strategy.close("Long", when=bExit, comment=exit_msg)
	// }
// }

// CLEAN UP:
if strategy.position_size == 0 and not is_squeezing
	entry_price := 0
	stop_loss_price := float(0)


もっと