이중 이동 평균 볼링거 밴드 트렌드 추적 전략

저자:차오장, 날짜: 2023-12-11 15:10:02
태그:

img

전반적인 설명

이 전략은 두 개의 기하급수적인 이동 평균 (EMA) 을 서로 다른 시간 프레임에 걸쳐 계산하여 일반적인 시장 트렌드 방향을 결정하고, 트렌드 거래를 구현하기 위해 적응적인 볼링거 밴드를 사용하여 트렌드 방향으로 과소 구매 및 과소 판매 기회를 식별합니다.

전략 논리

  1. 200주기 EMA와 30주기 EMA가 계산됩니다. 200주기 EMA가 30주기 EMA보다 크면 장기 트렌드는 상승으로 결정됩니다. 그렇지 않으면 하락으로 결정됩니다.

  2. 트렌드 방향이 결정된 후 볼린거 밴드의 기본선, 상단 및 하단 밴드가 계산된다. 기본선은 구성 가능한 시간 프레임 (예를 들어 8 기간) 에서 SMA를 채택한다. 밴드 너비는 기본선과 같은 기간 동안 가장 높고 가장 낮은 가격의 진폭의 구성 가능한 곱자 (예를 들어 1.3 및 1.1) 이다.

  3. 장기 트렌드가 상승할 때, 하위 밴드 브레이크오웃은 긴 진입을 신호하고, 장기 트렌드가 하락할 때, 상위 밴드 브레이크오웃은 짧은 진입을 신호합니다.

  4. 가짜 브레이크를 필터링하기 위해, 브레이크 이전 마지막 촛불의 변화율은 구성 가능한 임계치 (예를 들어 3%) 이하로 확인되고, 대역 폭은 구성 가능한 레벨 (예를 들어 폐쇄 가격의 2.2%) 보다 높게 확인됩니다.

  5. 포지션 개설 후, 설정 가능한 스톱 로스 (예를 들어 -3%) 및 영업 (예를 들어 10%) 는 수익을 차단하도록 설정됩니다.

전략 강점

  1. 이중 EMA는 주요 트렌드를 정의하고 주요 트렌드가 불분명할 때 무질서한 포지션을 개설하는 것을 피합니다.

  2. 적응적인 볼링거 대역은 트렌드를 따라 입구점을 설정합니다. 자동 너비 조정은 트렌드를 더 고정시킵니다.

  3. 변화 속도와 최소 너비 요구 사항은 거짓 파열을 효과적으로 필터합니다.

  4. 스톱 로즈와 수익 취득 설정은 위험을 통제하면서 수익을 합리적으로 차단합니다.

전략 위험

  1. 이중 EMA는 트렌드 전환점을 정확하게 찾아내지 못하고, 트렌드 전환점에 기회를 놓치고 있습니다.

  2. 부적절한 BB 파라미터 설정으로 인해 잘못된 신호가 발생할 수 있습니다.

  3. 고정된 스톱 로즈와 영업이익은 시장 변동에 적응할 수 없습니다.

최적화 방향

  1. 주요 및 부차적인 트렌드 전환을 결정하기 위해 다른 지표를 포함합니다.

  2. BB 매개 변수를 동적으로 조정합니다.

  3. 특정 기준에 기초하여 손해를 멈추고 이익을 취하기 위한 조건부 명령을 설정합니다.

결론

이 전략은 이중 EMA를 사용하여 주요 트렌드를 판단하고 볼링거 밴드를 사용하여 기회를 식별함으로써 트렌드 거래를 구현합니다. 그것의 강점은 트렌드 수익을 잠금하기 위해 합리적으로 엔트리, 스톱 로스 및 영업 조건을 설정하는 데 있습니다. 또한 트렌드 전환점과 부적절한 BB 매개 변수 설정을 잡지 못하는 것과 같은 몇 가지 위험이 있습니다. 이러한 측면에서의 추가 최적화는 트렌드 수익을 더 잘 잡을 수있는 전략을 강화 할 것입니다.


/*backtest
start: 2022-12-04 00:00:00
end: 2023-12-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//////////////////////////////////////////////////////////////////////
// Component Code Start
testStartYear = input(2019, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2039, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false
// Component Code Stop

strategy("Custom Band Strategy", overlay=true)
source = close //종가 기준

//추세 조건 설정
emaLong = ema(source, input(200, minval=0))
emaShort = ema(source, input(30, minval=0))
trend = if emaShort>=emaLong
    1
else
    -1
    
plot(emaLong, color=red, transp=0)
plot(emaShort, color=blue, transp=0)


//BB 계산(default 14/3.2)
length = input(8, minval=1)

basis = sma(source, length)
plot(basis, color=green, transp=0)
max=highest(abs(source-basis), length)

factor1 = input(1.3, minval=0.5)
factor2 = input(1.1, minval=0.5)

upper = if trend==1
    basis + max*factor1
else
    basis + max*factor2
lower = if trend==-1
    basis - max*factor1
else
    basis - max*factor2

plot1 = plot(upper)
plot2 = plot(lower)
fill(plot1, plot2, transp=80, color=green)

//밴드 이탈 후 재진입 조건 설정
cross_over = (low<=lower and close>=lower) or crossover(close,lower)
cross_under = (high>=upper and close<=upper) or crossunder(close,upper)

//변동율 계산
maxCandle=highest(abs(open-close), length)
    
roc = abs(open-close)/open*100
changerate = input(3, minval=0.0)

//수익률 계산
value = abs(strategy.position_size)*strategy.position_avg_price
roe = strategy.openprofit/value * 100
expRoeL = (upper-lower)/lower*100
expRoeS = (upper-lower)/upper*100
exp = input(2.2, minval=0.0)

target = input(10, minval=0.0)
stop = input(-3, minval=-10.0)

strategy.close_all(when=roc>=changerate and testPeriod())
strategy.close_all(when=roe>=target and testPeriod())
strategy.close_all(when=roe<=stop and testPeriod())

plotchar(crossover(close,lower) and crossunder(close,upper),color=blue, transp=0, text="cross")
plotchar(roc>=changerate,color=red, transp=0, text="roc")
plotchar(roe>=target,color=blue, transp=0, text="target")
plotchar(roe<=stop,color=green, transp=0, text="stop")

minroe = input(2, minval=0.0)

strategy.close_all(when=cross_under and roe>minroe and testPeriod())
strategy.entry("BBandLE", strategy.long, stop=source, oca_name="BollingerBands",  comment="BBandLE", when=(cross_over) and trend==1 and roc<changerate and expRoeL>exp and source>emaLong and strategy.position_size==0 and testPeriod()) //trend==1 and 
//else
strategy.close_all(when=cross_over and roe>minroe and testPeriod())
strategy.entry("BBandSE", strategy.short, stop=source, oca_name="BollingerBands",  comment="BBandSE", when=(cross_under) and trend==-1 and roc<changerate and expRoeS>exp and source<emaLong and strategy.position_size==0 and testPeriod()) //trend==-1 and 

더 많은