フィボナッチ数列に基づく適応型ボリンジャーバンド戦略の分析

ATR BB SMA FIB
作成日: 2025-01-06 16:41:48 最終変更日: 2025-01-06 16:41:48
コピー: 2 クリック数: 434
1
フォロー
1617
フォロワー

フィボナッチ数列に基づく適応型ボリンジャーバンド戦略の分析

概要

この戦略は、フィボナッチ数列とボリンジャーバンドを組み合わせた革新的な取引システムです。従来のボリンジャーバンドの標準偏差倍数をフィボナッチ比率(1.618、2.618、4.236)に置き換えることで、独自の価格変動幅判定システムを形成します。この戦略には、ストッププロフィットとストップロスの設定、取引時間ウィンドウのフィルタリングなど、完全な取引管理機能が含まれており、非常に実用的で柔軟性があります。

戦略原則

この戦略の核となるロジックは、価格とフィボナッチ ボリンジャー バンドの相互作用に基づいています。まず、価格の単純移動平均 (SMA) を中間トラックとして計算し、次に ATR にさまざまなフィボナッチ比率を掛けて上部トラックと下部トラックを形成します。価格がユーザーが選択したフィボナッチバンドを突破すると、システムは取引シグナルを生成します。具体的には、最低価格が目標買いバンドより低く、最高価格がバンドより高い場合にロングシグナルが発動され、最低価格が目標売りバンドより低く、最高価格がバンドより高い場合にショートシグナルが発動される。バンドよりも。

戦略的優位性

  1. 強力な適応性: ATR を通じて帯域幅を動的に調整し、さまざまな市場環境に戦略をより適切に適応させます。
  2. 高い柔軟性: ユーザーは、取引スタイルに応じて、さまざまなフィボナッチバンドを取引シグナルとして選択できます。
  3. 完璧なリスク管理: ストッププロフィット、ストップロス、時間フィルタリング機能が組み込まれており、リスクを効果的に管理できます。
  4. 視覚的な直感: トレーダーが市場構造を理解するのに役立つように、さまざまな透明度バンドが表示されます。
  5. 明確な計算ロジック:古典的なテクニカル指標の組み合わせを使用し、理解しやすく維持しやすい

戦略リスク

  1. 偽のブレイクアウトリスク: ブレイクアウト後すぐに価格が下落し、偽のシグナルが発生する可能性がある
  2. パラメータ感度: フィボナッチ比率の選択によって戦略のパフォーマンスに大きく影響する可能性がある
  3. 時間依存性: 取引時間ウィンドウを有効にすると、重要な取引機会を逃す可能性があります。
  4. 市場環境への依存: 不安定な市場では取引シグナルが多すぎる可能性がある

戦略最適化の方向性

  1. シグナル確認メカニズム:ブレイクスルーの確認としてボリュームまたはモメンタムインジケーターを追加することをお勧めします
  2. 動的パラメータ最適化: フィボナッチ比率は市場のボラティリティに基づいて自動的に調整されます
  3. 市場環境フィルタリング:トレンド判断機能を追加し、異なる市場環境で異なるパラメータを使用する
  4. 信号重み付けシステム: 信号の信頼性を向上させるために複数の時間枠分析を確立する
  5. ポジション管理の最適化: 市場のボラティリティとシグナルの強さに基づいてポジションサイズを動的に調整します

要約する

これは、古典的なテクニカル分析ツールを革新的に組み合わせ、フィボナッチ数列を通じて従来のボリンジャーバンド戦略を最適化する戦略です。その主な利点は適応性と柔軟性にありますが、使用時にはパラメータ選択と市場環境とのマッチングに注意を払う必要があります。この戦略には、追加の確認インジケーターを追加し、シグナル生成メカニズムを最適化することで、まだ改善の余地が大いにあります。

ストラテジーソースコード
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
// © sapphire_edge 

