MACDクロスオーバー戦略

EMA MA
作成日: 2024-04-18 17:56:23 最終変更日: 2024-04-18 17:56:23
コピー: 0 クリック数: 716
1
フォロー
1617
フォロワー

MACDクロスオーバー戦略

概要

この戦略は,2つの異なる周期の指数移動平均 ((EMA) を交差して,速いEMAが下から上へゆっくりとしたEMAを横切るときに買いの信号を生じ,速いEMAが上から下へゆっくりとしたEMAを横切るときに売る信号を生じます.この戦略は,様々な金融機関と時間周期に適用できます.例えば,ゴールドは2時間周期で最も有効で,ビットコインは日線図で最も有効です.

戦略原則

  1. 計算速度の EMA ((デフォルト周期は12) と遅い EMA ((デフォルト周期は26)) を計算する.
  2. 多頭部地域 ((急速EMAは遅いEMAの上にあり,価格は急速EMAの上にあり) と空頭部地域 ((急速EMAは遅いEMAの下にあり,価格は急速EMAの下にあり) を定義する.
  3. 空頭領域から多頭領域に変換するときに購入し,多頭領域から空頭領域に変換するときに販売する.
  4. 多頭部と空頭部を緑と赤で示し,矢印で買付信号を表示する.

戦略的優位性

  1. シンプルで分かりやすい,初心者向け.
  2. 様々な金融機関や時間帯に適用可能である.
  3. 傾向を追跡する能力があり,中長期のトレンドを捉えることができます.
  4. パラメータは調整可能で,柔軟性を増す.

戦略リスク

  1. 市場が揺れ動いていると,誤った信号が発生し,損失を招きます.
  2. トレンドが逆転すると,反応が遅いので,滑り場が生じます.
  3. パラメータの選択が間違えば,戦略の効果に影響する.

戦略最適化の方向性

  1. トレンドフィルター (ADXが特定の値より大きいときにのみ取引するなど) を加え,波動市場での損失を減らす.
  2. ATRで,ストップダメージを決定し,単発損失を減らすなど,出場時間を最適化します.
  3. パラメータを最適化し,最適なパラメータの組み合わせを見つけ,安定性と収益性を向上させる.
  4. MACD,RSIなどの他の指標の補助判断と組み合わせると,信号の精度が向上する.

要約する

MACD交差策略は,トレンド追跡に基づく簡単な策略である.その優点は,シンプルで実用的で適用範囲が広いことであり,デメリットとしては,トレンド転換を把握することが困難であり,パラメータの選択が困難である.トレンドフィルタリング,入場場場の最適化,パラメータの選択,および他の指標の組み合わせにより,この戦略のパフォーマンスを改善することができる.この戦略は,さらなる研究とテストに値する.

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

//@version=5
strategy('Advance EMA Crossover Strategy', overlay=true, precision=6)
//****************************************************************************//
// CDC Action Zone is based on a simple EMA crossover 
// between [default] EMA12 and EMA26
// The zones are defined by the relative position of 
// price in relation to the two EMA lines
// Different zones can be use to activate / deactivate 
// other trading strategies
// The strategy can also be used on its own with 
// acceptable results, buy on the first green candle
// and sell on the first red candle
//****************************************************************************//
// Define User Input Variables

xsrc = input(title='Source Data', defval=close)
xprd1 = input(title='Fast EMA period', defval=12)
xprd2 = input(title='Slow EMA period', defval=26)
xsmooth = input(title='Smoothing period (1 = no smoothing)', defval=1)
fillSW = input(title='Paint Bar Colors', defval=true)
fastSW = input(title='Show fast moving average line', defval=true)
slowSW = input(title='Show slow moving average line', defval=true)
plotSigsw = input(title='Plot Buy/Sell Signals?', defval=true)

//****************************************************************************//
//Calculate Indicators

xPrice = ta.ema(xsrc, xsmooth)

FastMA = ta.ema(xPrice, xprd1)
SlowMA = ta.ema(xPrice, xprd2)

//****************************************************************************//
// Define Color Zones and Conditions

BullZone = FastMA > SlowMA and xPrice > FastMA  // Bullish Zone
BearZone = FastMA < SlowMA and xPrice < FastMA  // Bearish Zone

//****************************************************************************//
// Strategy Entry and Exit Conditions

if (BullZone and not BullZone[1])
    strategy.entry("Buy", strategy.long)  // Buy on the transition into BullZone

if (BearZone and not BearZone[1])
    strategy.close("Buy")  // Sell on the transition into BearZone

//****************************************************************************//
// Display color on chart

plotcolor = BullZone ? color.green : BearZone ? color.red : color.gray
barcolor(color=fillSW ? plotcolor : na)

//****************************************************************************//
// Plot Fast and Slow Moving Averages

plot(fastSW ? FastMA : na, color=color.red, title="Fast EMA", linewidth=2)
plot(slowSW ? SlowMA : na, color=color.blue, title="Slow EMA", linewidth=2)

//****************************************************************************//
// Plot Buy and Sell Signals

plotshape(series=plotSigsw and BullZone and not BullZone[1], location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=plotSigsw and BearZone and not BearZone[1], location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")

//****************************************************************************//