ダブルEMAゴールデンクロストレンドフォロー戦略


作成日: 2023-11-21 15:10:54 最終変更日: 2023-11-21 15:10:54
コピー: 0 クリック数: 648
1
フォロー
1617
フォロワー

ダブルEMAゴールデンクロストレンドフォロー戦略

概要

この戦略は,速線EMAと遅線EMAを計算し,二つのEMAの大きさの関係を比較して市場トレンドの方向を判断するために,簡単なトレンド追跡戦略に属します. 速線EMA上での遅線EMAを横切るときに多行し,速線EMA下での遅線EMAを横切るときに空行し,典型的な双EMA黄金クロス戦略に属します.

戦略原則

この戦略の核心指標は,快線EMAと慢線EMAである.快線EMAの長さは21サイクル,慢線EMAの長さは55サイクルに設定されている.快線EMAは,最近の短期トレンドを反映した価格変化により迅速に反応し,慢線EMAは,価格変化に反応し,中長期トレンドを反映した部分的なノイズをフィルターするより遅い.

速線EMA上での遅線EMAを横断すると,短期トレンドが上昇に転じ,中長期トレンドが逆転する可能性があり,これは多額のシグナルである.速線EMA下での遅線EMAを横断すると,短期トレンドが下向きに転じ,中長期トレンドが逆転する可能性があり,これは空調のシグナルである.

EMAを速やかに比較することで,短期と中長期の2つの時間尺度におけるトレンドの転換点を捉えることができる.これは典型的なトレンド追跡策である.

戦略的優位性

  1. シンプルで明快で,理解し,実行しやすい
  2. パラメータ調整の柔軟性,快線と遅線EMA周期のカスタマイズ
  3. 設定可能なATR止損止め,制御可能なリスク

戦略リスク

  1. 双EMA交差点の選択は不適切であり,最適なエントリーポイントを逃すリスクがある
  2. 状況が揺れ動いているとき,複数の無効信号が発生し,損失のリスクが生じます.
  3. ATR パラメータが正しく設定されていないため,ストップダメージが過度に緩やかまたは過度に激しくなる可能性があります.

リスク対策:

  1. EMAのスローラインパラメータを最適化して,最適なパラメータの組み合わせを探します.
  2. フィルタリングの強化により,変動による無効信号を回避する.
  3. ATRパラメータをテストし,最適化して,止損停止設定が合理的であることを確認する.

戦略最適化の方向性

  1. 統計的方法による異なるEMA周期パラメータの安定性テスト
  2. フィルタリング条件を追加し,他の指標と組み合わせて無効信号を回避する
  3. ATRパラメータを最適化して最適のストップ・ローズ・ストップ・レートを得る

要約する

この戦略は,快線EMAと慢線EMAの交差によって市場トレンドを判断し,シンプルで明快で,容易に実行できます.同時にATRと組み合わせて,ストップ・ローズ・ストップを設定し,制御可能なリスクを設定できます.パラメータを最適化し,フィルタリング条件を増やすことで,戦略の安定性と収益性をさらに強化できます.

ストラテジーソースコード
/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy(title = "VP Backtester", overlay=false)


// Create General Strategy Inputs
st_yr_inp = input(defval=2017, title='Backtest Start Year')
st_mn_inp = input(defval=01, title='Backtest Start Month')
st_dy_inp = input(defval=01, title='Backtest Start Day')
en_yr_inp = input(defval=2025, title='Backtest End Year')
en_mn_inp = input(defval=01, title='Backtest End Month')
en_dy_inp = input(defval=01, title='Backtest End Day')
 
// Default Stop Types
fstp = input(defval=false, title="Fixed Perc stop")
fper = input(defval=0.1, title='Percentage for fixed stop', type=float)
atsp = input(defval=true, title="ATR Based stop")
atrl = input(defval=14, title='ATR Length for stop')
atrmsl = input(defval=1.5, title='ATR Multiplier for stoploss')
atrtpm = input(defval=1, title='ATR Multiplier for profit')
 
// Sessions
asa_inp = input(defval=true, title="Trade the Asian Session")
eur_inp = input(defval=true, title="Trade the European Session")
usa_inp = input(defval=true, title="Trade the US session")
ses_cls = input(defval=true, title="End of Session Close Out?")
 
// Session Start / End times (In exchange TZ = UTC-5)    
asa_ses = "1700-0300" 
eur_ses = "0200-1200" 
usa_ses = "0800-1700"  
 
in_asa = time(timeframe.period, asa_ses)
in_eur = time(timeframe.period, eur_ses)
in_usa = time(timeframe.period, usa_ses)
 
strategy.risk.allow_entry_in(strategy.direction.all)
 
// Set start and end dates for backtest
start = timestamp(st_yr_inp, st_mn_inp, st_dy_inp,00,00)
end = timestamp(en_yr_inp, en_mn_inp, en_dy_inp,00,00)
window()  => time >= start and time <= end ? true : false // create function "within window of time"

 
// Check if we are in a sessions we want to trade
can_trade = asa_inp and not na(in_asa) ? true :
  eur_inp and not na(in_eur) ? true :
  usa_inp and not na(in_usa) ? true :
  false
  
// atr calc for stop and profit
atr = atr(atrl)
atr_stp_dst_sl = atr * atrmsl
atr_stp_dst_tp = atr * atrtpm



//*************************************************************************************
// Put your strategy/indicator code below
// and make sure to set long_condition=1 for opening a buy trade
// and short_condition for opening a sell trade
//*************************************************************************************
fastInput = input(21)
slowInput = input(55)

fast = ema(close, fastInput)
slow = ema(close, slowInput)

plot(fast, color = red)
plot(slow, color = blue)

long_condition = crossover(fast, slow)
short_condition = crossunder(fast, slow)


//*************************************************************************************
// Trade management with ATR based stop & profit
//*************************************************************************************
if (long_condition and window() )
    strategy.entry("Long Entry",  strategy.long)
    if strategy.position_size <= 0 // Less than as in both direction strat - Could be long before switching
        if atsp
            atr_stop = open  - atr_stp_dst_sl
            atr_profit = open + atr_stp_dst_tp
            strategy.exit('ATR Long Exit', "Long Entry", stop=atr_stop, limit = atr_profit)
        if fstp
            stop = open - (open * fper)
            strategy.exit('Perc Fixed Long Stop Exit', "Long Entry", stop=stop)
 
if (short_condition and window() )
    strategy.entry("Short Entry",strategy.short)
    if strategy.position_size >= 0 // Greater than as in both direction strat - Could be long before switching
        if atsp
            atr_stop = open  + atr_stp_dst_sl
            atr_profit = open - atr_stp_dst_tp
            strategy.exit('ATR Short Exit', "Short Entry", stop=atr_stop, limit = atr_profit)
        if fstp
            stop = open + (open * fper)
            strategy.exit('Perc Fixed Short Stop Exit', "Short Entry", stop=stop)
 
 
strategy.close_all(when=not can_trade and ses_cls)