10EMA 더블 크로스오버 추세 추종 전략


생성 날짜: 2023-12-29 16:03:55 마지막으로 수정됨: 2023-12-29 16:03:55
복사: 1 클릭수: 807
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

10EMA 더블 크로스오버 추세 추종 전략

개요

이 전략은 10 EMA와 50 EMA의 이중 교차에 기반한 트렌드 추적 전략이다. 그것은 시계줄의 10 EMA를 보조 판단으로 결합하여, 불과 곰이 교대하는 시장에서 동적으로 트렌드 방향을 찾아, 자동 추적 스톱을 구현한다.

전략 원칙

전략의 핵심 논리는 10 EMA와 50 EMA의 골드포크 사각지대에 기반한다. 구체적으로, 10 EMA가 아래에서 50 EMA를 가로질러 골드포크를 형성할 때, 상향 추세로 진입한다고 판단하고; 10 EMA가 위에서 아래에서 50 EMA를 가로질러 사각지대를 형성할 때, 하향 추세로 진입한다고 판단한다.

골드포크 사다리 후 1-5 K선 안에 포지션을 열고 더 많은 공백을 한다. 또한, 전략은 시간선의 10EMA를 보조 판단으로 도입하여, 시간선의 10EMA가 상승 추세에 있을 때만 골드포크 뒤에 포지션을 열고, 시간선의 10EMA가 하락 추세에 있을 때만 사다리 뒤에 포지션을 열고, 따라서 일부 가짜 신호를 필터링한다.

포지션 개시 후, 전략은 스톱 손실 + 제한 가격 정지를 추적하는 출구 방식을 채택한다. 스톱 손실은 수익을 잠금하고 거래 수익을 최대화 할 수 있습니다. 제한 가격 정지는 가격이 목표 지점에 도달했을 때 거래를 폐쇄하여 수익을 얻을 수 있습니다.

전략적 이점

이 전략의 가장 큰 장점은 메인 트렌드 방향을 판단하는 동시에 EMA 교차를 이용하는 것과 보조 지표 필터링 신호를 도입하는 것입니다. 이 전략은 가짜 교차를 효과적으로 필터링하여 신호의 신뢰성을 향상시킬 수 있습니다. 이중 EMA 교차는 트렌드 추적의 이익을 극대화하고 트렌드 추적의 위험을 효과적으로 제어 할 수 있습니다.

단일 지표 전략에 비해, 이 전략은 트렌드 방향과 진폭을 더 정확하게 판단할 수 있다. 전통적인 스톱 스팟에 비해, 이 전략은 더 진보된 추적 스톱 스팟 기술을 사용하여, 이익을 더 잘 고정시킬 수 있다.

위험 분석

이 전략은 주로 간헐적인 위프사우와 트렌드 반전의 위험에 직면합니다. 연속적인 가짜 교차 신호가 발생하면 전략이 중매 될 수 있습니다. 또한, 포지션 개설 후 가격 반전은 손실을 초래합니다.

휘프사우의 위험을 줄이기 위해, 전략은 보조 지표에 신호 필터링을 추가한다. 트렌드 반전의 위험을 제어하기 위해, 전략은 좀 더 관용적 인 중지 범위를 채택하고, 가격 제한 스톱 설정은 이러한 위험을 줄이는 데 도움이 될 수 있습니다.

최적화 방향

이 전략에는 몇 가지 최적화 가능한 방향이 있습니다: 첫째, EMA 주기, 포지션 개시 지연 루트 등과 같은 다양한 파라미터 조합을 테스트하여 최적의 파라미터를 찾을 수 있습니다. 둘째, MACD, BOLL 등과 같은 더 많은 보조 지표를 도입하여 신호 필터링을 수행하여 신호 품질을 향상시킬 수 있습니다. 셋째, 시간적 손실, 진동적 손실 등과 같은 다른 손실을 막는 논리를 최적화 할 수 있습니다. 넷째, 특정 기간이나 상승 하락 아래에서만 신호를 유발하는 것과 같은 더 많은 여건의 조건으로 거래를 시작하는 전략과 결합 할 수 있습니다.

요약하다

