ボリンジャー・バンドのトレンド逆転戦略

作者: リン・ハーンチャオチャン,日付: 2023年11月1日 11:29:34
タグ:

img

概要

この戦略は,価格が上または下帯に近づくと,ボリンジャーバンドと移動平均をLONGまたはSHORTに利用する.価格が上帯を超えるとショートになり,価格が下帯を超えるとロングになる.この戦略は,トレンドフォローと平均逆転戦略の両方の利点を組み合わせ,レンジバインド市場では良好なパフォーマンスを発揮する.

論理

戦略では2つの入口信号を特定しています

  1. ロングシグナル:EMA線上にある間,閉じる価格が下帯に達すると,前のキャンドルは下落し,現在のキャンドルは上昇します.

  2. ショートシグナル:EMA線以下で閉じる価格が上位帯に達すると,前のキャンドルは上昇し,現在のキャンドルは下落する.

ストップ・ロスは固定ストップ・ロスを使用します.ストップ・ロスのレベルは,エントリー価格プラス/マイナスリスク/リターン比 ×エントリー価格とメリットレベル間の距離で設定されます.

テイク・プロフィートはダイナミック テイク・プロフィートを利用します. ロング テイク・プロフィートは下部帯に設定されます.ショート テイク・プロフィートは上部帯に設定されます.

利点

  1. トレンドフォローと平均逆転戦略の両方の強みを組み合わせ,レンジ・バインド市場では良好なパフォーマンスを発揮します.

  2. ボリンジャーバンドを使用して,買い過ぎと売り過ぎのレベルを特定し,逆転信号の精度を向上させます.

  3. 固定ストップロスはリスク管理を容易にする.

  4. ダイナミック・テイク・プロフィートは 利益の最大化を可能にします

リスク

  1. 脱出戦略は 走行を停止する傾向があります 偽脱出を注意する必要があります

  2. 市場が動揺しているときに 頻繁にストップロスを誘発します

  3. 固定ストップ損失は 市場の変動に適応できない. 幅が幅も狭すぎる.

  4. ボリンジャー帯のパラメータ調節が不十分であれば 平均的な結果が得られます

強化

  1. 入力シグナルをフィルタリングするためにRSIインジケーターを組み込む.例えば,RSIが50を超えるとロングで,RSIが50未満であればショートで.これは悪いシグナルを避ける.

  2. 変動に応じてストップ距離を調整する適応ストップ損失を実装する.例えば,動的ストップ損失を設定するためにATRを使用する.

  3. 最適なパラメータの組み合わせを見つけるためにボリンガー帯のパラメータを最適化します

  4. EMAのサポート/レジスタンス効果を高めるために,異なる EMA 期間をテストする.

概要

この戦略は,トレンドと逆転を組み合わせ,ボリンジャーバンドによって識別されたオーバーバイト/オーバーセールレベルに入ります.動的テイク・プロフィートを通じて利益を最大化します.レンジ・バインド市場ではうまく機能します.ストップ・ランに注意してください.パフォーマンスを最適化するためにパラメータを細かく調整します.全体として実践的で効果的な戦略です.


/*backtest
start: 2023-10-24 00:00:00
end: 2023-10-31 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

// Welcome to yet another script. This script was a lot easier since I was stuck for so long on the Donchian Channels one and learned so much from that one that I could use in this one
// This code should be a lot cleaner compared to the Donchian Channels, but we'll leave that up to the pro's
// This strategy has two entry signals, long = when price hits lower band, while above EMA, previous candle was bearish and current candle is bullish
// Short = when price hits upper band, while below EMA, previous candle was bullish and current candle is bearish
// Take profits are the opposite side's band(lower band for long signals, upper band for short signals). This means our take profit price will change per bar
// Our stop loss doesn't change, it's the difference between entry price and the take profit target divided by the input risk reward
// At the time of writing this, I could probably calculate that much easier by simply multiplying the opposite band by the input risk reward ratio
// Since I want to get this script out and working on the next one, I won't clean that up, I'm sorry
// strategy(shorttitle="BB Trending Reverse Strategy", title="Bollinger Bands Trending Reverse Strategy", overlay=true, default_qty_type = strategy.cash, default_qty_value = 150, initial_capital = 1000, currency = currency.USD, commission_type = "percent", commission_value = 0.036)

// The built-in Bollinger Band indicator inputs and variables, added some inputs of my own and organised the code
length              = input(20, minval=1)
src                 = input(close, title="Source")
mult                = input(2.0, minval=0.001, maxval=50, title="StdDev")
emaInput            = input(title = "EMA Input", type = input.integer, defval = 200, minval = 10, maxval = 400, step = 1)
riskreward          = input(title = "Risk/Reward Ratio", type = input.float, defval = 1.50, minval = 0.01, maxval = 100, step = 0.01)
offset              = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
basis               = sma(src, length)
dev                 = mult * stdev(src, length)
upper               = basis + dev
lower               = basis - dev
ema                 = ema(close, emaInput)

// These are our conditions as explained above
entryLong           = low[1] <= lower[1] and low <= lower and low > ema
entryShort          = high[1] >= upper[1] and high >= upper and high < ema
reversecandleLong   = close > open and close[1] < open[1]
reversecandleShort  = close < open and close[1] > open[1]
var stopLong        = 0.0
var stopShort       = 0.0

// These are our entry signals, notice how the stop condition is within the if statement while the strategy.exit is outside of the if statement, this way the take profit targets trails up or down depending on what the price does
if reversecandleLong and entryLong and strategy.position_size == 0
    stopLong := (((close / upper - 1) * riskreward + 1) * close)
    strategy.entry("Long Entry", strategy.long, comment = "Long Entry")
    
strategy.exit("Exit Long", "Long Entry", limit = upper, stop = stopLong, comment = "Exit Long")

if reversecandleShort and entryShort and strategy.position_size == 0
    stopShort := (((close / lower - 1) / riskreward + 1) * close)
    strategy.entry("Short Entry", strategy.short, comment = "Short Entry")

strategy.exit("Exit Short", "Short Entry", limit = lower, stop = stopShort, comment = "Exit Short")


// The built-in Bollinger Band plots
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=#198787, transp=95)
plot(ema, color=color.red)

// These plots are to check the stoplosses, they can  make a mess of your chart so only use these if you want to make sure these work
// plot(stopLong)
// plot(stopShort)

もっと