단기 이동평균선이 중기 및 장기 이동평균선을 교차할 때의 돌파거래 전략


생성 날짜: 2023-11-24 13:33:21 마지막으로 수정됨: 2023-11-24 13:33:21
복사: 0 클릭수: 853
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

단기 이동평균선이 중기 및 장기 이동평균선을 교차할 때의 돌파거래 전략

이 전략은 단기, 중기, 장기 3개의 다른 주기들의 지수 이동 평균 (EMA) 을 기반으로 거래 신호를 생성한다. 그 중, 단기 EMA 주기는 5일이고, 중기 EMA 주기는 8일이고, 장기 EMA 주기는 13일이다. 단기 EMA가 중기 및 장기 EMA를 통과하면 더 많이 하고, 단기 EMA가 중기 및 장기 EMA를 통과하면 더 적게 한다.

전략 원칙

이 전략은 서로 다른 주기의 EMA를 계산하여 시장의 흐름을 판단한다. 단기 EMA는 최근 며칠의 평균 가격을 반영하고, 중기 EMA는 더 긴 기간의 평균 가격을 반영한다. 단기 EMA 위를 가로질러 중기 장기 EMA는 가격이 상향으로 돌파되기 시작하여 더 많이 한다. 단기 EMA 아래를 가로질러 중기 장기 EMA는 가격이 하향으로 돌파되기 시작하여 공백한다.

구체적으로, 이 전략은 동시에 5일, 8일, 13일 세 개의 EMA를 계산한다. 5일 EMA 위 8일과 13일 EMA를 착용할 때 다수 신호가 생성된다. 5일 EMA 아래 8일과 13일 EMA를 착용할 때 다수 신호가 생성된다. 다수 후, 5일 EMA가 다시 13일 EMA를 착용할 경우, 평지된다.

전략적 이점

  1. 다주기 EMA를 사용하여 트렌드를 판단하여 단일 EMA 주기가 너무 짧거나 너무 길어서 중요한 트렌드 전환점을 놓치지 않도록하십시오.
  2. 중·단·장기 3주기 EMA와 결합하여 거래 신호가 더 신뢰성 있고 정확합니다.
  3. EMA를 통해 가격을 평평하게 하고, 시장의 일부 소음을 필터링하여 불필요한 포지션을 방지할 수 있습니다.

전략적 위험

  1. 세 개의 EMA는 지연된 추세 지표이며 실제 가격 돌파가 발생하기 전에 시간 차이가 발생할 수 있으며 거래 신호가 지연 될 수 있습니다.
  2. EMA는 실제 동향과 단기 조정의 차이를 구별하지 못하여 잘못된 신호를 줄 수 있습니다.
  3. 고정된 EMA 주기는 다른 주기의 변화하는 시장의 특성에 적응할 수 없습니다.

다음의 방법으로 최적화할 수 있습니다.

  1. MACD와 같은 다른 지표와 결합하여 진정한 트렌드를 판단하여 잘못된 신호를 피하십시오.
  2. 다양한 품종, 시장 환경에 따라 유연하게 조정 가능한 EMA 주기 파라미터
  3. 이동성 손실을 추가하여 수익을 고정하고 위험을 제어합니다.

요약하다

이 전략은 짧은 중장기 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())