이중 이동 평균 크로스오버 전략

저자:차오장, 2024-01-12 14:59:18
태그:

img

전반적인 설명

이중 이동 평균 크로스오버 전략은 트렌드를 따르는 전형적인 전략이다. 그것은 서로 다른 기간을 가진 두 개의 EMA 라인을 사용하고 짧은 기간 EMA가 더 긴 기간 EMA를 넘을 때 길고 반대 교차가 트렌드 반전을 캡처 할 때 짧습니다.

원칙

이 전략의 핵심 지표는 두 개의 EMA 라인입니다. 하나는 30 기간이고 다른 하나는 60 기간입니다. 두 개의 EMA 라인은 코드에서 사용자 정의 함수로 계산됩니다.

emaLen1 = emaFuncOne(close, lenMA1)
emaLen2 = emaFuncTwo(close, lenMA2)  

거래 신호는 두 개의 EMA 라인의 교차에서 생성됩니다.

currentState = if emaLen2 > emaLen1
    0
else 
    1

previousState = if emaLastLen2 > emaLastLen1 
    0
else
    1

convergence = if currentState != previousState
    1  
else
    0

짧은 기간 EMA가 더 긴 기간 EMA를 넘을 때, currentState는 previousState와 같지 않습니다. 짧은 기간 EMA가 더 긴 기간 EMA 아래로 넘어가면, currentState는 previousState와 같지 않습니다, 크로스오버 신호가 트리거됩니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 논리는 간단하고 직관적이며 이해하기 쉽고 구현하기 쉽습니다.
  2. EMA와 함께 가격 변동을 완화하고 시장 소음을 필터링합니다.
  3. 트렌드를 자동으로 추적하고 트레이드를 놓치지 않습니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. 크로스오버 신호는 늦어지기도 하고 역전을 적시에 포착하지 못할 수도 있습니다.
  2. Whipsaw 신호는 범위 시장에서 자주 발생할 수 있습니다.
  3. 열악한 매개 변수 조정은 과민성 또는 지연을 일으킬 수 있습니다.

최적화는 EMA 기간을 조정하거나 필터를 추가하여 수행 할 수 있습니다.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 다른 EMA 기간 조합을 테스트합니다.
  2. 거짓 신호를 줄이기 위해 볼륨 또는 변동성 필터를 추가합니다.
  3. 추세를 확인하기 위해 MACD와 같은 다른 지표를 포함합니다.
  4. 손해를 멈추고 수익을 취하는 방식으로 자금 관리를 최적화하십시오

결론

이중 이동 평균 크로스오버 전략은 전체적으로 추세를 따르는 간단하고 실용적인 시스템입니다. 그것은 직선적이고 구현하기 쉽고 트렌드를 자동으로 추적 할 수 있습니다. 그러나 지연 및 잘못된 신호와 같은 몇 가지 위험이 있습니다. 매개 변수 조정 및 필터를 추가하면 근본적인 알고리즘 거래 전략 중 하나가 될 수 있습니다.


/*backtest
start: 2024-01-10 00:00:00
end: 2024-01-11 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy("ParkerMAStrat", overlay=true)

lenMA1=input(title="Length 1", defval=30)
lenMA2=input(title="Length 2",  defval=60)

x = 0

checkLines(current, last) =>

    if current > last
        x = 1
    else
        x = 0
    x
    

//plot ema based on len1
emaFuncOne(src, time_period) =>

    alpha = 2 / (time_period + 1)
    // we have defined the alpha function above
    ema = 0.0
    // this is the initial declaration of ema, since we dont know the first ema we will declare it to 0.0 [as a decimal]
    ema := alpha * src + (1 - alpha) * nz(ema[1])
    // this returns the computed ema at the current time
    // notice the use of : (colon) symbol before =, it symbolises, that we are changing the value of ema,
    // since the ema was previously declared to 0
    // this is called mutable variale declaration in pine script
    ema
    // return ema from the function

emaLen1 = emaFuncOne(close, lenMA1)

    
plot(emaLen1, color=green, transp=0, linewidth=2)
// now we plot the _10_period_ema

//plot ema based on len2
emaFuncTwo(src, time_period) =>

    alpha = 2 / (time_period + 1)
    // we have defined the alpha function above
    ema = 0.0
    // this is the initial declaration of ema, since we dont know the first ema we will declare it to 0.0 [as a decimal]
    ema := alpha * src + (1 - alpha) * nz(ema[1])
    // this returns the computed ema at the current time
    // notice the use of : (colon) symbol before =, it symbolises, that we are changing the value of ema,
    // since the ema was previously declared to 0
    // this is called mutable variale declaration in pine script
    ema
    // return ema from the function

//plot ema based on len2
emaFuncOneLast(src, time_period) =>

    alpha = 2 / (time_period + 1)
    // we have defined the alpha function above
    ema = 0.0
    // this is the initial declaration of ema, since we dont know the first ema we will declare it to 0.0 [as a decimal]
    ema := alpha * src + (1 - alpha) * nz(ema[0])
    // this returns the computed ema at the current time
    // notice the use of : (colon) symbol before =, it symbolises, that we are changing the value of ema,
    // since the ema was previously declared to 0
    // this is called mutable variale declaration in pine script
    ema
    // return ema from the function

//plot ema based on len2
emaFuncTwoLast(src, time_period) =>

    alpha = 2 / (time_period + 1)
    // we have defined the alpha function above
    ema = 0.0
    // this is the initial declaration of ema, since we dont know the first ema we will declare it to 0.0 [as a decimal]
    ema := alpha * src + (1 - alpha) * nz(ema[0])
    // this returns the computed ema at the current time
    // notice the use of : (colon) symbol before =, it symbolises, that we are changing the value of ema,
    // since the ema was previously declared to 0
    // this is called mutable variale declaration in pine script
    ema
    // return ema from the function



emaLastLen1 = emaFuncOneLast(close, lenMA1)
emaLastLen2 = emaFuncTwoLast(close, lenMA2)
emaLen2 = emaFuncTwo(close, lenMA2)

    
plot(emaLen2, color=red, transp=30, linewidth=2)
// now we plot the _10_period_ema

//now we compare the two and when green crosses red we buy/sell (line1 vs line2)

previousState = if emaLastLen2 > emaLastLen1
    0
else
    1

currentState = if emaLen2 > emaLen1
    0
else
    1

convergence = if currentState != previousState
    1
else
    0

    
lineCheck = if convergence == 1 
    checkLines(currentState, previousState)
    
if lineCheck == 1
    strategy.entry("Long", strategy.long)
else
    strategy.entry("Short", strategy.short)


더 많은