動向平均値とMACDに基づく戦略をフォローする傾向

作者: リン・ハーンチャオチャン, 日付: 2023年11月15日 15:58:19
タグ:

img

概要

この戦略は,動向平均値とMACD指標を組み合わせ,トレンドを決定し,取引信号を生成する.これは典型的なトレンドフォロー戦略に属している.トレンド方向を決定するために異なるタイムフレームの2つのZLSMA動向平均値と,特定の購入・販売信号を生成するためにMACDクロスオーバーを使用する.これは,短期市場の騒音に誤導されない間に,中長期のトレンドを効果的に把握することを可能にする.

戦略の論理

戦略は以下の主要要素で構成されています.

  1. Fast ZLSMAとSlow ZLSMA:異なるタイムフレームのZLSMA移動平均を比較すると,全体的なトレンド方向が決定される.速い線は32期ZLSMAから構成され,遅い線は400期ZLSMAから構成される.速い線がスローラインを超えると,それは上昇信号であり,その逆である.

  2. MACD指標:MACDは,スローライン (26期EMA) をファストライン (12期EMA) から減算して計算される.シグナルラインはMACDの9期EMAである.MACDがシグナルラインの上を横切ると購入信号であり,MACDがシグナルライン下を横切ると販売信号である.

  3. トレーディング・シグナル:ZLSMAのトレンド方向がMACDクロスオーバー信号と一致するときにのみ購入・売却・シグナルが生成される.特に,マックドのゴールデン・クロスと一致するときにブル・トレンドがロングになり,マックドのデッド・クロスと一致するときにベア・トレンドがショートされる.

  4. ストップ・ロスト・アンド・テイク・プロフィート: 戦略には現在,ストップ・ロスト・アンド・テイク・プロフィートの論理が含まれていないため,さらなる最適化が必要である.

主なトレンドとMACDを組み合わせてエントリーをタイミングで決定することで,誤ったブレイクを効果的にフィルタリングし,短期的な市場騒音に惑わされないことができます.

利点分析

この戦略の主な利点は以下の通りです.

  1. トレンドを把握する: トレンドの方向性を決定するために異なる時間枠の移動平均を使用することで,トレンドと取引し,中長期のトレンドを効果的に把握することができます.

  2. 雑音をフィルタリングする: MACD インディケーターの適用は,短期的な市場の雑音をフィルタリングし,小さな範囲の市場によって誤導されないようにします.

  3. カスタマイズ可能なパラメータ:移動平均期とMACDパラメータはカスタマイズ可能で,異なる市場のために最適化できます.

  4. 実行が簡単:使用されたすべての指標は共通の技術指標です.戦略の論理は単純で明確で,理解し実行するのが簡単です.

  5. 制御可能なリスク: 明確なストップ・ロストとテイク・プロフィットがあれば,各取引のリスクと報酬は制御できます.

リスク分析

この戦略の主なリスクは,

  1. 誤ったトレンド決定: 主なトレンドが誤って決定された場合,すべての取引は損失をもたらす可能性があります.

  2. パラメータの最適化が不適切である:移動平均値とMACDパラメータは徹底的にテストされ最適化されなければなりません.そうでなければ結果は不満足かもしれません.

  3. ストップ・ロスの欠如:現在,ストップ・ロスは存在しないため,過剰な損失のリスクがあります.

  4. 利益の可能性が限られている: 傾向を追求する戦略として,各取引の利益の可能性は限られており,収益性を高めるために高額が必要である.

  5. 取引頻度が高い: パラメータの調整が正しくない場合,取引頻度が過剰になり,取引コストやスライプが増加する可能性があります.

オプティマイゼーションの方向性

この戦略は,次の側面においてさらに最適化することができる.

  1. ストップ・ロスのメカニズムを追加します. 適切なストップ・ロスのポイントを設定して,取引毎の最大損失を厳格に制御します.

  2. パラメータを最適化: バックテストして最適移動平均値とMACDパラメータの組み合わせを見つけるために最適化します.

  3. 低取引頻度: 傾向が顕著であるときにのみ取引信号が生成されることを確保するためにパラメータを調整します.

  4. 他の要因を組み込む: 傾向やシグナルを確認するために,ボリュームの変化のような要因を追加することができます.

  5. 入力タイミングを向上させる: 入力精度を高めるためにMACDの使用をさらに強化する.

  6. 汎用化: 戦略をさまざまな製品に広く適用できるようにパラメータを最適化し,適用性を拡大します.

