
이중 EMA 전략은 트렌드 추적 전략으로, 다른 주기의 EMA를 계산하여 가격의 트렌드 방향을 식별하여 포지션 또는 평소 포지션을 결정한다. 이 전략은 간단하고 실용적이며, 트렌드성이 강한 시장에 적용된다.
이 전략은 주로 두 개의 EMA 지표, 하나는 짧은 주기 9일 EMA, 다른 하나는 더 긴 주기 21일 EMA에 기초한다. 그들의 교차는 창고 및 창고 신호이다.
단기 EMA 상에서 장기 EMA를 통과할 때, 가격이 상승 추세에 진입한 것으로 간주되며, 이 전략은 이 때 더 많은 주문을 하고, 가격 상승을 추적한다. 단기 EMA 아래에서 장기 EMA를 통과할 때, 가격이 하향 추세에 진입한 것으로 간주되며, 이 전략은 이 때 공명 주문을 하고, 가격 하락을 추적한다.
이 EMA 지표는 가격 데이터의 잡음을 효과적으로 필터링하여 가격 트렌드의 주요 방향을 식별할 수 있습니다. 따라서 이 전략은 더 긴 가격 트렌드 사이클을 잡을 수 있기를 기대하여 쌍 EMA 지표를 포지션 및 포지션의 기초로 사용합니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
이 전략은 다음과 같은 측면에서 최적화될 수 있습니다.
이중 EMA 전략은 전체적으로 매우 실용적인 트렌드 추적 전략이다. 그것은 작동하기 쉽고 이해하기 쉽고 강한 트렌드 시장에서 우수한 성능을 발휘한다. 이 전략에는 또한 여러 차원에서 전략의 안정성을 향상시킬 수있는 몇 가지 위험이 있습니다.
/*backtest
start: 2023-02-21 00:00:00
end: 2024-02-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
// This can only draw so many lines. Use bar replay to go back further
strategy("Strategy Lines", shorttitle="Strategy Lines", overlay=true, max_lines_count=500)
//###########################################################################################################################################
// Replace your strategy here
//###########################################################################################################################################
shortEMA = ta.ema(close, input(9, title="Short EMA Length"))
longEMA = ta.ema(close, input(21, title="Long EMA Length"))
// Entry conditions for long and short positions
longCondition = ta.crossover(shortEMA, longEMA)
shortCondition = ta.crossunder(shortEMA, longEMA)
//###########################################################################################################################################
// Strategy Lines
//###########################################################################################################################################
var timeLow = bar_index
var line li = na
var openLPrice = 0.0000
var openSPrice = 0.0000
LongWColor = input.color(color.rgb(0,255,0,0),"Long Win Color", group="Strategy Lines")
LongLColor = input.color(color.rgb(0,0,255,0),"Long Loss Color", group="Strategy Lines")
ShortWColor = input.color(color.rgb(255,255,0,0),"Short Win Color", group="Strategy Lines")
ShortLColor = input.color(color.rgb(255,0,0,0),"Short Loss Color", group="Strategy Lines")
WinFontColor = input.color(color.rgb(0,0,0,0),"Win Font Color", group="Strategy Lines")
LossFontColor = input.color(color.rgb(255,255,255,0),"Loss Font Color", group="Strategy Lines")
LinesShowLabel = input(false,"Show Labels?",group = "Strategy Lines")
// // Start new line when we go long
// if strategy.position_size >0
// line.delete(li)
// li := line.new(timeLow, close[bar_index-timeLow], bar_index, close, width=2, color=close>openLPrice?LongWColor:LongLColor)
// // Start new line when we go short
// if strategy.position_size <0
// line.delete(li)
// li := line.new(timeLow, close[bar_index-timeLow], bar_index, close, width=2, color=close<openSPrice?ShortWColor:ShortLColor)
// //Delete Lines if we don't have a position open
// if strategy.position_size ==0
// li := line.new(timeLow, close[bar_index-timeLow], bar_index, close, width=2, color=color.rgb(0,0,0,100))
// line.delete(li)
if LinesShowLabel
// Short Label
if strategy.position_size>=0 and strategy.position_size[1] <0
label.new(
timeLow, na,
text=str.tostring((openSPrice-close[1])/(syminfo.mintick*10)),
color=close[1]<openSPrice?ShortWColor:ShortLColor,
textcolor=close[1]<openSPrice?WinFontColor:LossFontColor,
size=size.small,
style=label.style_label_down, yloc=yloc.abovebar)
// Long Label
if strategy.position_size<=0 and strategy.position_size[1] >0
label.new(
timeLow, na,
text=str.tostring((close[1]-openLPrice)/(syminfo.mintick*10)),
color=close[1]>openLPrice?LongWColor:LongLColor,
textcolor=close[1]>openLPrice?WinFontColor:LossFontColor,
size=size.small,
style=label.style_label_down, yloc=yloc.abovebar)
// Open long position and draw line
if (longCondition)
//strategy.entry("Long", strategy.long)
// timeLow := bar_index
// li := line.new(timeLow, close[bar_index-timeLow], bar_index, close, width=2, color=close>openLPrice?LongWColor:LongLColor)
openLPrice := close
// Open short position and draw line
if (shortCondition)
//strategy.entry("Short", strategy.short)
// timeLow := bar_index
// li := line.new(timeLow, close[bar_index-timeLow], bar_index, close, width=2, color=close<openSPrice?ShortWColor:ShortLColor)
openSPrice := close
//###########################################################################################################################################
// Strategy Execution (Replace this as well)
//###########################################################################################################################################
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)