MACDオシレーターとEMAクロスオーバー戦略


作成日: 2023-09-23 15:24:12 最終変更日: 2023-09-23 15:24:12
コピー: 0 クリック数: 746
1
フォロー
1617
フォロワー

概要

この戦略は,振動指数MACDと移動平均EMAを組み合わせたシンプルで効率的な取引戦略である.現在は4時間K線で設定されており,必要に応じて他の時間周期に調整できます.これは,ビットコインとイーサノイムの過去3年間のデータで,単なる保有戦略よりも優れたパフォーマンスを発揮しています.

戦略原則

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

  1. MACD指数:価格動力の変化を判断する.

  2. EMA平均線:価格の方向を判断する

  3. 時間の条件: 戦略の有効期間を制限する.

  4. 多空選択:多空または空の方向を選択する.

取引の具体的ルールは以下の通りです.

  1. プラス/空白:閉盘価格がEMAより高く,MACD柱状線が正し,現在のK線が前日より高いとき,プラス/空白する.

  2. 空売り/平売り:閉盘価格がEMAより低いとき,MACD柱状線が負であり,現在のK線が前日より低いとき空売り/平売りする.

この戦略は,トレンドと短期間の2つの取引の考え方を融合させ,効率的な量的な意思決定システムを形成します.

優位分析

この戦略は,単一の指標と比較して,以下の利点があります.

  1. MACDは短期的な動力を判断し,EMAはトレンドの方向を判断し,指標は緊密に配合する.

  2. 規則はシンプルでわかりやすく,理解しやすく,実行し難しくない.

  3. 柔軟に調整できるパラメータは,異なる品種と時間周期に適用されます.

  4. 単方向で多,空のどちらかを選択し,双方向で取引することもできます.

  5. 戦略の有効期間を設定して,不必要な取引を回避できます.

  6. 安定した業績と長年にわたって継続的な利益がある.

  7. 資金管理は管理し,単一の損失を避けることができます.

  8. 機械学習の技術を導入し,最適化や向上させることができます.

リスク分析

この戦略は多くの利点がありますが,以下のリスクも懸念されています.

  1. パラメータ最適化の範囲は広く,過最適化のリスクがあります.

  2. ストップ・ストップが設定されていない場合,損失が拡大するリスクがある.

  3. 取引量も考慮していないので,偽の突破が発生する可能性があります.

  4. 遅刻はトレンドの転換点を認識し,完全に損失を回避することはできません.

  5. 市場環境の変化により効果が弱まる可能性があります.

  6. モデルが安定していることに注意してください.

  7. 取引の頻度が高く,取引コストが高くなる可能性があります.

  8. 利回り率に注意し,曲線がすぎないようにしましょう.

最適化の方向

分析の結果,この戦略は以下のように最適化できる:

  1. 偽突破を避けるため,取引量指数に加入します.

  2. ストップ・ロスト・ストップを設定し,単発損失を制御する.

  3. 異なる時間帯のパラメータの効果を評価する.

  4. 機械学習の導入と動態の最適化

  5. マルチ市場検証,安定性向上

  6. ポジションのサイズを調整し,取引頻度を減らす.

  7. 資金管理戦略の最適化

  8. テスト価格差の契約は,頻度を増やします.

  9. 継続的な反復検査により,過適合を防止する.

要約する

この戦略は,MACDとEMAの指標を組み合わせて,全体として簡潔で効率的な量化戦略を形成する.しかし,いかなる戦略も,市場環境の変化に適応し,安定性を保つために,継続的に最適化および検証する必要があります.取引戦略は,継続的に進化し,更新する必要があります.

ストラテジーソースコード
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SoftKill21

//@version=4
strategy("My Script", overlay=true)

//heiking ashi calculation
UseHAcandles    = input(false, title="Use Heikin Ashi Candles in Algo Calculations")
//
// === /INPUTS ===

// === BASE FUNCTIONS ===

haClose = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : close
haOpen  = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : open
haHigh  = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : high
haLow   = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : low

//timecondition
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2020, title = "From Year", minval = 1970)
 //monday and session 
 
// To Date Inputs
toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2021, title = "To Year", minval = 1970)

startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true

//ema data  -- moving average
len = input(9, minval=1, title="Length")
src = input(hl2, title="Source")
out = ema(src, len)
//plot(out, title="EMA", color=color.blue)

//histogram
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)

// Calculating
fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal


//main variables to apply conditions are going to be out(moving avg) and hist(macd)

long = haClose > out and haClose > haClose[1] and out > out[1] and hist> 0 and hist[1] < 0 and time_cond
short = haClose < out and haClose < haClose[1] and out < out[1] and hist < 0 and hist[1] > 0 and time_cond

//limit to 1 entry
var longOpeneda = false
var shortOpeneda = false
var int timeOfBuya = na



longCondition= long and not longOpeneda 

if longCondition
    longOpeneda := true
    timeOfBuya := time


longExitSignala = short
exitLongCondition = longOpeneda[1] and longExitSignala

if exitLongCondition
    longOpeneda := false
    timeOfBuya := na


plotshape(longCondition, style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, title="BUY", text="BUY", textcolor=color.white)
plotshape(exitLongCondition, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="SELL", text="SELL", textcolor=color.white)

//automatization

longEntry= input(true)
shortEntry=input(false)

if(longEntry)
    strategy.entry("long",strategy.long,when=longCondition)
    strategy.close("long",when=exitLongCondition)

if(shortEntry)
    strategy.entry("short",strategy.short,when=exitLongCondition)
    strategy.close("short",when=longCondition)