EMA 크로스오버에 기반한 트렌드 거래 전략

저자:차오장, 날짜: 2023-10-31 14:37:38
태그:

img

전반적인 설명

이 전략의 핵심 아이디어는 EMA 지표의 황금 십자 및 죽은 십자 신호를 사용하여 구매 및 판매 결정을 내리는 것입니다. 빠른 및 느린 EMA의 여러 세트를 그래프화하고 크로스오버를 기반으로 거래 신호를 생성합니다.

전략 논리

전략은 먼저 빠른 EMA ema1에서 ema6 및 느린 EMA ema7에서 ema12를 포함하여 여러 EMA 라인을 정의합니다. 다음 구매 신호를 정의합니다.

  • 구매 신호는 ema1이 ema3 위에 넘어가면 생성됩니다.

  • 판매 신호는 ema1가 ema3 아래로 넘어가면 생성됩니다.

따라서 단기 EMA가 장기 EMA를 넘으면 시장의 상승 추세를 나타내고 구매 신호가 발사됩니다. 단기 EMA가 장기 EMA를 넘으면 하락 추세를 나타내고 판매 신호가 발사됩니다.

전략은 EMA 라인의 교차를 모니터링하여 트렌드 방향을 결정하고 이에 따라 구매/판매 결정을 합니다.

이점 분석

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

  1. 트렌드를 결정하기 위해 EMA 라인을 사용하면 단기 시장 소음을 필터링하고 거래 신호를 더 신뢰할 수 있습니다.

  2. 여러 EMA를 그래프화하면 트렌드 변화를 더 정확하게 식별할 수 있습니다. 빠른 EMA와 느린 EMA 사이의 크로스오버는 중요한 트렌드 전환점을 파악하는 데 도움이됩니다.

  3. 전략은 간단하고 명확합니다. 거래 신호는 EMA 교차로 생성되며 양 거래에 이해하기 쉽고 구현 할 수 있습니다.

  4. EMA 기간 매개 변수는 다양한 제품과 시장에 맞게 조정할 수 있습니다.

위험 분석

이 전략의 위험은 다음과 같습니다.

  1. EMA 라인은 거래 신호를 지연시킬 수 있는 지연 효과를 가지고 있습니다.

  2. EMA 매개 변수들의 잘못된 선택은 잘못된 신호를 생성할 수 있습니다.

  3. EMA 교차는 다양한 시장에서 잘못된 신호를 효과적으로 필터링하지 못합니다.

  4. EMA 매개 변수들을 최적화할 수 있는 공간이 제한되어 있기 때문에 과도한 부착 위험이 존재합니다.

해결책:

  1. 다른 지표와 함께 필터를 추가하여 다양한 시장에서 잘못된 신호를 피합니다.

  2. 다른 기간 매개 변수들의 테스트 안정성

  3. 패러미터를 조정하거나 위험을 제어하기 위한 출구 메커니즘을 추가합니다.

최적화 방향

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

  1. 손해가 한계치에 도달할 때 출구 포지션에 스톱 로스를 추가합니다.

  2. 추가 구매/판매 신호로 재입구 논리를 구현합니다.

  3. 가장 좋은 결과를 위해 EMA 교차 기간 매개 변수를 최적화하십시오.

  4. 신호 품질을 향상시키기 위해 여러 요소 검증을 위한 다른 지표를 포함합니다.

  5. 최적의 적용 가능성을 찾기 위해 다른 제품에서 테스트 매개 변수 조정

  6. 라이브 트레이딩에서 미끄러짐을 고려하고 백테스팅을 통해 최적화하십시오.

요약

이것은 EMA 크로스오버에 기반한 간단한 트렌드 다음 전략입니다. 트렌드 변화를 식별 할 수 있지만 지연 효과 및 윙사와 같은 위험도 있습니다. 스톱 로스, 매개 변수 최적화, 다중 인자 검증 등을 통해 개선하면 백테스팅 및 라이브 거래에서 전략 성능을 더욱 향상시킬 수 있습니다.


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

//@version=3
//Companion Strategy script to my Cloud Study. Enjoy! -MP
// study("MP's Cloud Study", overlay=true)
strategy(title="MP's Cloud Strat'", shorttitle="MP's Cloud Strat", overlay=true, precision=6, pyramiding=0, initial_capital=10000, currency="USD", default_qty_type=strategy.percent_of_equity,calc_on_order_fills= false, calc_on_every_tick=false, default_qty_value=100.0, commission_type=strategy.commission.percent, commission_value=0.05)

//bgcolor ( color=black, transp=20, title='Blackground', editable=true)

src = close, len1 = input(2, minval=1, title="Short EMA")
src2 = close, len3 = input(7, minval=1, title="Long EMA")
emaShort = ema(src, len1)
emaLong = ema(src2, len3)


StartYear = input(2018, "Start Year")
StartMonth = input(01, "Start Month")
StartDay = input(18, "Start Day")

 
StopYear = input(2018, "Stop Year")
StopMonth = input(12, "Stop Month")
StopDay = input(26, "Stop Day")
tradeStop = timestamp(StopYear,StopMonth,StopDay,0,0)

