볼링거 밴드 및 VWAP 기반의 양적 거래 전략

저자:차오장, 날짜: 2024-01-04 15:59:46
태그:

img

전반적인 설명

이 전략은 입점 및 출구 결정을 내리기 위해 볼링거 밴드 (BB) 및 볼륨 가중 평균 가격 (VWAP) 지표를 결합합니다. 거래에 대한 단기 가격 이상 현상을 발견 할 수 있으며 단기 거래에 적합합니다.

전략 논리

이 전략은 주로 다음의 입국 및 출국 규칙을 기반으로 합니다.

  1. 트렌드를 판단하기 위한 전제 조건으로 느린 EMA 라인 위의 빠른 EMA 라인

  2. 매매가 상승세를 나타내는 VWAP보다 높은 가격으로 닫을 때 구매합니다

  3. 마지막 10 바에서 닫기 가격이 BB 하단 범위를 넘어섰다면 긴 값을 입력합니다.

  4. 마감 가격이 가격 반전을 나타내는 BB 상단 범위를 넘으면 판매

구체적으로, 50일 EMA가 200일 EMA보다 높는지 판단하여 전체 트렌드를 결정합니다. 그 다음 VWAP와 결합하여 가격이 단기 상승 추세인지 판단합니다. 마지막으로 볼링거 밴드를 사용하여 단기 비정상 하락을 탐지합니다.

출입 규칙은 간단합니다. 가격이 BB 상단보다 높을 때 출입합니다. 가격 반전을 나타냅니다.

이점 분석

이 전략은 엔트리 신호의 유효성을 높이기 위해 여러 지표를 결합합니다. 전체 트렌드를 판단하기 위해 EMA를 사용하면 트렌드에 반대하는 거래를 피합니다. VWAP는 단기 상승 동력을 캡처합니다. BB는 엔트리의 타이밍으로 단기 이상성을 감지합니다.

위험 분석

  1. EMA의 추세 판단이 정확하지 않아 추세에 반하는 거래가 발생한다
  2. VWAP는 시간적 데이터 또는 하루 내 데이터에 더 적합하며, 일일 데이터에 효율성이 떨어집니다.
  3. BB 매개 변수 설정 부적절, 너무 넓은 또는 좁은 대역 신호가 없습니다

위험을 완화하기 위해 EMA와 BB의 매개 변수를 조정할 수 있습니다. 트렌드 검출을 위해 다른 지표를 테스트하십시오. VWAP를 더 짧은 시간 내에 사용하십시오. 최고의 대역폭을 위해 BB 매개 변수를 최적화하십시오.

더 나은 기회

  1. MACD와 같은 트렌드 검출을 위한 다른 지표를 테스트합니다.
  2. EMA와 BB 매개 변수를 최적화
  3. 스톱 손실 메커니즘을 추가합니다.
  4. 잘못된 신호를 피하기 위해 필터를 추가합니다.
  5. 다양한 제품 및 시간 프레임에 대한 백테스트

결론

이 전략은 BB와 VWAP를 결합하여 엔트리 타이밍으로 단기 가격 변칙을 감지합니다. 전반적인 트렌드를 결정하기 위해 EMA를 사용하면 트렌드에 반대되는 거래를 피합니다. 단기 추진력을 빠르게 발견 할 수 있습니다. 내일 및 단기 거래에 적합합니다. 매개 변수를 최적화하고 더 많은 논리를 통합하여 안정성과 수익성을 더욱 향상시킵니다.


/*backtest
start: 2023-12-04 00:00:00
end: 2024-01-03 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/
// © mohanee

//@version=4
strategy(title="VWAP and BB strategy [EEMANI]", overlay=true,pyramiding=2, default_qty_value=3, default_qty_type=strategy.fixed,    initial_capital=10000, currency=currency.USD)
//This strategy combines VWAP and BB indicators
//BUY RULE
//1. EMA50 > EMA 200
//2. if current close > vwap session  value 
//3. check if  price dipped BB lower band for any of last 10 candles
//EXIT RULE
//1. price closes above BB upper band   
//STOP LOSS EXIT
//1. As configured --- default is set to 5%

is_price_dipped_bb(pds,source1) =>
    t_bbDipped=false
    for i=1 to pds
        t_bbDipped:=  (t_bbDipped   or  close[i]<source1) ? true : false
        if t_bbDipped==true
            break
        else
            continue
            
    t_bbDipped
    
// variables  BEGIN
shortEMA = input(50, title="fast EMA", minval=1)
longEMA = input(200, title="slow EMA", minval=1)

//BB

smaLength = input(20, title="BB SMA Length", minval=1)
bbsrc = input(close, title="BB Source")



//addOnDivergence = input(true,title="Add to existing on Divergence")
//exitOption = input(title="exit on RSI or BB", type=input.string, options=["RSI", "BB"],      defval="BB")

//bbSource = input(title="BB  source", type=input.string, options=["close", "vwap"],      defval="close")
     
//vwap_res = input(title="VWAP Resolution", type=input.resolution, defval="session")
stopLoss = input(title="Stop Loss%", defval=5, minval=1)

//variables  END




longEMAval= ema(close, longEMA)
shortEMAval= ema(close, shortEMA)


vwapVal=vwap(close)



// Drawings

//plot emas
plot(longEMAval, color = color.orange, linewidth = 1, transp=0)
plot(shortEMAval, color = color.green, linewidth = 1, transp=0)


//bollinger calculation 
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(bbsrc, smaLength)
dev = mult * stdev(bbsrc, smaLength)
upperBand = basis + dev
lowerBand = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//bollinger calculation 

//plot bb
//plot(basis, "Basis", color=#872323, 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=#198787, transp=95)


plot(vwapVal, color = color.purple, linewidth = 1, transp=0)


// Colour background

barcolor(shortEMAval>longEMAval and close<=lowerBand ? color.yellow: na)
  

//longCondition=  shortEMAval > longEMAval and  close>open and  close>vwapVal
longCondition= shortEMAval >= longEMAval  and  close>=vwapVal and close>open  //      close>vwapVal   and   



//Entry
strategy.entry(id="VWAP_BB LE", comment="VB LE" , long=true,  when= longCondition and  is_price_dipped_bb(10,lowerBand) )  //and strategy.position_size<1 

//add to the existing position
//strategy.entry(id="VWAP_RSI LE", comment="VR LE Add" , long=true,  when= addOnDivergence==true and strategy.position_size>=1 and close<strategy.position_avg_price   and (close<lowerBand or  low<lowerBand) and rsiVal>rsi_buy_line)

barcolor(strategy.position_size>=1  ? color.blue: na)



strategy.close(id="VWAP_BB LE", comment="TP Exit VB LE",   when=crossover(close,upperBand) )

//stoploss
stopLossVal =   strategy.position_avg_price * (1-(stopLoss*0.01) )
strategy.close(id="VB LE", comment="SL Exit",   when= close < stopLossVal)



더 많은