단기, 중기 및 장기 EMA 크로스오버 거래 전략

저자:차오장날짜: 2023-11-24 13:33:21
태그:

img

이 전략은 서로 다른 기간을 가진 세 가지 기하급수적인 이동 평균 라인 (EMA) 을 기반으로 거래 신호를 생성합니다. 5 일 기간을 가진 단기 EMA, 8 일 기간을 가진 중기 EMA 및 13 일 기간을 가진 장기 EMA. 단기 EMA가 중기 및 장기 EMA를 넘어서면 길게, 중기 및 장기 EMA를 넘어서면 짧게됩니다.

전략 논리

이 전략은 다른 기간의 EMA를 계산하여 시장 트렌드를 판단합니다. 단기 EMA는 최근 며칠의 평균 가격을 반영하고 중장기 EMA는 더 긴 시간 프레임에서의 평균 가격을 반영합니다. 중장기 EMA에 대한 단기 EMA의 크로스오버는 가격의 상승 브레이크를 신호하여 긴 포지션을 취합니다. 반대로, 단기 EMA가 다른 두 개 아래로 넘어가면 하락 가격 브레이크를 신호하여 짧은 포지션을 취합니다.

특히, 이 전략은 5일, 8일 및 13일 EMA를 동시에 계산한다. 5일 EMA가 8일 및 13일 EMA를 넘을 때 긴 신호를 생성한다; 5일 EMA가 다른 두 개 아래로 넘을 때 짧은 신호를 생성한다. 긴 지점에 들어가면 5일 EMA가 13일 EMA 아래로 다시 넘어가면 포지션은 닫힌다. 짧은 포지션에도 마찬가지다.

전략 의 장점

  1. 여러 기간 EMA를 사용하는 것은 너무 짧거나 긴 단일 EMA 기간에서 발생할 수 있는 주요 트렌드 반전 지점을 놓치는 것을 피합니다.
  2. 단기, 중기 및 장기 EMA 세 개를 결합하면 거래 신호의 신뢰성이 향상됩니다.
  3. EMA를 통한 원활한 가격 결정은 시장 소음을 필터링하고 불필요한 입시를 방지합니다.

전략 의 위험

  1. 이 세 가지 EMA는 모두 후진 트렌드 지표이며, 실제 가격 파업 전까지 약간의 시간 지연을 포함하고 있으며, 늦은 신호가 발생할 위험이 있습니다.
  2. EMA는 실제 추세와 단기 교정을 효과적으로 구별할 수 없으며 잘못된 신호를 낼 수 있습니다.
  3. 고정 EMA 기간은 다른 시간 프레임에서 다른 시장 체제에 적응할 수 없습니다.

개선 아이디어:

  1. MACD와 같은 다른 지표를 추가하여 실제 추세를 더 잘 측정하고 잘못된 신호를 피합니다.
  2. 다양한 제품 및 시장 환경에 대한 EMA 기간 매개 변수를 유연하게 조정합니다.
  3. 수익을 차단하고 위험을 제어하기 위해 이동 스톱 손실을 추가합니다.

요약

이 브레이크아웃 시스템은 짧은, 중장기 및 장기 EMA 사이의 크로스오버를 비교하여 트렌드 역전을 판단하는 전형적인 시스템이다. 신호의 단순성은 거래를 용이하게하지만 EMA의 고유한 지연과 일시적인 보정으로부터 실제 트렌드를 필터할 수 없다는 문제로 고통받습니다. 미래의 개선은 다른 기술적 지표 또는 적응적 매개 변수 조정을 통합하여 최적화 할 수 있습니다.


/*backtest
start: 2023-11-16 00:00:00
end: 2023-11-23 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gregoirejohnb
// @It is modified by ttsaadet.
// Moving average crossover systems measure drift in the market. They are great strategies for time-limited people.
// So, why don't more people use them?
// 

//
strategy(title="EMA Crossover Strategy", shorttitle="EMA-5-8-13 COS by TTS", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.TRY,commission_type=strategy.commission.percent,commission_value=0.04, process_orders_on_close = true, initial_capital = 100000)

// === GENERAL INPUTS ===
//strategy start date
start_year = input(defval=2020, title="Backtest Start Year")

// === LOGIC ===
short_period = input(type=input.integer,defval=5,minval=1,title="Length")
mid_period = input(type=input.integer,defval=8,minval=1,title="Length")
long_period = input(type=input.integer,defval=13,minval=1,title="Length")

longOnly = input(type=input.bool,defval=false,title="Long Only")
shortEma = ema(hl2,short_period)
midEma = ema(hl2,mid_period)
longEma = ema(hl2,long_period)

plot(shortEma,linewidth=2,color=color.red,title="Fast")
plot(midEma,linewidth=2,color=color.orange,title="Fast")
plot(longEma,linewidth=2,color=color.blue,title="Slow")

longEntry = ((shortEma > midEma) and crossover(shortEma,longEma)) or ((shortEma > longEma) and crossover(shortEma,midEma))
shortEntry =((shortEma < midEma) and crossunder(shortEma,longEma)) or ((shortEma < longEma) and crossunder(shortEma,midEma))

plotshape(longEntry ? close : na,style=shape.triangleup,color=color.green,location=location.belowbar,size=size.small,title="Long Triangle")
plotshape(shortEntry and not longOnly ? close : na,style=shape.triangledown,color=color.red,location=location.abovebar,size=size.small,title="Short Triangle")
plotshape(shortEntry and longOnly ? close : na,style=shape.xcross,color=color.black,location=location.abovebar,size=size.small,title="Exit Sign")

// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() =>
    longEntry 
exitLong() =>
    crossunder(shortEma,longEma)

strategy.entry(id="Long", long=strategy.long, when=enterLong())
strategy.close(id="Long", when=exitLong())


// === STRATEGY - SHORT POSITION EXECUTION ===

enterShort() =>
    not longOnly and shortEntry  
exitShort() =>
    crossover(shortEma,longEma)

strategy.entry(id="Short", long=strategy.short, when=enterShort())
strategy.close(id="Short", when=exitShort())

더 많은