移動平均に基づくMACD動的トレンド判断戦略


作成日: 2024-02-19 10:48:11 最終変更日: 2024-02-19 10:48:11
コピー: 0 クリック数: 359
1
フォロー
1219
フォロワー

移動平均に基づくMACD動的トレンド判断戦略

概要

この戦略は,MACD指標の均線組合せに基づいて,時間周期を越えた動的傾向判断を実現し,より古典的なトレンド追跡戦略に属している.主に,急激な平均線の差値MACDとその信号線の関係によって,現在のトレンドの方向と強さを判断する.同時に,正確性を向上させるために,動的にポジションを調整する跨周期判断を導入する.

戦略原則

  1. MACD指標の速慢平均線差値とその信号線関係に基づいて現在のトレンド方向を判断する
  2. MACD差値上は信号線を多信号として穿え,下は空白信号として穿え
  3. MACD差値とMACD柱状線を導入し,戦略信号として同方向強化
  4. 超周期判断モジュールを追加し,信号波とポジション調節の基礎としてより高い時間周期MACD指標を取り込む
  5. ポジションの動的調整,跨周期信号が弱くるとポジションのサイズを小さくし,信号が強くなるとポジションを大きくする

優位分析

  1. MACD指数自体はトレンドの方向を判断する上で有効です.
  2. 組み合わせたMACD差値と柱状線の二重検証により,信号の精度が向上する
  3. 周期間判断は,高周波信号に誤導されないように戦略の安定性を高めます.
  4. ダイナミックなポジション調整により,戦略がチャンスをよりうまく捉え,余剰収益を上げる

リスク分析と解決策

  1. MACDの信号が遅れており,信号の効果が低下する可能性があります.
  • 解決方法: 信号を早期に捉えるために,高速平均線と遅速平均線の差値判断を加える
  1. 周期を越えた信号は必ずしも正確ではなく,戦略を誤導する可能性がある.
  • 解決策: ポジションのダイナミック調整メカニズムを導入し,主周期戦略を主導する
  1. 多要素組み合わせ戦略の全体的な安定性は不足している可能性がある
  • 解決策:戦略のパラメータを慎重に調整し,全体的な健全性を確保する

最適化の方向

  1. 異なる周期パラメータの組み合わせの効果をテスト
  2. 戦略の効果に対するさまざまな周期間の組み合わせの影響をテストする
  3. MACD指標のパラメータを調整する.例えば,速慢平均線周期,信号線周期など
  4. 異なるポジションの調節因子の効果をテストする
  5. 他の品種でテストした結果

要約する

このMACD平均線は,クロスサイクルダイナミックなトレンド戦略を組み合わせて,クラシック指標判断と多時間枠参照の優位性を統合している.パラメータ最適化と組み合わせテストにより,より安定した,収益の良いトレンド追跡戦略を構築することができる.実地テストと投入適用に値する.

ストラテジーソースコード
/*backtest
start: 2023-02-12 00:00:00
end: 2024-02-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@temelbulut
//@version=5
strategy('MACD Strategy %80', overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=50)

fastLength = input.int(title='MACD Fast Length', defval=12, minval=1)
slowLength = input.int(title='MACD Slow Length', defval=26, minval=1)
signalLength = input.int(title='MACD Signal Length', defval=9, minval=1)
crossscore = input(title='Cross (buy/sell) Score', defval=10.)
indiside = input(title='indicator Direction Score', defval=8)
histside = input(title='Histogram Direction Score', defval=2)
shotsl = input(title='Show Stop Loss Line', defval=false)
Mult = input.float(title='Stop Loss Factor', defval=1.2, minval=0.1, maxval=100)
Period = input.int(title='Stop Loss Period', defval=10, minval=1, maxval=100)
lookaheadi = input(title='Lookahead', defval=true)

HTF = timeframe.period == '1' ? '5' : timeframe.period == '3' ? '15' : timeframe.period == '5' ? '15' : timeframe.period == '15' ? '60' : timeframe.period == '30' ? '60' : timeframe.period == '45' ? '60' : timeframe.period == '60' ? '240' : timeframe.period == '120' ? '240' : timeframe.period == '180' ? '240' : timeframe.period == '240' ? 'D' : timeframe.period == 'D' ? 'W' : 'W'

calc = timeframe.period == '1' ? 5 : timeframe.period == '3' ? 5 : timeframe.period == '5' ? 3 : timeframe.period == '15' ? 4 : timeframe.period == '30' ? 4 : timeframe.period == '45' ? 4 : timeframe.period == '60' ? 4 : timeframe.period == '120' ? 3 : timeframe.period == '180' ? 3 : timeframe.period == '240' ? 6 : timeframe.period == 'D' ? 5 : 1

count() =>
    indi = ta.ema(close, fastLength) - ta.ema(close, slowLength)
    signal = ta.ema(indi, signalLength)
    Anlyse = 0.0
    // direction of indi and histogram
    hist = indi - signal
    Anlyse := indi > indi[1] ? hist > hist[1] ? indiside + histside : hist == hist[1] ? indiside : indiside - histside : 0
    Anlyse += (indi < indi[1] ? hist < hist[1] ? -(indiside + histside) : hist == hist[1] ? -indiside : -(indiside - histside) : 0)
    Anlyse += (indi == indi[1] ? hist > hist[1] ? histside : hist < hist[1] ? -histside : 0 : 0)
    // cross now earlier ?
    countcross = indi >= signal and indi[1] < signal[1] ? crossscore : indi <= signal and indi[1] > signal[1] ? -crossscore : 0.
    countcross += nz(countcross[1]) * 0.6
    Anlyse += countcross
    nz(Anlyse)

Anlys = count()
AnlysHfrm = lookaheadi ? request.security(syminfo.tickerid, HTF, count(), lookahead=barmerge.lookahead_on) : request.security(syminfo.tickerid, HTF, count(), lookahead=barmerge.lookahead_off)
Result = (AnlysHfrm * calc + Anlys) / (calc + 1)

longCondition = ta.change(Result) != 0 and Result > 0
if longCondition
    strategy.entry('MACD Long', strategy.long,alert_message = 'MACD Long')

shortCondition = ta.change(Result) != 0 and Result < 0
if shortCondition
    strategy.entry('MACD Short', strategy.short,alert_message = 'MACD Short')

countstop(pos) =>
    Upt = hl2 - Mult * ta.atr(Period)
    Dnt = hl2 + Mult * ta.atr(Period)
    TUp = 0.
    TDown = 0.
    TUp := close[1] > TUp[1] ? math.max(Upt, TUp[1]) : Upt
    TDown := close[1] < TDown[1] ? math.min(Dnt, TDown[1]) : Dnt
    tslmtf = pos == 1 ? TUp : TDown
    tslmtf

pos = longCondition ? 1 : -1
stline = 0.
countstop__1 = countstop(pos)
security_1 = request.security(syminfo.tickerid, HTF, countstop__1)
stline := ta.change(time(HTF)) != 0 or longCondition or shortCondition ? security_1 : nz(stline[1])
plot(stline, color=shotsl ? color.rgb(148, 169, 18) : na, style=plot.style_line, linewidth=2, title='Stop Loss')