ボリンジャーバンド逆転振動トレンド戦略

作者: リン・ハーンチャオチャン開催日:2023年10月31日 14時30分45秒
タグ:

img

概要

これはボリンジャーバンドチャネルをベースとした逆転振動トレンド戦略である.トレンドを決定するためにボリンジャーバンド上下チャネルを使用し,価格がチャネル境界に近づくときに逆転の機会を探します.

戦略の論理

この戦略は,ボリンジャーバンドを主な技術指標として使用する.ボリンジャーバンドは,n期間の移動平均値と上部/下部バンドの偏差から構成される.上部バンド = n期間のMA + m * n期間の標準偏差,下部バンド = n期間のMA - m * n期間の標準偏差. nとmはパラメータである.

価格が上部帯に近づくと,上昇傾向を示すが,ピーク時に逆転する可能性がある.価格が下部帯に近づくと,下位帯に逆転する可能性がある.ボリンジャー帯の効果的なブレイクが潜在的な逆転を意味する.

特別取引規則は次のとおりです.

  1. 上部帯を閉じるとロング,下部帯を閉じるとショート.

  2. n 期間の移動平均を利益採取とストップ損失の信号として使用する.MA 下の閉じる時,長い閉じる.MA 上の閉じる時,短い閉じる.

  3. 取引ごとに固定量を使う.

  4. 固定割引のポジションサイズを使用します. 固定利益比を満たすときに固定金額でポジションサイズを増加し,損失の場合サイズを減少します.

利点分析

この戦略の利点は

  1. トレンド方向とトレード逆転を決定するためにボリンジャーバンドチャネルを使用することで,ほとんどのウィップソーを回避し,勝利率を向上させます.

  2. 移動平均は信頼性の高い 利益の引き上げ/ストップ損失の信号で ほとんどの利益を固定します

  3. 固定量は単純で簡単に実行できます 複雑な計算は必要ありません

  4. 固定分数のポジションサイズ化により ポジション調整によってリスクを制御しながら 利益も拡大します

リスク分析

この戦略のリスクは

  1. ボリンジャー・バンドは誤った信号を生成し,トレンドに反して取引する損失を引き起こす可能性があります.

  2. 移動平均値の遅延は,十分な利益を得られない可能性があります.

  3. 定額は市場状況に適応できないし,ポジションサイズが過小になるリスクもある.

  4. 固定分数法における積極的な位置サイズ調整は損失を拡大する可能性があります.

ソリューション:信号の精度を向上させるためにボリンガー帯パラメータを最適化する. 傾向を決定するために他の指標を追加する. 固定量サイズを減らす. 分数位置サイズメソッドで位置サイズ調整比率を下げる.

改善 の 方向

戦略は以下の側面から改善できます.

  1. 精度を高めるために n と m のようなボリンガー帯のパラメータを最適化します

  2. MACD,KDなどの他の指標を追加して,間違った信号を避ける.

  3. 定量から動的な位置付けに 市場状況に基づいて変更します

  4. ポジションサイズの調整比が低くなって ポジションサイズの割引で 株式の曲線が平らになる.

  5. リスクをコントロールするために 移動ストップ・ロース,ブレイク・ストップ・ロースなどのストップ・ロース戦略を追加します

  6. パラメータの最適化により,最適なパラメータの組み合わせを見つけることができます.

概要

概要すると,これは典型的なボリンジャーバンド逆転戦略である.ボリンジャーバンドによって逆転点を特定し,移動平均によって利益を取ること/ストップ損失を設定し,固定量と分数的なポジションサイジングによってリスクを制御する.逆転戦略として,理論的にはいくつかのウィップソウを避け,伝統的なボリンジャーバンド戦略と比較して収益性を向上させる.しかし,ボリンジャーバンドの欠陥,移動平均は,堅牢な実用的な適用のためにさらなる最適化とリスク管理を必要とする.


