EMA 경사 크로스 트렌드 전략

저자:차오장, 날짜: 2023-10-17 17:02:30
태그:

img

전반적인 설명

이 전략은 다른 길이의 두 EMA의 기울기의 교차를 사용하여 신호를 따라 트렌드를 생성합니다. 기본적으로 130 및 400이 사용됩니다.

전략이 시장에 진출하는 조건은 다음과 같습니다.

  • 빠른 기울기 > 느린 기울기 및 가격 > EMA 200: 길게 이동
  • 빠른 기울기 < 느린 기울기 및 가격 < EMA 200: 단축

단순 경사선이 반대 방향으로 교차하면 위치가 닫습니다.

이 전략은 비트코인과 가장 유동적이고 자본화 된 알트코인에서 가장 잘 작동하지만 특히 트렌드를 자주 가지면 휘발성 자산에서도 잘 작동합니다. 4시간 정도면 잘 되죠

또한 옵션으로 사용할 수 있는 변동성 필터 (Volatility filter) 가 있는데, 두 기울기 사이의 차이가 특정 값보다 크면만 포지션을 열 수 있습니다. 목적은 가격이 옆으로 갈 때 포지션을 열지 않고 소음이 신호보다 훨씬 커지는 것입니다.

즐기세요!

전략 논리

이 전략의 핵심은 서로 다른 길이의 두 EMA의 기울기를 비교하는 것입니다.

먼저 130과 400의 길이의 EMA를 계산하고, 각 기울기의 기울기를 계산하고, 각 기울기에 길이 3의 EMA를 계산하여 평탄한 기울기 곡선을 얻습니다.

빠른 EMA 기울기가 느린 EMA 기울기의 위를 넘을 때 구매 신호가 생성됩니다. 빠른 EMA 기울기가 느린 EMA 기울기의 아래를 넘을 때 판매 신호가 생성됩니다.

소음을 필터링하기 위해, 200 기간 EMA는 트렌드 필터로 사용될 수 있으며, 가격이 EMA보다 높을 때만 긴 신호를 고려하고, EMA보다 낮을 때만 짧은 신호를 고려합니다.

또한 변동성 필터를 사용할 수 있으며, 두 기울기 사이의 차이는 한 임계보다 크면만 신호를 생성하여 기울기가 교차하지만 변동성이 충분하지 않은 경우를 피합니다.

빠른 경사와 느린 경사가 역으로 교차할 때, 포지션은 수익/손실을 막기 위해 닫습니다.

이점 분석

  1. 신호를 생성하기 위해 기울기 교차를 사용하면 트렌드를 효과적으로 추적 할 수 있습니다.

  2. EMA 기간 조합을 조정하면 다른 시장 조건에 적응할 수 있습니다.

  3. 트렌드 필터는 불조리한 가격 움직임에 의해 오해되는 것을 피합니다.

  4. 변동성 필터는 잘못된 신호를 필터링합니다.

  5. 단순하고 명확한 논리, 이해하기 쉽고 실행하기 쉬운

  6. 여러 시간 프레임에서 사용할 수 있습니다.

위험 분석

  1. 큰 범위의 시장에서 빈번한 오픈과 종료가 발생할 수 있습니다.

  2. 부적절한 EMA 기간은 트렌드 전환점을 놓칠 수 있습니다.

  3. 변하는 시장 조건에 적응하도록 매개 변수를 조정해야 합니다.

  4. MA 시스템과 마찬가지로, 큰 추세는 극단적으로 반전될 수 있습니다.

최적화 방향

  1. 최적의 매개 변수를 찾기 위해 다른 EMA 기간 조합을 시도하십시오.

  2. 자산 특성 및 시장 조건에 따라 매개 변수를 선택

  3. 위험을 통제하기 위해 스톱 로스 전략을 추가하는 것을 고려하십시오.

  4. 동적으로 EMA 기간을 조정하는 것을 고려하십시오

  5. 다른 변동성 임계값을 테스트합니다

  6. 시간 프레임에 걸쳐 테스트 효과