// # ========================================================================= #
// #                  
// #        _____                   __    _              ______    __         
// #      / ___/____ _____  ____  / /_  (_)_______     / ____/___/ /___ ____ 
// #      \__ \/ __ `/ __ \/ __ \/ __ \/ / ___/ _ \   / __/ / __  / __ `/ _ \
// #     ___/ / /_/ / /_/ / /_/ / / / / / /  /  __/  / /___/ /_/ / /_/ /  __/
// #    /____/\__,_/ .___/ .___/_/ /_/_/_/   \___/  /_____/\__,_/\__, /\___/ 
// #              /_/   /_/                                     /____/       
// #                                      
// # ========================================================================= #

strategy(shorttitle="⟡Sapphire⟡ FiboBands Strategy", title="[Sapphire] Fibonacci Bollinger Bands Strategy", initial_capital= 50000, currency= currency.USD,default_qty_value = 1,commission_type= strategy.commission.cash_per_contract,overlay= true )

// # ========================================================================= #
// #                       // Settings Menu //
// # ========================================================================= #

// --------------------    Main Settings    -------------------- //
groupFiboBands = "FiboBands"
length = input.int(20, minval = 1, title = 'Length', group=groupFiboBands)
src = input(close, title = 'Source', group=groupFiboBands)
offset = input.int(0, 'Offset', minval = -500, maxval = 500, group=groupFiboBands)

fibo1 = input(defval = 1.618, title = 'Fibonacci Ratio 1', group=groupFiboBands)
fibo2 = input(defval = 2.618, title = 'Fibonacci Ratio 2', group=groupFiboBands)
fibo3 = input(defval = 4.236, title = 'Fibonacci Ratio 3', group=groupFiboBands)

fiboBuy = input.string(options = ['Fibo 1', 'Fibo 2', 'Fibo 3'], defval = 'Fibo 1', title = 'Fibonacci Buy', group=groupFiboBands)
fiboSell = input.string(options = ['Fibo 1', 'Fibo 2', 'Fibo 3'], defval = 'Fibo 1', title = 'Fibonacci Sell', group=groupFiboBands)

showSignals = input.bool(true, title="Show Signals", group=groupFiboBands)
signalOffset = input.int(5, title="Signal Vertical Offset", group=groupFiboBands)

// --------------------    Trade Management Inputs    -------------------- //
groupTradeManagement = "Trade Management"
useProfitPerc    = input.bool(false, title="Enable Profit Target", group=groupTradeManagement)
takeProfitPerc  = input.float(1.0, title="Take Profit (%)", step=0.1, group=groupTradeManagement)
useStopLossPerc    = input.bool(false, title="Enable Stop Loss", group=groupTradeManagement)
stopLossPerc    = input.float(1.0, title="Stop Loss (%)", step=0.1, group=groupTradeManagement)

// --------------------    Time Filter Inputs    -------------------- //
groupTimeOfDayFilter = "Time of Day Filter"
useTimeFilter1  = input.bool(false, title="Enable Time Filter 1", group=groupTimeOfDayFilter)
startHour1      = input.int(0, title="Start Hour (24-hour format)", minval=0, maxval=23, group=groupTimeOfDayFilter)
startMinute1    = input.int(0, title="Start Minute", minval=0, maxval=59, group=groupTimeOfDayFilter)
endHour1        = input.int(23, title="End Hour (24-hour format)", minval=0, maxval=23, group=groupTimeOfDayFilter)
endMinute1      = input.int(45, title="End Minute", minval=0, maxval=59, group=groupTimeOfDayFilter)
closeAtEndTimeWindow = input.bool(false, title="Close Trades at End of Time Window", group=groupTimeOfDayFilter)

// --------------------    Trading Window    -------------------- //
isWithinTradingWindow(startHour, startMinute, endHour, endMinute) =>
    nyTime            = timestamp("America/New_York", year, month, dayofmonth, hour, minute)
    nyHour            = hour(nyTime)
    nyMinute          = minute(nyTime)
    timeInMinutes     = nyHour * 60 + nyMinute
    startInMinutes    = startHour * 60 + startMinute
    endInMinutes      = endHour * 60 + endMinute
    timeInMinutes    >= startInMinutes and timeInMinutes <= endInMinutes

timeCondition =  (useTimeFilter1 ? isWithinTradingWindow(startHour1, startMinute1, endHour1, endMinute1) : true)

