MACD와 Donchian 채널의 트렌드를 따르는 전략

저자:차오장, 날짜: 2023-11-15 11:37:37
태그:

img

전반적인 설명

이 전략은 트렌드를 결정하기 위해 돈치안 채널 지표와 MACD 지표를 결합합니다. 그것은 전형적인 트렌드 다음 전략에 속합니다. 가격이 상단 밴드를 깨고 MACD가 황금 십자가를 표시 할 때 길게 가고 가격이 하단 밴드를 깨고 MACD가 죽음의 십자가를 표시 할 때 짧게됩니다. ATR 지표는 스톱 손실을 계산하는 데 사용됩니다.

전략 논리

  1. 빠른 선, 느린 선 및 히스토그램을 포함한 MACD 지표를 계산합니다.

  2. 상부와 하부 돈치안 채널 대역을 계산합니다. 상부 대역은 N 일 동안 가장 높은 가격이고, 하부 대역은 N 일 동안 가장 낮은 가격입니다.

  3. 가격이 상단선을 넘어서고 MACD 빠른 라인이 느린 라인을 넘어서면,

  4. 가격이 하위 띠를 넘어서고 MACD 빠른 선이 느린 선 아래를 넘어가면

  5. 이 전략의 스톱 로스를 계산하기 위해 ATR 지표를 사용하십시오. 이 지수는 ATR 값과 현재 가격의 계수를 곱한 값으로 설정됩니다.

  6. 반전 신호가 나오면 위치를 닫아요

이점 분석

이 전략은 트렌드 판단 지표와 채널 지표를 결합하여 트렌드를 효과적으로 추적 할 수 있습니다. MACD 지표는 가격 추세와 동력을 판단합니다. 돈치안 채널은 방향을 판단합니다. ATR 스톱 로스는 거래 당 손실을 제한합니다.

이점:

  1. 전략은 간단하고 몇 가지 매개 변수만 있고 실행하기 쉽습니다.

  2. 트렌드를 따라 포지션을 개설하고, 트렌드 기회를 잡을 수 있습니다.

  3. ATR 스톱 손실은 위험을 통제합니다.

  4. 마감량은 어느 정도 조절할 수 있습니다.

위험 분석

또한 몇 가지 위험이 있습니다.

  1. 돈치안 채널의 부적절한 파라미터 설정은 잘못된 신호를 일으킬 수 있습니다.

  2. MACD 매개 변수 부적절한 경우 신호가 뒤떨어질 수도 있습니다.

  3. 너무 넓은 스톱 로스 설정은 확장 손실로 이어질 수 있습니다.

  4. 급격한 시장 변동은 엄청난 손실을 초래할 수 있습니다.

  5. 이 전략은 과잉 거래를 하는 경향이 있습니다.

해결책:

  1. 매개 변수를 최적화하고 주식을 신중하게 선택하세요.

  2. 엄격한 스톱 손실, 추후 스톱 손실.

  3. 위치 크기를 적절히 조정하세요.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 감수성을 높이기 위해 MACD 매개 변수를 최적화합니다.

  2. 스톱 로스 알고리즘을 최적화해서 가격에 가깝게 만들게

  3. 트렌드 강도에 따라 위치 사이즈 메커니즘을 추가합니다.

  4. 잘못된 신호를 피하기 위해 필터를 추가합니다.

  5. 거래용 상품의 선택 기준을 추가합니다.

  6. 거래 기간의 판단을 추가합니다.

요약

요약하자면, 이것은 전형적인 트렌드 다음 전략이다. 트렌드 방향을 나타내는 돈치안 채널과 트렌드 강도를 나타내는 MACD를 결합한다. 트렌드를 효과적으로 따라가며 위험을 제어할 수 있다. 매개 변수, 스톱 로스, 포지션 사이징 등을 최적화함으로써 안정성과 수익성이 더욱 향상될 수 있다. 이 전략은 트렌드 판단에 높은 정확성을 필요로 하는 투자자들에게 적합하다.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 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/
// © Robrecht99

//@version=5
strategy("Trend Following with Donchian Channels and MACD", overlay=false, margin_long=100, margin_short=100, pyramiding=3)

// MACD //
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])

col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")

fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
plot(macd, title="MACD", color=col_macd)
plot(signal, title="Signal", color=col_signal)

// Donchian Channels //

Length1 = input.int(title="Length Upper Channel", defval=50, minval=1, group="Donchian Channels Inputs")
Length2 = input.int(title="Length Lower Channel", defval=50, minval=1, group="Donchian Channels Inputs")
h1 = ta.highest(high[1], Length1)
l1 = ta.lowest(low[1], Length2)
fillColor = input.color(color.new(color.purple, 95), title = "Fill Color", group = "Donchian Channels Inputs")
upperColor = input.color(color.new(color.orange, 0), title = " Color Upper Channel", group = "Donchian Channels Inputs", inline = "upper")
lowerColor = input.color(color.new(color.orange, 0), title = " Color Lower Channel", group = "Donchian Channels Inputs", inline = "lower")
u = plot(h1, "Upper", color=upperColor)
l = plot(l1, "Lower", color=upperColor)
fill(u, l, color=fillColor)

//ATR and Position Size //
strategy.initial_capital = 50000
length = input.int(title="ATR Period", defval=14, minval=1, group="ATR Inputs")
risk = input(title="Risk Per Trade", defval=0.01, group="ATR Inputs")
multiplier = input(title="ATR Multiplier", defval=2, group="ATR Inputs")
atr = ta.atr(length)
amount = (risk * strategy.initial_capital / (multiplier * atr))

// Buy and Sell Conditions //

entrycondition1 = ta.crossover(macd, signal)
entrycondition2 = macd > signal
entrycondition3 = macd and signal > hist
sellcondition1 = ta.crossover(signal, macd)
sellcondition2 = signal > macd
sellcondition3 = macd and signal < hist

// Buy and Sell Signals //

if (close > h1 and entrycondition2 and entrycondition3)
    strategy.entry("long", strategy.long, qty=amount)
    stoploss = close - atr * 4
    strategy.exit("exit sl", stop=stoploss, trail_offset=stoploss)
if (sellcondition1 and sellcondition2 and sellcondition3)
    strategy.close(id="long")

if (close < l1 and sellcondition2 and sellcondition3)
    strategy.entry("short", strategy.short, qty=amount)
    stoploss = close + atr * 4
    strategy.exit("exit sl", stop=stoploss, trail_offset=stoploss)
if (entrycondition1 and entrycondition2 and entrycondition3)
    strategy.close(id="short")

더 많은