双 EMA ゴールデンクロス トレンド トラッキング 戦略

作者: リン・ハーンチャオチャン,日付: 2023年11月21日 15時10分54秒
タグ:

img

概要

この戦略は,速いEMA線と遅いEMA線を計算し,市場のトレンド方向を決定するために2つのEMA間のサイズ関係を比較する.これは単純なトレンド追跡戦略に属している.速いEMAが遅いEMAを超えると,ロングに行く.速いEMAが遅いEMAを下回ると,ショートに行く.これは典型的な二重EMAゴールデンクロス戦略である.

戦略の論理

この戦略の主な指標は,高速EMAと遅いEMAである.高速EMAの長さは21期,遅いEMAの長さは55期に設定されている.高速EMAは,最近の短期トレンドを反映した価格変化により速く反応することができる.遅い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クロスオーバーに基づいてトレンドを判断し,実装がシンプルで明確である.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)
 


もっと