結論

結論として,この戦略は,移動平均値とMACDのシンプルで効果的な組み合わせを通じて,中期から長期間の傾向を効果的に捉え,それを堅牢な定量的な取引戦略の基盤にします.しかし,パラメータはさらなる最適化が必要であり,リスクはより良い制御を必要とし,より一貫した結果を達成するために他の要因を組み込む必要があります.これは実用的な価値があり,改善の余地があります.


/*backtest
start: 2023-11-07 00:00:00
end: 2023-11-10 05:00:00
period: 1m
basePeriod: 1m
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/
// © veryfid

//@version=5
strategy("Stratégie ZLSMA Bruno", shorttitle="Stratégie ZLSMA Bruno", overlay=false)

source = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
sh = input(true, title="Show Histogram?")
macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
hist_colorChange = input(true,title="MacD Histogram 4 Colors?")

//res = useCurrentRes ? period : resCustom

fastLength = input(12), 
slowLength=input(26)
signalLength=input(9)

fastMA = ta.ema(source, fastLength)
slowMA = ta.ema(source, slowLength)

macd = fastMA - slowMA
signal = ta.sma(macd, signalLength)
hist = macd - signal

outMacD =  macd
outSignal = signal
outHist =  hist

histA_IsUp = outHist > outHist[1] and outHist > 0
histA_IsDown = outHist < outHist[1] and outHist > 0
histB_IsDown = outHist < outHist[1] and outHist <= 0
histB_IsUp = outHist > outHist[1] and outHist <= 0

//MacD Color Definitions
macd_IsAbove = outMacD >= outSignal
macd_IsBelow = outMacD < outSignal

//plot_color = hist_colorChange ? histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon :yellow :gray
macd_color = macd_colorChange ? macd_IsAbove ? color.lime : color.red : color.red
//signal_color = macd_colorChange ? macd_IsAbove ? yellow : yellow : lime

circleYPosition = outSignal
 
//plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
//plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=line ,linewidth=2)
//plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=histogram, linewidth=4)
plot(sd and ta.cross(outMacD, outSignal) ? circleYPosition : na, title="Cross", style=plot.style_circles, linewidth=4, color=macd_color)
hline(0, '0 Line', linestyle=hline.style_solid, linewidth=2, color=color.white)

// Paramètres de la ZLSMA
length = input(32, title="Longueur")
offset = input(0, title="Décalage")
src = input(close, title="Source")
lsma = ta.linreg(src, length, offset)
lsma2 = ta.linreg(lsma, length, offset)
eq = lsma - lsma2
zlsma = lsma + eq

length_slow = input(400, title="Longueur")
offset_slow = input(0, title="Décalage")
lsma_slow = ta.linreg(src, length_slow, offset_slow)
lsma2_slow = ta.linreg(lsma_slow, length_slow, offset_slow)
eq_slow = lsma_slow - lsma2_slow
zlsma_slow = lsma_slow + eq_slow

// Paramètres de la sensibilité
sensitivity = input(0.5, title="Sensibilité")

// Règles de trading
longCondition = zlsma < zlsma_slow and  zlsma_slow < zlsma_slow[1] and zlsma > zlsma[1] and ta.cross(outMacD, outSignal) and  macd_color == color.lime//ta.crossover(zlsma, close) and ta.crossover(zlsma, zlsma[1]) // Croisement vers le haut
shortCondition = zlsma > zlsma_slow and  zlsma_slow > zlsma_slow[1] and zlsma < zlsma[1] and ta.cross(outMacD, outSignal) and  macd_color == color.lime   //ta.crossunder(zlsma, close) and ta.crossunder(zlsma, zlsma[1]) // Croisement vers le bas

// Entrée en position
strategy.entry("Achat", strategy.long, when=longCondition)
strategy.entry("Vente", strategy.short, when=shortCondition)
botifySignalZLSMA = longCondition ? 1 : shortCondition ? -1 : 0
plot(botifySignalZLSMA, title='Botify_signal', display=display.none)
// Sortie de position
strategy.close("Achat", when=ta.crossunder(zlsma, close)) // Close the "Achat" position
strategy.close("Vente", when=ta.crossover(zlsma, close)) // Close the "Vente" position


// Tracé de la courbe ZLSMA
plot(zlsma, color=color.yellow, linewidth=3)
plot(zlsma_slow, color=color.red, linewidth=3)



もっと