フィボナッチ帯振動戦略

作者: リン・ハーンチャオチャン,日付: 2023-11-21 13:47:12
タグ:

img

概要

フィボナッチ帯振動戦略 (Fibonacci Band Oscillation Strategy) は,フィボナッチ理論に基づいて設計された定量戦略である.主にフィボナッチ比率を使用して,複数の価格帯を計算して上下帯を形成する.価格がバンドを突破すると,利益のためにバンド間の振動特性を捕捉するために取引信号が生成される.

戦略の論理

コードの基本論理は,フィボナッチ値帯をキーポイントとして計算することです.主なステップは:

  1. 中間線として 14 期間の EMA を計算する
  2. ATRとフィボナッチ比に従って上下4帯線を計算する
  3. 価格がダウンバンドやアップバンドを突破したときの取引信号を生成する
  4. 利益のために価格の振動を追跡するためにストップ・ロスを設定し,利益を取ります

この突破型手法によって 市場における短期変動を効果的に把握し 利益を得るために バンド間での往復取引を行うことができます

利点

この戦略の最大の利点は,重要な価格ポイントを特定するために,フィボナッチ比率という重要な理論指標を利用し,それによって利益の確率を増やすことである.具体的な利点は主に以下に反映されている.

  1. 透明なフィボナッチ帯で 突破点を判断しやすい
  2. 合理的な帯域範囲で,過度に断片化したり,過度に緩やかでない
  3. 攻撃的および保守的な取引の両方に複数のバンドを選択できます
  4. 帯振動の特徴が大きいため,短期間の取引戦略に良い影響を与える

リスク

この戦略は短期的な利益を追求しているため,注意すべきリスクもあります.

  1. 大規模なサイクル傾向下で利益を得られない
  2. 激烈な価格変動下で高いストップ損失リスク
  3. 多くの突破信号は慎重に選択する必要があります
  4. バンド振動の特徴が失われる場合,無効

これらのリスクは,パラメータを適切に調整し,適切な範囲を選択し,資本管理方法によって制御できます.

最適化

戦略のさらなる最適化にはまだ余地があります.

  1. トレンドインジケーターと組み合わせて,特定のトレンド方向にのみシグナルを生成する
  2. 特定の時間帯や重要な出来事の前と後に戦略を閉じる
  3. ストップ・ロスの幅を市場の変動頻度に応じて動的に調整する
  4. バランスラインとして異なるサイクルの EMA を選択してパラメータを最適化する

結論

一般的に,フィボナッチ帯振動戦略は,非常に実践的な短期戦略である.フィボナッチ理論を使用して価格のキーポイントを設定する.価格がこれらのポイントの周りに振動すると,寛大な利益を得ることができる.このブレイクアウトベースの方法は,一定程度の変動性と特性を持つ市場に適しています.単独または他の戦略と組み合わせて使用できます.パラメータチューニングと適切な資本管理により,戦略は長期的に安定して動作することができます.


/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
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/
// © drhakankilic

//@version=5
strategy("FIBONACCI BANDS Strategy", shorttitle="FBANDS Strategy", overlay=true)
// === Date === { 
//Backtest dates
fromDay = input.int(defval=1, title='From Day',minval=1,maxval=31)
fromMonth = input.int(defval=2, title='From Month',minval=1,maxval=12)
fromYear = input.int(defval=2022, title='From Year')
thruDay = input.int(defval=1, title='Thru Day',minval=1,maxval=31)
thruMonth = input.int(defval=1, title='Thru Month',minval=1,maxval=12)
thruYear = input.int(defval=2112, title='Thru Year')
showDate = true  // input(defval=true, title="Show Date Range")
start = timestamp(fromYear, fromMonth, fromDay, 00, 00)  // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59)  // backtest finish window
window() =>  // create function "within window of time"
    time >= start and time <= finish ? true : false
// }

// === Long or Short ===  
tradeDirection = input.string(title="Long veya Short", options=["Long", "Short", "Both"], defval="Both",                                       group="Bot")
// Translate input into trading conditions
longOK  = (tradeDirection == "Long") or (tradeDirection == "Both")
shortOK = (tradeDirection == "Short") or (tradeDirection == "Both")
copypaste   = input('{{strategy.order.alert_message}}',         title='alert message to copy/paste',                                    group="Bot")
// }