요약

이 전략은 명확하고 이해하기 쉬운 논리를 가지고 있으며, EMA 기울기 교차를 사용하여 신호를 생성하고 트렌드를 효과적으로 추적합니다. 트렌드 및 변동성 필터는 시끄러운 거래를 줄여줍니다. EMA 기간 조합을 조정하면 다양한 시장 조건에 적응합니다. 전반적으로 실시간 거래에서 테스트하고 최적화하는 가치가있는 간단하고 실용적인 트렌드 다음 전략입니다.


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

//@version=4
// strategy(title="Slopes",initial_capital=1000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=30, overlay=false)

//definizione input

start = timestamp(input(2018, "start year"), input(1, "start month"), input(1, "start day"), 00, 00)
end = timestamp(input(2020, "end year"), input(1, "end month"), input(1, "end day"), 00, 00)

average = input (title="Source MA Type", type=input.string, defval="EMA",options=["EMA","SMA"])

len1=input(130,title="Fast MA Length")
len2=input(400,title="Slow MA Length")

smoothingavg = input (title="Smoothing MAs Type", type=input.string, defval="EMA",options=["EMA","SMA"])
smoothingavglen = input (3,title="Smoothing MAs Length")

trendfilter=input(true,title="Trend Filter")
trendfilterperiod=input(200,title="Trend Filter MA Period")
trendfiltertype=input (title="Trend Filter MA Type", type=input.string, defval="EMA",options=["EMA","SMA"])

volatilityfilter=input(false,title="Volatility Filter")
volatilitydelta=input(0.0003,step=0.0001,title="Delta Slopes EMA")

//variabili

m1 = if average == "EMA" 
    ema(close,len1)
else
    sma(close,len1)

m2=if average == "EMA" 
    ema(close,len2)
else
    sma(close,len2)

slp1=(m1-m1[1])/m1
slp2=(m2-m2[1])/m2

e1=if smoothingavg == "EMA" 
    ema(slp1,smoothingavglen)
else
    sma(slp1,smoothingavglen)

e2=if smoothingavg == "EMA" 
    ema(slp2,smoothingavglen)
else
    sma(slp2,smoothingavglen)

plot(e1,color=color.yellow)
plot(e2,color=color.red)
//plot (abs(e1-e2),color=color.white)
//plot (ema(e1-e2,9),color=color.yellow)

//variabili accessorie e condizioni

TrendConditionL=if trendfiltertype =="EMA"
    close>ema(close,trendfilterperiod)
else
    close>sma(close,trendfilterperiod)
    
TrendConditionS=if trendfiltertype =="EMA"
    close<ema(close,trendfilterperiod)
else
    close<sma(close,trendfilterperiod)
    
VolatilityCondition = abs(e1-e2) > volatilitydelta

ConditionEntryL= if trendfilter == true
    if volatilityfilter == true
        e1>e2 and TrendConditionL and VolatilityCondition
    else
        e1>e2 and TrendConditionL
else
    if volatilityfilter == true
        e1>e2 and VolatilityCondition
    else 
        e1>e2

ConditionEntryS= if trendfilter == true
    if volatilityfilter == true
        e1<e2 and TrendConditionS and VolatilityCondition
    else 
        e1<e2 and TrendConditionS
else
    if volatilityfilter == true
        e1<e2 and VolatilityCondition
    else
        e1<e2

ConditionExitL=crossunder(e1,e2)
ConditionExitS=crossover(e1,e2)

if true
    if ConditionExitS
        if strategy.position_size < 0
            strategy.close("SLPShort")

if true
    if ConditionExitL
        if strategy.position_size > 0
            strategy.close("SLPLong")

if true
    if ConditionEntryL
        strategy.entry ("SLPLong",long=true)
        
if true
    if ConditionEntryS 
        strategy.entry("SLPShort",long=false)

더 많은