/*backtest
start: 2023-09-30 00:00:00
end: 2023-10-30 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/
// © gsanson66


//This strategy uses the well-known Bollinger Bands Indicator
//@version=5
strategy("BOLLINGER BANDS BACKTESTING", shorttitle="BB BACKTESTING", overlay=true, initial_capital=1000, default_qty_type=strategy.cash, default_qty_value=950, commission_type=strategy.commission.percent, commission_value=0.18)


//----------------------------------------FUNCTIONS---------------------------------------//

//@function Displays text passed to `txt` when called.
debugLabel(txt, color) =>
    label.new(bar_index, high, text = txt, color=color, style = label.style_label_lower_right, textcolor = color.black, size = size.small)

//@function which looks if the close date of the current bar falls inside the date range
inBacktestPeriod(start, end) => (time >= start) and (time <= end)


//---------------------------------------USER INPUTS--------------------------------------//

//Technical parameters
bbLength = input.int(defval=20, minval=1, title="BB Length", group="Technical Parameters")
mult = input.float(defval=2, minval=0.1, title="Standard Deviation Multipler", group="Technical Parameters")
smaLength = input.int(defval=20, minval=1, title="SMA Exit Signal Length", group="Technical Parameters")
//Money Management
fixedRatio = input.int(defval=400, minval=1, title="Fixed Ratio Value ($)", group="Money Management")
increasingOrderAmount = input.int(defval=200, minval=1, title="Increasing Order Amount ($)", group="Money Management")
//Backtesting period
startDate = input(title="Start Date", defval=timestamp("1 Jan 2020 00:00:00"), group="Backtesting Period")
endDate = input(title="End Date", defval=timestamp("1 July 2024 00:00:00"), group="Backtesting Period")


//----------------------------------VARIABLES INITIALISATION-----------------------------//
strategy.initial_capital = 50000
//Exit SMA
smaExit = ta.sma(close, smaLength)
//BB Calculation
basis = ta.sma(close, bbLength)
dev = mult * ta.stdev(close, bbLength)
upperBB = basis + dev
lowerBB = basis - dev
//Money management
equity = strategy.equity - strategy.openprofit
var float capital_ref = strategy.initial_capital
var float cashOrder = strategy.initial_capital * 0.95
//Backtesting period
bool inRange = na


//------------------------------CHECKING SOME CONDITIONS ON EACH SCRIPT EXECUTION-------------------------------//

//Checking if the date belong to the range
inRange := true

//Checking performances of the strategy
if equity > capital_ref + fixedRatio
    spread = (equity - capital_ref)/fixedRatio
    nb_level = int(spread)
    increasingOrder = nb_level * increasingOrderAmount
    cashOrder := cashOrder + increasingOrder
    capital_ref := capital_ref + nb_level*fixedRatio
if equity < capital_ref - fixedRatio
    spread = (capital_ref - equity)/fixedRatio
    nb_level = int(spread)
    decreasingOrder = nb_level * increasingOrderAmount
    cashOrder := cashOrder - decreasingOrder
    capital_ref := capital_ref - nb_level*fixedRatio

//Checking if we close all trades in case where we exit the backtesting period
if strategy.position_size!=0 and not inRange
    strategy.close_all()
    debugLabel("END OF BACKTESTING PERIOD : we close the trade", color=color.rgb(116, 116, 116))


//-----------------------------------EXIT SIGNAL------------------------------//

if strategy.position_size > 0 and close < smaExit
    strategy.close("Long")
if strategy.position_size < 0 and close > smaExit
    strategy.close("Short")


//----------------------------------LONG/SHORT CONDITION---------------------------//

//Long Condition
if close > upperBB and inRange
    qty = cashOrder/close
    strategy.entry("Long", strategy.long, qty)
//Short Condition
if close < lowerBB and inRange
    qty = cashOrder/close
    strategy.entry("Short", strategy.short, qty)


//---------------------------------PLOTTING ELEMENT----------------------------------//

plot(smaExit, color=color.orange)
upperBBPlot = plot(upperBB, color=color.blue)
lowerBBPlot = plot(lowerBB, color=color.blue)
fill(upperBBPlot, lowerBBPlot, title = "Background", color=strategy.position_size>0 ? color.rgb(0, 255, 0, 90) : strategy.position_size<0 ? color.rgb(255, 0, 0, 90) : color.rgb(33, 150, 243, 95))


もっと