// Check if the current bar is the last one within the specified time window
isEndOfTimeWindow() =>
    nyTime            = timestamp("America/New_York", year, month, dayofmonth, hour, minute)
    nyHour            = hour(nyTime)
    nyMinute          = minute(nyTime)
    timeInMinutes     = nyHour * 60 + nyMinute
    endInMinutes      = endHour1 * 60 + endMinute1
    timeInMinutes == endInMinutes

// Logic to close trades if the time window ends
if timeCondition and closeAtEndTimeWindow and isEndOfTimeWindow()
    strategy.close_all(comment="Closing trades at end of time window")

// # ========================================================================= #
// #                       // Calculations //
// # ========================================================================= #

sma = ta.sma(src, length)
atr = ta.atr(length)

ratio1 = atr * fibo1
ratio2 = atr * fibo2
ratio3 = atr * fibo3

upper3 = sma + ratio3
upper2 = sma + ratio2
upper1 = sma + ratio1

lower1 = sma - ratio1
lower2 = sma - ratio2
lower3 = sma - ratio3

// # ========================================================================= #
// #                       // Signal Logic //
// # ========================================================================= #

// --------------------    Entry Logic    -------------------- //
targetBuy = fiboBuy == 'Fibo 1' ? upper1 : fiboBuy == 'Fibo 2' ? upper2 : upper3
buy = low < targetBuy and high > targetBuy

// --------------------    User-Defined Exit Logic    -------------------- //
targetSell = fiboSell == 'Fibo 1' ? lower1 : fiboSell == 'Fibo 2' ? lower2 : lower3
sell = low < targetSell and high > targetSell

// # ========================================================================= #
// #                       // Strategy Management //
// # ========================================================================= #

// --------------------    Trade Execution Flags    -------------------- //
var bool buyExecuted = false
var bool sellExecuted = false

float labelOffset = ta.atr(14) * signalOffset

// --------------------    Buy Logic    -------------------- //
if buy and timeCondition 
    if useProfitPerc or useStopLossPerc
        strategy.entry("Buy", strategy.long, stop=(useStopLossPerc ? close * (1 - stopLossPerc / 100) : na), limit=(useProfitPerc ? close * (1 + takeProfitPerc / 100) : na))
    else
        strategy.entry("Buy", strategy.long)

    if showSignals and not buyExecuted
        buyExecuted := true  
        sellExecuted := false  
        label.new(bar_index, high - labelOffset, "◭", style=label.style_label_up, color = color.rgb(119, 0, 255, 20), textcolor=color.white)

// --------------------    Sell Logic    -------------------- //
if sell and timeCondition
    if useProfitPerc or useStopLossPerc
        strategy.entry("Sell", strategy.short, stop=(useStopLossPerc ? close * (1 + stopLossPerc / 100) : na), limit=(useProfitPerc ? close * (1 - takeProfitPerc / 100) : na))
    else
        strategy.entry("Sell", strategy.short)

    if showSignals and not sellExecuted
        sellExecuted := true 
        buyExecuted := false  
        label.new(bar_index, low + labelOffset, "⧩", style=label.style_label_down, color = color.rgb(255, 85, 0, 20), textcolor=color.white)



// # ========================================================================= #
// #                         // Plots and Charts //
// # ========================================================================= #

plot(sma, style = plot.style_line, title = 'Basis', color = color.new(color.orange, 0), linewidth = 2, offset = offset)

upp3 = plot(upper3, title = 'Upper 3', color = color.new(color.teal, 90), offset = offset)
upp2 = plot(upper2, title = 'Upper 2', color = color.new(color.teal, 60), offset = offset)
upp1 = plot(upper1, title = 'Upper 1', color = color.new(color.teal, 30), offset = offset)

low1 = plot(lower1, title = 'Lower 1', color = color.new(color.teal, 30), offset = offset)
low2 = plot(lower2, title = 'Lower 2', color = color.new(color.teal, 60), offset = offset)
low3 = plot(lower3, title = 'Lower 3', color = color.new(color.teal, 90), offset = offset)

fill(upp3, low3, title = 'Background', color = color.new(color.teal, 95))