볼링거 밴드 브레이크아웃 전략

저자:차오장, 날짜: 2024-02-06 14:36:26
태그:

img

전반적인 설명

이 전략은 VWAP를 추적하기 위해 볼링거 밴드를 사용합니다. VWAP가 중간 밴드 위에 깨지면 긴 포지션을 채택하고, VWAP가 하부 밴드 아래에 깨지면 포지션을 닫습니다. 피보트 포인트는 또한 잘못된 브레이크오프를 피하기 위해 진입을 위한 보조 신호로 사용됩니다.

전략 논리

  1. VWAP를 계산해
  2. VWAP의 Bollinger Bands를 계산합니다. 상위, 중위 및 하위 밴드를 포함합니다.
  3. VWAP가 중간 지대 이상으로 돌파하고 가격이 피보트 포인트 이상으로 돌파할 때 긴 포지션을 취합니다.
  4. 5%로 중지 손실을 설정
  5. VWAP가 하단 범위를 넘으면 긴 포지션을 닫습니다.

이점 분석

  1. VWAP는 강력한 트렌드 추적 능력을 가지고 있습니다. BB와 함께 트렌드 시작을 정확하게 식별합니다.
  2. 피보트 포인트를 추가하면 잘못된 브레이크를 필터링하여 불필요한 손실을 피합니다.
  3. 일부 이익의 일부 출구 잠금 및 통제 위험.
  4. 백테스트는 좋은 안정성을 가진 황소 시장에서 좋은 성과를 보여줍니다.

위험 분석

  1. 범위에 묶인 시장에서 거짓 파업으로 인한 손실에 유연합니다.
  2. 피보트 포인트는 잘못된 신호를 완전히 피할 수 없습니다. 더 많은 필터가 필요합니다.
  3. 거래 빈도가 증가하면 거래 비용이 더 높습니다.
  4. 베어 시장에서 좋은 성과를 거두지 못해 좋은 리스크 통제가 필요합니다.

최적화 방향

  1. MACD, KDJ와 같은 지표를 추가하여 신호를 필터합니다.
  2. 백테스트를 통해 BB 매개 변수를 최적화해
  3. 기계 학습을 사용하여 BB 매개 변수를 동적으로 최적화합니다.
  4. 최적을 찾기 위해 다른 스톱 로스 레벨을 테스트합니다.
  5. 시장의 변동성에 따라 적응적인 수익을 추가합니다.

결론

알고리즘 거래에 적합한 안정적인 브레이크아웃 시스템. 위험 통제에 대한 관심이 필요합니다. 추가 연구와 최적화로 훌륭한 브레이크아웃 전략이 될 수 있습니다.


/*backtest
start: 2024-01-06 00:00:00
end: 2024-02-05 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/
// © ediks123

//@version=4
strategy("BBofVWAP with entry at Pivot Point", overlay=false, pyramiding=1,   default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,

// Function outputs 1 when it's the first bar of the D/W/M/Y
is_newbar(res) =>
    ch = 0
    if(res == 'Y')
        t  = year(time('D'))
        ch := change(t) != 0 ? 1 : 0
    else
        t = time(res)
        ch := change(t) != 0 ? 1 : 0
    ch


//variables BEGIN
//smaLength=input(200,title="Slow MA Length")

bbLength=input(50,title="BB Length")  
//bbsrc = input(close, title="BB Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)

pp_period = input(title = "Pivot Period", type=input.string, defval="Week", options = ['Day', 'Week'])

pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' 

riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(5,title="Stop Loss",minval=1)



//sma200=sma(close,smaLength)
//plot(sma200, title="SMA 200", color=color.orange)

myVwap=vwap(hlc3)

//bollinger calculation
basis = sma(myVwap, bbLength)
dev = mult * stdev(myVwap, bbLength)
upperBand = basis + dev
lowerBand = basis - dev

//plot bb
plot(basis, "Basis", color=color.teal, style=plot.style_circles , offset = offset)
p1 = plot(upperBand, "Upper", color=color.teal, offset = offset)
p2 = plot(lowerBand, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=color.teal, transp=95)

plot(myVwap, title="VWAP", color=color.purple)


//pivot points 


// Calc High
high_cur = 0.0
high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)

phigh = 0.0
phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]

// Calc Low
low_cur = 0.0
low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)

plow = 0.0
plow := is_newbar(pp_res) ? low_cur[1] : plow[1]

// Calc Close
pclose = 0.0
pclose := is_newbar(pp_res) ? close[1] : pclose[1]


vPP = (phigh + plow + pclose) / 3

//pivot points


//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  

//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1


strategy.entry(id="BB_VWAP_PP",long=true, qty=qty1, when=   crossover(myVwap,basis)  and close>=vPP  )

bgcolor(strategy.position_size>=1?color.blue:na, transp=75)
barcolor(strategy.position_size>=1?color.green:na)

stopLossVal=  strategy.position_size>=1 ?  close * (1 - (stopLoss*0.01) ) : 0.00

//partial exit
//strategy.close(id="BBofVwap", qty=strategy.position_size/3, when=crossunder(myVwap,upperBand) and strategy.position_size>=1 )  //and close>strategy.position_avg_price)



//exit on lowerband or stoploss 
strategy.close(id="BB_VWAP_PP", comment="P" , qty=strategy.position_size/3, when= crossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_price)  //
strategy.close(id="BB_VWAP_PP", comment="Exit All", when=crossunder(myVwap,lowerBand) and strategy.position_size>=1 )
//strategy.close(id="BBofVwapWithFibPivot", comment="Exit All", when=crossunder(close,vPP) and strategy.position_size>=1 )

strategy.close(id="BB_VWAP_PP", comment="Stop Loss Exit", when=crossunder(close,stopLossVal) and strategy.position_size>=1 )

더 많은