피보나치 밴드 오시슬레이션 전략

저자:차오장, 날짜: 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")
 


더 많은