Donchian 채널 추세 추종 전략


생성 날짜: 2024-01-22 12:30:05 마지막으로 수정됨: 2024-01-22 12:30:05
복사: 0 클릭수: 645
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

Donchian 채널 추세 추종 전략

개요

돈치안 채널 트렌드 추적 전략은 돈치안 채널 지표에 기반한 트렌드 추적 전략이다. 이는 가격 트렌드를 식별하기 위해 다양한 길이의 돈치안 채널을 사용하며, 가격이 채널을 뚫을 때 거래 신호를 발생시킨다.

이 전략의 주요 아이디어는 긴 주기의 Donchian 통로를 사용하여 큰 트렌드 방향을 판단하고, 짧은 주기의 Donchian 통로를 입점 및 중단 신호로 사용하는 것입니다. 그것은 시장의 단기 변동에 의해 미혹되지 않도록 중·장선 가격 트렌드를 포착하기 위해 고안되었습니다.

전략 원칙

  1. 긴 주기 (예: 50일) 의 최고 종결 가격과 최저 종결 가격을 계산하여 Donchian 채널을 구성한다. 가격이 채널을 돌파할 때 상향을 보고, 하향을 돌파할 때 하향을 보고 있다. 이것은 큰 흐름을 판단하는 기초이다.

  2. 짧은 기간 (예: 20일) 의 최대의 종결 가격과 최저 종결값을 입점과 중단의 기준으로 계산한다. 가격이 긴 경로를 돌파할 때, 종결 가격도 짧은 경로를 돌파할 경우, 입장은 더/무료이다.

  3. 다단계 포지션을 보유할 때, 가격이 짧은 라인 아래로 떨어지면 상쇄된다. 공백 포지션을 보유할 때, 가격이 짧은 라인 상쇄를 깨면 상쇄된다.

  4. 스톱로스는 N배 ATR로 설정된다. 이것은 시장의 변동성에 따라 자동으로 조정될 수 있으며, 스톱로스가 활성화될 가능성을 줄이는 데 도움이 된다.

  5. 거래가 끝날 때까지 지분을 청산하거나, 손실이 끝날 때까지 지분을 유지 할 수 있습니다. 이것은 입력 파라미터를 통해 제어 할 수 있습니다.

이 전략은 트렌드 판단과 수익 손실을 동시에 고려하여 가격 트렌드를 포착하고 위험을 제어 할 수 있으며 중장선 운영에 적합합니다.

우위 분석

  1. 중장기 트렌드를 효과적으로 식별하고, 단기 시장의 소음으로 방해받지 않도록하십시오.

  2. 자동 손실 제도는 단독 손실을 제한할 수 있습니다.

  3. ATR 상쇄는 시장의 변동성에 따라 상쇄 거리를 조정하여 상쇄가 충격을 받을 가능성을 줄일 수 있습니다.

  4. 거래할 수 없는 경우 자동으로 청산하여 거래 위험을 관리할 수 있습니다.

  5. 전략적 논리는 간단하고 명확하며 이해하기 쉽다.

위험 분석

  1. 명확한 추세가 없는 시장에서 전략은 더 많은 거래를 만들어 내는데, 이는 거래 비용을 증가시키고 손실을 달성할 가능성을 높여준다.

  2. 스톱로스 메커니즘이 있지만, 특이한 상황에서는 가격 이 스톱로스를 넘어서는 것이 큰 손실을 초래할 수 있습니다.

  3. ATR 계산은 단지 역사적인 데이터에 기초하여 미래의 흐름과 변동성을 정확하게 예측할 수 없으며 실제 스톱드라이스 거리는 너무 크거나 너무 작을 수 있다.

  4. 실물에서는 100%의 실행을 보장할 수 없습니다. 극단적인 경우 손실을 초래할 수 있습니다.

최적화 방향

  1. Donchian 통로 파라미터를 조정하여 트렌드 식별 효과를 최적화하십시오.

  2. 다른 지표와 결합하여 MACD, KDJ와 같은 거래 신호를 확인하여 전략의 안정성을 향상시킵니다.

  3. 이동 스톱을 증가시켜 스톱 포인트가 가격과 함께 이동하게 하고, 손실을 더욱 제한한다.

  4. 포지션 보유 기간이 전체 효과에 미치는 영향을 테스트하여 최적의 포지션 보유 기간을 결정합니다.

  5. 동적으로 포지션 규모를 조정하고, 트렌드 상황에서 포지션을 늘리는 것을 고려한다.

요약하다

Donchian channel 트렌드 추적 전략은 트렌드 판단과 위험 관리를 통합하여 트렌드 식별을 통해 excess return를 얻고, 동시에 스톱 패스 메커니즘은 꼬리 위험을 제어한다. 이 전략은 중장선 가격 트렌드를 식별하고 포착하는 데 적합하며, 매개 변수 최적화 및 메커니즘 보완 후 안정적인 긍정적 수익을 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title="Donchian", overlay=true, calc_on_every_tick=true)

// =============================================================================
// VARIABLES
// =============================================================================

