トレンドフォロー戦略 MACD と ドンチアンチャネル

作者: リン・ハーンチャオチャン,日付: 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. 取引時間の判断を追加します.

概要

概要すると,これは典型的なトレンドフォロー戦略である.トレンド指向をDonchian Channelとトレンド強さを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")

もっと