전략에 따른 돈치안 트렌드

저자:차오장, 날짜: 2024-01-31 16:53:31
태그:

img

전반적인 설명

돈치안 트렌드 다음 전략은 기사에서 설명 된 돈치안 채널 원리에 기초하여 개발되었습니다. 이 전략은 트렌드 방향을 결정하기 위해 돈치안 채널을 사용하여 가격이 새로운 최고 또는 최저에 도달 할 때 긴 또는 짧은 포지션을 설정합니다.

전략 논리

이 전략은 트렌드 방향을 판단하기 위해 돈치안 채널 지표에 기반합니다. 돈치안 채널은 더 긴 기간 채널과 더 짧은 기간 채널으로 구성됩니다. 가격이 더 긴 기간 채널을 통과하면 트렌드의 시작을 신호합니다. 가격이 더 짧은 기간 채널을 통과하면 트렌드의 끝을 신호합니다.

특히, 더 긴 기간 채널 길이는 50일 또는 20일이고, 더 짧은 기간 채널 길이는 50일, 20일 또는 10일이다. 가격이 50일 만에 가장 높은 가격에 해당되는 경우, 긴 포지션을 개척한다. 가격이 50일 만에 가장 낮은 가격에 해당되는 경우, 짧은 포지션을 개척한다. 가격이 20일 또는 10일 만에 가장 낮은 가격에 해당되는 경우, 긴 포지션을 폐쇄한다. 가격이 20일 또는 10일 만에 가장 높은 가격에 해당되는 경우, 짧은 포지션을 폐쇄한다.

서로 다른 기간의 두 개의 돈치안 채널을 결합함으로써 트렌드가 시작될 때 지위를 설정하는 방향을 결정할 수 있으며 트렌드가 끝날 때 적절한 스톱 손실을 실현할 수 있습니다.

이점 분석

이 전략의 주요 장점은 다음과 같습니다.

  1. 트렌드를 포착 할 수있는 강력한 능력. 그것은 Donchian 채널 브레이크를 사용하여 트렌드의 시작과 끝을 식별하여 트렌드를 효과적으로 추적 할 수 있습니다.

  2. 적절한 리스크 제어. 단일 거래 손실을 제어하기 위해 이동 스톱 손실을 사용합니다.

  3. 유연한 매개 변수 조정 채널 기간 조합은 다른 제품과 시장 환경에 적응하도록 자유롭게 선택할 수 있습니다.

  4. 간단하고 명확한 거래 논리. 이해하기 쉽고 구현하기 쉽습니다.

위험 분석

이 전략의 위험은 다음과 같습니다.

  1. 범위에 묶인 시장에 적응 할 수 없습니다. 추세가 불분명하면 연속적으로 작은 스톱 손실을 겪을 것입니다.

  2. 파업 실패 위험. 채널을 넘어서면 가격이 하락할 수 있어 스톱 로스를 유발할 수 있습니다.

  3. 기간 선택 위험: 부적절한 채널 기간 설정은 노이즈 거래로 이어질 수 있습니다.

  4. 샤프 비율 감소 위험: 스톱 로스를 조정하지 않고 포지션 크기를 늘리는 것은 샤프 비율 감소로 이어질 수 있습니다.

해결책은 다음과 같습니다.

  1. 적절한 채널 기간 조합을 선택하기 위해 매개 변수를 최적화합니다.
  2. 리스크를 조절하기 위해 포지션 크기와 스톱 로스를 적절히 조정합니다.
  3. 이 전략을 명백한 트렌드를 가진 제품과 시장에 사용하십시오.

최적화 방향

이 전략의 최적화 방향:

  1. 필터 조건을 추가하여 윙사브를 피합니다. 예를 들어 진정한 브레이크를 판단하기 위해 볼륨을 결합합니다.

  2. 이윤 비율을 높이기 위해 채널 기간 조합과 위치 사이징을 최적화합니다. 적응 스톱 손실이 도입 될 수 있습니다.

  3. 최적의 매개 변수 집합을 찾기 위해 브레이크포인트 최적화를 시도하고 있습니다.

  4. 동적 최적화 및 매개 변수 조정을 위한 기계 학습 알고리즘을 늘려나가고 있습니다.

결론

돈치안 트렌드 다음 전략은 이중 채널을 사용하여 가격 트렌드의 시작과 끝을 식별하고 효과적인 단일 거래 손실 제어와 함께 트렌드 다음 트레이딩 스타일을 채택합니다. 이 전략은 유연한 매개 변수 조정 및 쉬운 구현을 가지고 있으며, 자신을 매우 실용적인 트렌드 다음 전략으로 만듭니다. 그러나 범위 제한 시장에서 수익성이 부족하고 매개 변수 선택의 위험이 주목되어야합니다. 추가 최적화는 더 나은 전략 성능으로 이어질 수 있습니다.


/*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,
     pyramiding=0, initial_capital=1000,
     commission_type=strategy.commission.cash_per_order,
     commission_value=2, slippage=2)

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

donch_string = input.string(title="Length", options = ['20/10','50/20', '50/50', '20/20', '100/100'], defval='50/50')
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 = false)

// =============================================================================
// 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 VERTICAL COLOR BAR
// =============================================================================

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 DONCHIAN 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='Close in end')

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

더 많은