
これは,ブリン帯通路に基づく反転振動トレンド戦略である.これは,ブリン帯上下通路をトレンド判断として使用し,価格が通路の境界に近づくと反転の機会を探して入場する.
この戦略は,ブリン帯の指標を主要な技術指標として使用している.ブリン帯は,n日移動平均とその上下波動範囲で構成されており,ブリン帯上軌=n日移動平均+m×n日標準差,ブリン帯下軌=n日移動平均−m×n日標準差である.nとmがパラメータである.
価格が上線に近づくと,現在の上昇傾向にあるが,逆転する可能性があることを示す.価格が下線に近づくと,現在の下降傾向にあるが,逆転する可能性があることを示す.このとき,ブルリン帯を効果的に破れば,逆転を開始する可能性がある.
この戦略の具体的な取引規則は以下の通りです.
閉盘価格がブリン帯上線より大きいときは,多入場;閉盘価格がブリン帯下線より小さいときは,空き入場。
ストップ・ロスはn日移動平均で信号. 多単位の閉盘価格を下回ってn日平均線を破るときにストップ・ロスは出場する. 空単位の閉盘価格の上回ってn日平均線を破るときにストップ・ロスは出場する.
固定取引量で,取引の数は固定されます.
固定比率の資金管理法を採用し,固定利回り率と注文調整幅を設定する.固定比率の利回りが達成されたとき,固定利回り率でポジションを増やし,損失が起きたとき,ポジションを減らす.
この戦略の利点は以下の通りです.
ブリン帯通路を使用してトレンドの方向を判断し,逆転取引戦略を採用し,価格が逆転する可能性のあるタイミングで入場し,ほとんどの揺れを回避し,勝率を上げます.
移動平均は,ストップ・ストップ・ロスの信号としてより信頼性が高く,利益のほとんどをロックすることができます.
固定取引量戦略は簡単で,複雑な計算を必要としません.
固定比率の資金管理戦略は,ポジションの調整によって利益を拡大しながらリスクを制御することができます.
この戦略にはリスクもあります.
ブリン帯判定が誤信号を生成する確率があり,トレンドの逆転で単一損失を起こす可能性があります.
移動平均の遅滞により,足らないストップが発生する可能性があります.
固定取引量では,市場状況に応じてポジションを調整することができないため,ポジションが大きすぎたり小さすぎたりする問題がある.
固定比率の資金管理方法により,ポジションの幅が大きくなり,損失が拡大する可能性があります.
対策: ブリン帯のパラメータを最適化し,信号の正確性を向上させる.他の指標と組み合わせてトレンドを判断する.固定ポジションのサイズを適切に縮小する.固定比率資金管理のポジション調整幅を低下させる.
この戦略は以下の点で最適化できます.
ブリン帯のパラメータの最適化,例えばn値とm値の調整,ブリン帯通路判断の正確性の向上.
MACD,KDなどの他の指標の判断を追加し,ブリンが誤信号を帯びないようにする.
固定取引量を動的取引量に調整し,市場の状況に応じてポジションを柔軟に調整する.
固定比率資金管理法のポジション調整幅を低くし,資金曲線を最適化する.
移動ストップ,区間突破ストップなどのストップ戦略を追加し,リスクをさらに制御します.
パラメータ最適化,パラメータの組み合わせの自動最適化,戦略の最適化のための最適なパラメータを探す.
この戦略は,全体として,比類的なブリン帯反転戦略である.ブリン帯を活用してトレンドの反転点を判断し,移動平均をセットしてストップ・ストロー,固定取引量,固定比率の資金管理を制御するリスクと組み合わせている.従来のブリン帯戦略と比較して,この戦略は,反転戦略として,理論的には,部分的な揺れを回避し,利益の確率を向上させる.しかし,ブリン帯や移動平均線などの指標自体には欠陥があるため,実際の運用では,戦略をパラメータ化して取引リスクを減らすために,さらなる最適化が必要である.
/*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))