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

作者: リン・ハーンチャオチャン, 日時: 2023-09-23 15:24:12
タグ:

概要

これは,MACDオシレーターとEMAクロスオーバーを組み合わせたシンプルで効率的な取引戦略である.現在4hキャンドルに設定されているが,他のタイムフレームに適応できる.過去3年間でBTCとETHでうまく機能し,バイ・アンド・ホールに勝った.最適化により,先物,インデックス,フォレックス,株式などに適応することができる.

戦略の論理

主要な要素は次のとおりです.

  1. MACD: 価格動向の変化を判断する

  2. EMA: 価格傾向の方向性を決定する.

  3. 時間条件:有効な戦略期間を定義する.

  4. 長/短オプション:長または短方向を選択する.

取引規則は以下のとおりです

  1. ロング/アウトショート: EMA の上を閉じる時,MACD ヒストグラムが正し,現在のキャンドルは前のキャンドルより高い.

  2. ショート/ロングアウト: EMAを下回り,MACDヒストグラムがマイナスになり,現在のキャンドルは前のキャンドルより低い.

戦略は シンプルで効率的なシステムで 傾向と勢いを組み合わせます

利点

単一指標と比較して,主な利点は以下の通りです.

  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)



もっと