donch_string = input.string(title="Lenght", options = ['20/10','50/20', '50/50', '20/20', '100/100'], defval='20/10')
permit_long  = input.bool(title = 'Permit long', defval = true)
permit_short  = input.bool(title = 'Permit short', defval = true)
risk_percent = input.float(title="Position Risk %", defval=0.5, step=0.25)
stopOffset = input.float(title="ATR mult", defval=2.0, step=0.5)
atrLen = input.int(title="ATR Length", defval=20)
close_in_end  = input.bool(title = 'Close in end', defval = true)
permit_stop  = input.bool(title = 'Permit stop', defval = true)


// =============================================================================
// CALCULATIONS
// =============================================================================

donch_len_big = 
 donch_string == '50/20' ? 50 : 
 donch_string == '50/50' ? 50 : 
 donch_string == '20/20' ? 20 : 
 donch_string == '20/10' ? 20 : 
 donch_string == '100/100' ? 100 : 
 na
donch_len_small = 
 donch_string == '50/20' ? 20 : 
 donch_string == '50/50' ? 50 : 
 donch_string == '20/20' ? 20 : 
 donch_string == '20/10' ? 10 : 
 donch_string == '100/100' ? 100 : 
 na

big_maxclose = ta.highest(close, donch_len_big)
big_minclose = ta.lowest(close, donch_len_big)

small_maxclose = ta.highest(close, donch_len_small)
small_minclose = ta.lowest(close, donch_len_small)

atrValue = ta.atr(atrLen)[1]

tradeWindow  = true

// =============================================================================
// NOTOPEN QTY
// =============================================================================

risk_usd     = (risk_percent / 100) * strategy.equity
atr_currency = (atrValue * syminfo.pointvalue)
notopen_qty  = risk_usd / (stopOffset * atr_currency)

// =============================================================================
// LONG STOP
// =============================================================================

long_stop_price = 0.0
long_stop_price := 
 strategy.position_size > 0 and na(long_stop_price[1]) ? strategy.position_avg_price - stopOffset * atrValue : 
 strategy.position_size > 0 and strategy.openprofit > risk_usd ? strategy.position_avg_price:
 strategy.position_size > 0 ? long_stop_price[1] : 
 na

// =============================================================================
// SHORT STOP
// =============================================================================

short_stop_price = 0.0
short_stop_price := 
 strategy.position_size < 0 and na(short_stop_price[1]) ? strategy.position_avg_price + stopOffset * atrValue : 
 strategy.position_size < 0 and strategy.openprofit > risk_usd ? strategy.position_avg_price :
 strategy.position_size < 0 ? short_stop_price[1] : 
 na

// =============================================================================
// PLOT BG VERTICAL COLOR
// =============================================================================

cross_up = strategy.position_size <= 0 and close == big_maxclose and close >= syminfo.mintick and tradeWindow and permit_long
cross_dn =  strategy.position_size >= 0 and close == big_minclose and close >= syminfo.mintick and tradeWindow and permit_short
bg_color = cross_up ? color.green : cross_dn ? color.red : na
bg_color := color.new(bg_color, 70)
bgcolor(bg_color)

// =============================================================================
// PLOT HORIZONTAL LINES
// =============================================================================

s1 = cross_up ? na : cross_dn ? na : strategy.position_size != 0 ? strategy.position_avg_price : na
s2 = cross_up ? na : cross_dn ? na : strategy.position_size > 0 ? small_minclose : strategy.position_size < 0 ? small_maxclose : na
s3 = cross_up ? na : cross_dn ? na : not permit_stop ? na : 
 strategy.position_size > 0 ? long_stop_price : strategy.position_size < 0 ? short_stop_price : na

plot(series=big_maxclose, style=plot.style_linebr, color=color.black, linewidth=1, title="Donch Big Maxclose Black")
plot(series=big_minclose, style=plot.style_linebr, color=color.black, linewidth=1, title="Donch Big Minclose Black")

plot(series=s1, style=plot.style_linebr, color=color.yellow, linewidth=2, title="Entry Yellow")
plot(series=s2, style=plot.style_linebr, color=color.red, linewidth=1, title="Donch Small Red")
plot(series=s3, style=plot.style_linebr, color=color.fuchsia, linewidth=2, title="Stop Fuchsia")

// =============================================================================
// ENTRY ORDERS
// =============================================================================

if strategy.position_size <= 0 and close == big_maxclose and close >= syminfo.mintick and tradeWindow and permit_long
    strategy.entry("Long", strategy.long, qty=notopen_qty)

if (strategy.position_size >= 0) and close == big_minclose and close >= syminfo.mintick and tradeWindow and permit_short
    strategy.entry("Short", strategy.short, qty=notopen_qty)

// =============================================================================
// EXIT ORDERS
// =============================================================================

if strategy.position_size > 0 and permit_stop
    strategy.exit(id="Stop", from_entry="Long", stop=long_stop_price)

if strategy.position_size < 0 and permit_stop
    strategy.exit(id="Stop", from_entry="Short", stop=short_stop_price)

// ==========

if strategy.position_size > 0 and close == small_minclose and not barstate.islast
    strategy.close(id="Long", comment='Donch')

if strategy.position_size < 0 and close == small_maxclose and not barstate.islast
    strategy.close(id="Short", comment='Donch')

// ==========

if close_in_end
    if not tradeWindow
        strategy.close_all(comment='In end')

// =============================================================================
// END
// =============================================================================