//src = close, 
//len1 = input(3, minval=1, title="Fast EMA 1")
len2 = input(3, minval=1, title="Fast EMA 2")
//len3 = input(8, minval=1, title="Fast EMA 3")
len4 = input(5, minval=1, title="Fast EMA 4")
len5 = input(8, minval=1, title="Fast EMA 5")
len6 = input(10, minval=1, title="Fast EMA 6")
//Slow EMA
len7 = input(30, minval=1, title="Slow EMA 7")
len8 = input(35, minval=1, title="Slow EMA 8")
len9 = input(40, minval=1, title="Slow EMA 9")
len10 = input(45, minval=1, title="Slow EMA 10")
len11 = input(50, minval=1, title="Slow EMA 11")
len12 = input(60, minval=1, title="Slow EMA 12")

//Fast EMA
ema1 = ema(src, len1)
ema2 = ema(src, len2)
ema3 = ema(src, len3)
ema4 = ema(src, len4)
ema5 = ema(src, len5)
ema6 = ema(src, len6)
//Slow EMA
ema7 = ema(src, len7)
ema8 = ema(src, len8)
ema9 = ema(src, len9)
ema10 = ema(src, len10)
ema11 = ema(src, len11)
ema12 = ema(src, len12)

//Fast EMA Color Rules
//colfastL = (ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5 and ema5 > ema6)
colfastS = (ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5 and ema5 < ema6)
//Slow EMA Color Rules
//colslowL = ema7 > ema8 and ema8 > ema9 and ema9 > ema10 and ema10 > ema11 and ema11 > ema12 
//colslowS = ema7 < ema8 and ema8 < ema9 and ema9 < ema10 and ema10 < ema11 and ema11 < ema12 
//Fast EMA Final Color Rules
//colFinal = colfastL and colslowL? aqua : colfastS and colslowS? orange : gray
//Slow EMA Final Color Rules
//colFinal2 = colslowL  ? lime : colslowS ? red : gray
//Fast EMA Plots
p1=plot(ema1, title="Fast EMA 1", style=line, linewidth=2, color=silver)
plot(ema2, title="Fast EMA 2", style=line, linewidth=1, color=silver)
plot(ema3, title="Fast EMA 3", style=line, linewidth=1, color=silver)
plot(ema4, title="Fast EMA 4", style=line, linewidth=1, color=silver)
plot(ema5, title="Fast EMA 5", style=line, linewidth=1, color=silver)
p2=plot(ema6, title="Fast EMA 6", style=line, linewidth=2, color=silver)
fill(p1,p2,color=silver, transp=60)
//Slow EMA Plots
//p3=plot(ema7, title="Slow EMA 7", style=line, linewidth=4, color=colFinal2)
//plot(ema8, title="Slow EMA 8", style=line, linewidth=3, color=colFinal2)
//plot(ema9, title="Slow EMA 9", style=line, linewidth=3, color=colFinal2)
//plot(ema10, title="Slow EMA 10", style=line, linewidth=3, color=colFinal2)
//plot(ema11, title="Slow EMA 11", style=line, linewidth=3, color=colFinal2)
//p4=plot(ema12, title="Slow EMA 12", style=line, linewidth=4, color=colFinal2)
//fill(p3,p4, color=silver, transp=60)



//Plot the Ribbon
ma1=plot( emaShort,color=rising(emaShort,2)?green:red,linewidth=1,join=true,transp=20,title="Short")
ma2=plot( emaLong,color=rising(emaLong,2)?green:red,linewidth=1,join=true,transp=20,title="Long")
fcolor = emaShort>emaLong?green:red
fill(ma1,ma2,color=fcolor,transp=80,title="Ribbon Fill")


//fast = 4, slow = 16
//fastMA = ema(close, fast)
//slowMA = ema(close, slow)
//plot(fastMA, color=green, title = "buy/sell")
//plot(slowMA, color=red, title = "base")


//Conditions
buy_signal = crossover(ema1,ema3)
sell_signal = crossunder(ema1,ema3)

plotshape(sell_signal, style=shape.triangleup, color = red, text="Start Short")
plotshape(buy_signal, style=shape.triangledown, color = green, text="Start Long")

alertcondition(sell_signal, title = 'Sell/Short', message = 'e= s= c=position b=long t=market l= | delay=30 | e= s= b=short l= t=market q=0.01')
alertcondition(buy_signal, title = 'Buy/Long', message =  'e= s= c=position b=short t=market l= | delay=30 | e= s= b=long l= t=market q=0.01')

//alertcondition(sell_signal, title = 'Sell/Short', message = 'e= s= c=order b=buy | delay=3 | e= b=sell q=99% p=0.70% u=currency')
//alertcondition(buy_signal, title = 'Buy/Long', message =  'e= s= c=order b=sell | delay=30 | e= b=buy q=80 p=0.1% u=currency')


testStartYear = input(2018, "From Year") 
testStartMonth = input(1, "From Month")
testStartDay = input(1, "From Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2019, "To Year")
testStopMonth = input(1, "To Month")
testStopDay = input(1, "To Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() => true

if testPeriod()
    if buy_signal
        strategy.entry("Long", true)
    

    if sell_signal
        strategy.close("Long")

더 많은