// === FIBONACCI BANDS === {
EMAperiod = input.int(14, title='EMAperiod', minval=1, maxval=500, group="Fibonacci")
ATRperiod = input.int(14, title='ATRperiod', minval=1, maxval=500, group="Fibonacci")
EMA = ta.ema(close, EMAperiod)
TR1 = math.max(high - low, math.abs(high - close[1]))
TR = math.max(TR1, math.abs(low - close[1]))
ATR = ta.sma(TR, ATRperiod)
F2 = input(defval=1.618, title='Fibonacci Ratio 2', group="Fibonacci")
F3 = input(defval=2.618, title='Fibonacci Ratio 3', group="Fibonacci")
F4 = input(defval=4.236, title='Fibonacci Ratio 4', group="Fibonacci")
R1 = ATR
R2 = ATR * F2
R3 = ATR * F3
R4 = ATR * F4
FIBOTOP4 = EMA + R4
FIBOTOP3 = EMA + R3
FIBOTOP2 = EMA + R2
FIBOTOP1 = EMA + R1
FIBOBOT1 = EMA - R1
FIBOBOT2 = EMA - R2
FIBOBOT3 = EMA - R3
FIBOBOT4 = EMA - R4
plot(FIBOTOP4[1], title='FIBOTOP4', linewidth=1, color=color.new(color.orange, 0))
plot(FIBOTOP3[1], title='FIBOTOP3', linewidth=1, color=color.new(color.aqua, 20))
plot(FIBOTOP2[1], title='FIBOTOP2', linewidth=1, color=color.new(color.gray, 40))
plot(FIBOTOP1[1], title='FIBOTOP1', linewidth=1, color=color.new(color.purple, 40))

plot(FIBOBOT1[1], title='FIBOBOT1', linewidth=1, color=color.new(color.green, 40))
plot(FIBOBOT2[1], title='FIBOBOT2', linewidth=1, color=color.new(color.yellow, 40))
plot(FIBOBOT3[1], title='FIBOBOT3', linewidth=1, color=color.new(color.blue, 20))
plot(FIBOBOT4[1], title='FIBOBOT4', linewidth=1, color=color.new(color.aqua, 0))
// plot(EMA[1], style=plot.style_cross, title='EMA', color=color.new(color.red, 0))

prefm = input.string(title="Fibo", options=["close>FIBOTOP4(orange)", "close>FIBOTOP3(aqua)","close>FIBOTOP2(gray)","close>FIBOTOP1(purple)", "Disable"] , defval="close>FIBOTOP1(purple)", group="Long")
_prefm = false 
if (prefm == "close>FIBOTOP4(orange)" )
    _prefm := close>FIBOTOP4[1]
    
if (prefm == "close>FIBOTOP3(aqua)" )
    _prefm := close>FIBOTOP3[1]

if (prefm == "close>FIBOTOP2(gray)" )
    _prefm := close>FIBOTOP2[1]
    
if (prefm == "close>FIBOTOP1(purple)" )
    _prefm := close>FIBOTOP2[1]
 
 
if (prefm == "Disable" )
    _prefm := low<low[1] or low>low[1]  
    
prefmS = input.string(title="Fibo", options=["close<FIBOBOT1(green)", "close<FIBOBOT2(yellow)", "close<FIBOBOT3(blue)", "close<FIBOBOT4(aqua)", "Disable"] , defval="close<FIBOBOT1(green)", group="Short")
_prefmS = false 
if (prefmS == "close<FIBOBOT1(green)" )
    _prefmS := close<FIBOBOT1[1]
  
if (prefmS == "close<FIBOBOT2(yellow)" )
    _prefmS := close<FIBOBOT2[1]

if (prefmS == "close<FIBOBOT3(blue)" )
    _prefmS := close<FIBOBOT3[1]
  
if (prefmS == "close<FIBOBOT4(aqua)" )
    _prefmS := close<FIBOBOT4[1]

if (prefmS == "Disable" )
    _prefmS := low<low[1] or low>low[1]  

// }

long2= _prefm 

short2= _prefmS
//

// === Bot Codes === { 
enterlong = input("Long Code", title='Long İlk Alım', group="Long Code")
entershort= input("Short Code", title='Short İlk Alım', group="Short Code")
exitlong = input("Long Exit Code", title='Long Exit', group="Long Code")
exitshort= input("Short Exit Code", title='Short Exit', group="Short Code")
// }

////////////////////////////////////////////////////////////////////////////////////////////TPSL
// Inputs
sl_inp = input.float(4, title='Stop %', step=0.1, group="Long") / 100
tp_inp = input.float(1.5, title='TP %', step=0.1, group="Long") / 100

sl_inp2 = input.float(4, title='Stop %', step=0.1, group="Short") / 100
tp_inp2 = input.float(1.5, title='TP %', step=0.1, group="Short") / 100

longtp = strategy.position_avg_price * (1 + tp_inp) 
longstop=  strategy.position_avg_price * (1 - sl_inp)

shortstop=  strategy.position_avg_price * (1 + sl_inp2)
shorttp = strategy.position_avg_price * (1 - tp_inp2) 
////////////////////////////////////////////////////////////////////////////////////////////
if window() and strategy.position_size==0 and longOK
    strategy.entry("Long", strategy.long, when= long2, alert_message=enterlong, comment="Long")
    
if strategy.position_size>0
    strategy.exit("Long", stop= longstop, limit=longtp, alert_message=exitlong, comment="TPSL")
////////////////////////////////////////////////////////////////////////////////////////////SHORT
if window() and strategy.position_size==0 and shortOK 
    strategy.entry("Short", strategy.short, when= short2, alert_message=entershort, comment="Short")
    
if strategy.position_size<0
    strategy.exit("Short", stop= shortstop, limit= shorttp, alert_message=exitshort, comment="TPSL")
 


もっと