보린저 밴드 기반의 이중 이동 평균 매칭 전략

저자:차오장날짜: 2023-11-24 15:32:57
태그:

img

전반적인 설명

볼링거 밴드 (Bollinger Bands) 를 기반으로 한 이중 이동 평균 매칭 전략은 시장의 가격과 부피와 함께 실행되는 트렌드-추천 전략이다. 그것은 자동으로 시장 추세를 식별하고 스톱 노프 (stop profit) 및 스톱 로스 (stop loss) 규칙을 사용하여 거래 전략을 구현하기 위해 볼링거 밴드 (Bollinger Bands) 와 이동 평균의 크로스오버 (crossover) 를 거래 신호로 사용합니다.

전략 원칙

이 전략은 주로 볼링거 밴드 지표와 이동 평균 지표의 크로스오버 신호를 기반으로 거래합니다. 구체적으로 볼링거 밴드의 중간 레일, 상부 레일 및 5 ~ 200 일 사이의 길이의 7 개의 이동 평균을 동시에 사용합니다. 가격이 아래에서 위로 볼링거 밴드의 중간 및 하부 레일을 통과 할 때 구매 신호를 생성합니다. 가격이 아래에서 위로 볼링거 밴드의 상부 레일을 통과 할 때 판매 신호를 생성하여 추세를 달성합니다.

또한, 전략은 또한 긴 포지션과 짧은 포지션을 판단하기 위한 moveToFract 지표를 도입한다. 이 지표는 단기 및 장기 이동 평균의 배열 순서를 계산하여 현재 시장 추세가 상승 또는 하락하는지 결정하여 범위 제한 시장에서 잘못된 신호를 생성하는 것을 피한다. 마지막으로 구성 가능한 스톱 노프프 및 스톱 로스 규칙과 결합하여 거래 전략을 따르는 더 완전한 추세를 형성한다.

이점 분석

  1. 다양한 시장 환경에 맞게 매개 변수 조합을 사용자 정의 할 수있는 유연한 구성
  2. 필터로 두 가지 다른 표시기를 결합하면 잘못된 신호를 줄일 수 있습니다.
  3. 트렌드 판단 지표는 변동적인 시장에서 역행 작전을 피할 수 있습니다.
  4. 스톱 로스 설정을 추적하면 수익을 극대화 할 수 있습니다.

위험 분석

  1. 매개 변수들은 과도한 거래를 피하기 위해 서로 다른 시간 프레임의 주기에 적절하게 조정되어야 합니다.
  2. 추적 중지 손실은 빠른 감소에서 손실을 확장 할 수 있습니다.
  3. 충분한 자금을 확보해야 하며, 그렇지 않으면 지속적인 손실의 위험을 견딜 수 없습니다.

최적화 방향

  1. 더 이상 최적화하기 위해 황금 십자가와 죽음의 십자가 판단을 추가
  2. 다양한 품종은 다른 매개 변수를 가지고, 최적의 매개 변수를 위해 기계 학습을 고려
  3. 트렌드 변동성을 결정하고 위험 통제를 강화하기 위해 변동성 지수와 결합

결론

일반적으로, 이것은 매우 실용적인 트렌드 다음 전략이다. 결정 결정에 대한 지표 크로스오버를 사용하며, 또한 잘못된 신호를 효과적으로 필터링하기 위해 트렌드 판단 모듈을 통합한다. 스톱 이윤과 스톱 손실을 구성한 후, 트렌드를 완전히 따라 거래하고 좋은 수익을 얻을 수 있다. 매개 변수 조합을 조정하고 더 많은 필터를 추가함으로써, 이 전략은 더 많은 시장 환경에 적응하기 위해 더 이상 최적화 될 수 있으며, 개선 및 응용 전망에 큰 여지가 있다.


/*backtest
start: 2023-10-24 00:00:00
end: 2023-11-23 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/
// © HeWhoMustNotBeNamed

//@version=4
strategy("BuyTheDip", overlay=true, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01, calc_on_order_fills = true)

MAType = input(title="Moving Average Type", defval="sma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
exitType = input(title="Exit Strategy", defval="Signal", options=["Signal", "TrailingStop", "Both"])
LookbackPeriod = input(30, minval=10,step=10)

BBStdDev = input(2, minval=1, maxval=10, step=0.5)
BBLength = input(60, minval=5, step=5)

atrLength = input(22)
atrMult = input(6)

tradeDirection = input(title="Trade Direction", defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
backtestYears = input(10, minval=1, step=1)
includePartiallyAligned = true
f_getMovingAverage(source, MAType, length)=>
    ma = sma(source, length)
    if(MAType == "ema")
        ma := ema(source,length)
    if(MAType == "hma")
        ma := hma(source,length)
    if(MAType == "rma")
        ma := rma(source,length)
    if(MAType == "vwma")
        ma := vwma(source,length)
    if(MAType == "wma")
        ma := wma(source,length)
    ma

f_getTrailingStop(atr, atrMult)=>
    stop = close - atrMult*atr
    stop := strategy.position_size > 0 ? max(stop, stop[1]) : stop
    stop

f_getMaAlignment(MAType, includePartiallyAligned)=>
    ma5 = f_getMovingAverage(close,MAType,5)
    ma10 = f_getMovingAverage(close,MAType,10)
    ma20 = f_getMovingAverage(close,MAType,20)
    ma30 = f_getMovingAverage(close,MAType,30)
    ma50 = f_getMovingAverage(close,MAType,50)
    ma100 = f_getMovingAverage(close,MAType,100)
    ma200 = f_getMovingAverage(close,MAType,200)

    upwardScore = 0
    upwardScore := close > ma5? upwardScore+1:upwardScore
    upwardScore := ma5 > ma10? upwardScore+1:upwardScore
    upwardScore := ma10 > ma20? upwardScore+1:upwardScore
    upwardScore := ma20 > ma30? upwardScore+1:upwardScore
    upwardScore := ma30 > ma50? upwardScore+1:upwardScore
    upwardScore := ma50 > ma100? upwardScore+1:upwardScore
    upwardScore := ma100 > ma200? upwardScore+1:upwardScore
    
    upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
    downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
    upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 5? 0.5: upwardScore < 2?-0.5:upwardScore>3?0.25:-0.25) : 0
    
inDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)

exitBySignal = exitType == "Signal" or exitType == "Both"
exitByTrailingStop = exitType == "TrailingStop" or exitType == "Both"
maAlignment = f_getMaAlignment(MAType,includePartiallyAligned)
atr = atr(atrLength)

trailingStop = f_getTrailingStop(atr, atrMult)
maAligned = highest(maAlignment,LookbackPeriod)
[middle, upper, lower] = bb(close, BBLength, BBStdDev)

buyCondition = maAligned == 1 and (crossover(close, lower) or crossover(close, middle))
buyExitCondition = crossunder(close, upper)

strategy.entry("Buy", strategy.long, when=buyCondition and inDateRange, oca_name="oca_buy")
strategy.close("Buy", when=buyExitCondition and exitBySignal)
strategy.exit("ExitBuy", "Buy", stop = trailingStop, when=exitByTrailingStop )




더 많은