10EMA 이중 교차 트렌드 추적 전략은 EMA 골든 크로스 및 데스 크로스를 통해 현재 트렌드 방향을 판단하고, 추적 스톱 및 제한 스톱을 설정하여 수익을 잠금하고 위험을 제어하며, 보조 지표 필터링 신호와 결합하여 신호 품질을 향상시키는 것이 더 완벽한 트렌드 거래 전략입니다. 단일 지표와 전통적인 스톱 스톱의 장점과 비교하여 판단 정확도, 스톱 스톱 손실 최적화, 트렌드 수익을 효과적으로 얻을 수 있는 동시에 위험을 제어하는 전략은 일반 거래 계좌에 적합합니다. 물론 이 전략에는 개선의 여지가 있으며, 변수 최적화, 더 많은 보조 지표 등을 추가하여 전략을 더욱 강화 할 수 있습니다.

전략 소스 코드
/*backtest
start: 2022-12-22 00:00:00
end: 2023-12-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("10ema Strat 9", overlay=true, format=format.price)
//#region // inputs for candles
//time
t1 = time(timeframe.period,"0930-1500") //last hour of market is not ideal for trading
// candle status
bullish = close > open and barstate.isconfirmed
bearish = open > close and barstate.isconfirmed
bullcandle = ta.valuewhen(bullish, close, 0)
bearcandle = ta.valuewhen(bearish, close, 0)
ema1 = input.int(10, minval=1, title="short ema")
ema2 = input.int(50, minval=1, title="long ema")
ema3 = input.int(200, minval=1, title="hourly 10 ema")
//@variable Input for source
src = input(close, title="Source")
offsetema = input.int(title="Offset", defval=0, minval=-500, maxval=500)
sema = ta.ema(src, ema1)//@variable Input for smaller ema1
lema = ta.ema(src, ema2)//@variable Input for longer ema2
hema = ta.ema(src, ema3)// @variable Input for hourly ema3
bullcrosscount = ta.barssince(ta.crossover(sema,lema)) //@variable Input 10/50 cross higher
bearcrosscount = ta.barssince(ta.crossunder(sema,lema)) //@variable Input 10/50 cross lower
ideallong = bullcrosscount <= 5 //number of candles after the cross
idealshort = bearcrosscount <= 5 //number of candles after the cross

emabull = (sema > lema) and bearish and close > sema and close > hema and ideallong and t1 and barstate.isconfirmed
xemabull = ta.barssince(emabull)
dbullema = emabull and emabull[1] and xemabull <=1
bullentry = if dbullema
    ta.valuewhen(emabull[1], high + 0.05, 0)
else 
    ta.valuewhen(emabull, high + 0.05, 0)
bullentryh = dbullema ? bullentry[1] : bullentry
bullentrylow = ta.valuewhen(emabull, low - 0.05, 0)
bullstop = (bullentryh - bullentrylow) <= 1.00 ? bullentryh - 1.00 : (bullentryh - bullentrylow) <= 10.40 ? bullentrylow : na
bulltarget = (bullentryh - bullstop) * 1.62 + bullentryh

// bear setup
emabear = (sema < lema) and bullish and close < sema and close < hema and idealshort and t1 and barstate.isconfirmed
xemabear = ta.barssince(emabear)
dbearema = emabear and emabear [1] and xemabear <=1
bearentry = if dbearema
    ta.valuewhen(emabear[1], low - 0.05, 0)
else
    ta.valuewhen(emabear, low - 0.05, 0)
bearentryh = dbearema ? bearentry[1] : bearentry
bearentryhigh = ta.valuewhen(emabear, high + 0.05, 0)
bearstop = (bearentryhigh - bearentryh) <= 1.00 ? bearentryh + 1.00 : (bearentryh - bearentryhigh) <= 10.40 ? bearentryhigh : na
beartarget = bearentryh - (bearstop-bearentryh) * 1.62

bullclose = (xemabull <=7) and bullish and bullcrosscount >=1 and barstate.isconfirmed //number of candles for a close above
bearclose = (xemabear <=7) and bearish and bearcrosscount >=1 and barstate.isconfirmed //number of candles for a close below
buyzone = ta.barssince(bullclose)
shortzone =  ta.barssince(bearclose)
idealbuy = close >= bullentryh and bullclose and (buyzone<=7)
idealsell = close <= bearentryh and bearclose and (shortzone<=7)

// // bull setup on chart
// if sema > lema and xemabull < 50
//     var line line_bullentry = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(0, 200, 0), style=line.style_solid, width=1)
//     if emabull
//         line.set_xy1(line_bullentry, x=bar_index, y=bullentryh)
//         line.set_xy2(line_bullentry, x=bar_index, y=bullentryh)
//         alert("EMA-bullish", alert.freq_once_per_bar_close)
//     line.set_x2(line_bullentry, x=bar_index)
//     var line line_bullstop = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(250, 0, 0), style=line.style_solid, width=1)
//     if emabull
//         line.set_xy1(line_bullstop, x=bar_index, y=bullstop)
//         line.set_xy2(line_bullstop, x=bar_index, y=bullstop)
//     line.set_x2(line_bullstop, x=bar_index)    
//     var line line_bulltarget = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(200, 100, 200), style=line.style_solid, width=1)
//     if emabull
//         line.set_xy1(line_bulltarget, x=bar_index, y=bulltarget)
//         line.set_xy2(line_bulltarget, x=bar_index, y=bulltarget)
//     line.set_x2(line_bulltarget, x=bar_index)

// //bear setup on chart
// if sema < lema and xemabear < 50
//     var line line_bearentry = line.new(bar_index, na, bar_index, na, color=color.rgb(0, 200, 0), style=line.style_solid, width=1)
//     if emabear
//         line.set_xy1(line_bearentry, x=bar_index, y=bearentryh)
//         line.set_xy2(line_bearentry, x=bar_index, y=bearentryh)
//         alert("EMA-bearish", alert.freq_once_per_bar_close)
//     line.set_x2(line_bearentry, x=bar_index)
//     var line line_bearstop = line.new(bar_index, na, bar_index, na, color=color.rgb(250, 0, 0), style=line.style_solid, width=1)
//     if emabear
//         line.set_xy1(line_bearstop, x=bar_index, y=bearstop)
//         line.set_xy2(line_bearstop, x=bar_index, y=bearstop)
//     line.set_x2(line_bearstop, x=bar_index)
//     var line line_beartarget = line.new(bar_index, na, bar_index, na, color=color.rgb(200, 100, 200), style=line.style_solid, width=1)
//     if emabear
//         line.set_xy1(line_beartarget, x=bar_index, y=beartarget)
//         line.set_xy2(line_beartarget, x=bar_index, y=beartarget)
//     line.set_x2(line_beartarget, x=bar_index)

//#endregion
//execution 
if idealbuy
    strategy.close("sell", comment=na)	
    strategy.entry("buy", strategy.long, limit=bullentryh, stop=bullstop, comment="buy")
strategy.exit("exit","buy", trail_points = low, trail_offset = 5, qty_percent=100, limit=bulltarget, stop=bullstop)

if idealsell
	strategy.close("buy",comment=na)
    strategy.entry("sell", strategy.short, limit=bearentryh, stop=bearstop, comment="sell")
strategy.exit("exit","sell", trail_points = low, trail_offset = 5, qty_percent=100, limit=beartarget, stop=bearstop)
// strategy.close_all(time == close_day) 
//#region // graphical analysis
//Plots
plotshape(emabull, location=location.belowbar, title='emabull')
plotshape(idealbuy, style=shape.circle, color=color.green, title="bull close")
plotshape(emabear, title='emabear')
plotshape(idealsell, location=location.belowbar, style=shape.circle, color=color.red, title="bear close")

// //Dashboard
// var label id = na
// label.delete(id)   // Delete last label
// i_offsetLabel = input(15, "Data Dashboard Offset") 
// offset = i_offsetLabel * (time - time[1])
// dynamicText = "= Bull Setup ="
// id := label.new(x=time + offset, y=open, xloc=xloc.bar_time, text=dynamicText, color=color.rgb(255, 255, 255), size=size.normal)
// label.set_textcolor(id, color.rgb(0, 0, 0))
// label.set_text(id=id, text=dynamicText)
// label.set_textalign(id, text.align_left)
// label.set_text(id=id, text=dynamicText)
// f_round( _val, _decimals) => 
//     _p = math.pow(10, _decimals)
//     math.round(math.abs(_val) * _p) / _p * math.sign(_val)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bulltarget,2)) + "  :Target"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bullentryh,2)) + "  :Entry"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bullstop,2)) + "  :Stop"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + "= Bear Setup ="
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bearstop,2)) + "  :Stop"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bearentryh,2)) + "  :Entry"
// label.set_text(id=id, text=dynamicText)
// dynamicText := dynamicText + "\n" + str.tostring(f_round(beartarget,2)) + "  :Target"
// label.set_text(id=id, text=dynamicText)
// //#endregion