10EMA 이중 횡단 트렌드 추적 전략

저자:차오장, 날짜: 2023-12-29 16:03:55
태그:

img

전반적인 설명

이 전략은 10EMA와 50EMA의 이중 교차에 기반한 트렌드 추적 전략입니다. 10EMA를 시간 차트에 보조 판단으로 통합하여 번갈아진 황소 및 곰 시장에서 동적으로 트렌드 방향을 찾고 자동 추적 스톱 손실을 달성합니다.

전략 원칙

전략의 핵심 논리는 10EMA와 50EMA의 황금 십자가와 죽음의 십자가에 기반합니다. 구체적으로, 10EMA가 50EMA를 넘어서 황금 십자가를 형성하면 시장이 상승 추세로 들어갔다고 판단됩니다. 10EMA가 50EMA를 넘어서 사망 십자가를 형성하면 시장이 하락 추세로 들어갔다고 판단됩니다.

골든 크로스 또는 데스 크로스 이후 1-5 바 내로 긴 또는 짧은 포지션을 오픈하십시오. 또한 전략은 보조 판단으로 시간 차트에서 10EMA를 도입합니다. 시간 차트에서 10EMA가 황금 크로스 이후 상승 추세에 있을 때만 긴 포지션을 오픈하고 시간 차트에서 10EMA가 죽음의 크로스 이후에 하락 추세에 있을 때만 짧은 포지션을 오픈하여 일부 잘못된 신호를 필터링합니다.

포지션을 열었을 때 전략은 스톱 로스 + 리미드 오더를 추적하는 수익 취득 및 스톱 로스 방법을 채택합니다. 스톱 로스를 추적하면 수익을 잠금하고 거래의 수익성을 극대화 할 수 있습니다. 리미드 오더는 가격이 수익을 얻기 위해 목표에 도달하면 포지션이 닫히는 것을 보장합니다.

이점 분석

이 전략의 가장 큰 장점은 주요 트렌드 방향을 판단하기 위해 EMA 크로스를 사용하는 동시에 신호를 필터하기 위해 보조 지표를 도입하여 신호 신뢰성을 향상시키기 위해 잘못된 크로스를 효과적으로 필터 할 수 있다는 것입니다. 또한, 트레일링 스톱 로스와 리미트 노프트 테킹과 결합된 이중 EMA 크로스는 트렌드 트래킹 이윤을 극대화하고 전반적으로 좋은 리스크-어워드 비율로 거래 위험을 효과적으로 제어 할 수 있습니다.

단일 지표 전략과 비교하면 이 전략은 트렌드 방향과 진폭을 보다 정확하게 판단할 수 있다. 전통적인 스톱 로스와 비교하면 이 전략은 수익을 더 잘 확보하기 위해 더 고급 스톱 로스 추적 기술을 채택한다.

위험 분석

이 전략의 주요 위험은 간헐적 인 윙사와 트렌드 역전입니다. 연속적인 잘못된 교차 신호가 발생하면 전략이 폐기 될 수 있습니다. 또한, 포지션을 열고 후 가격 역전도 손실로 이어질 수 있습니다.

윙사 (whipsaws) 의 위험을 줄이기 위해 신호를 필터하기 위해 보조 지표가 추가됩니다. 트렌드 역전 위험을 제어하기 위해 상대적으로 관용적인 스톱 로스 범위가 채택되며 제한 이익 설정 또한이이 위험을 줄이는 데 도움이됩니다. 스톱 로스가 활성화되면 트렌드 방향으로 다시 입력하는 것도 가능합니다.

최적화 방향

이 전략에 대한 최적화 방향은 여러 가지가 있습니다. 첫째, 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

더 많은