이중 EMA 골든 크로스 트렌드 추적 전략

저자:차오장, 날짜: 2023-11-21 15:10:54
태그:

img

전반적인 설명

이 전략은 빠른 EMA 라인과 느린 EMA 라인을 계산하고 시장의 트렌드 방향을 결정하기 위해 두 EMA 사이의 크기 관계를 비교합니다. 간단한 트렌드 추적 전략에 속합니다. 빠른 EMA가 느린 EMA를 넘으면 길게 이동합니다. 빠른 EMA가 느린 EMA를 넘으면 짧게 이동합니다. 전형적인 이중 EMA 황금 십자가 전략입니다.

전략 논리

이 전략의 핵심 지표는 빠른 EMA와 느린 EMA입니다. 빠른 EMA 길이는 21 기간으로 설정되고 느린 EMA 길이는 55 기간으로 설정됩니다. 빠른 EMA는 최근의 단기 트렌드를 반영하여 가격 변화에 더 빠르게 반응 할 수 있습니다. 느린 EMA는 약간의 소음을 필터링하여 중장기 트렌드를 반영하여 가격 변화에 더 느리게 반응합니다.

빠른 EMA가 느린 EMA를 넘을 때, 단기 트렌드가 상승하고 중장기 트렌드가 역전될 수 있음을 나타냅니다. 이것은 긴 거리에 갈 신호입니다. 빠른 EMA가 느린 EMA를 넘을 때, 단기 트렌드가 하향으로 변하고 중장기 트렌드가 역전될 수 있음을 나타냅니다. 이것은 짧은 거리에 갈 신호입니다.

빠른 EMA와 느린 EMA를 비교함으로써, 단기 및 중장기, 두 가지 시간대에서 트렌드 반전 지점을 포착합니다. 이것은 전형적인 트렌드 추적 전략입니다.

장점

  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)
 


더 많은