
이 전략은 두 개의 이동 평균 (EMA) 의 교차를 기반으로 거래 신호를 생성한다. 단기 EMA (20일) 가 아래에서 위쪽으로 긴 EMA (50일) 를 통과하면 구매 신호를 생성한다. 단기 EMA가 위쪽으로 아래로 긴 EMA를 통과하면 판매 신호를 생성한다. 동시에, 이 전략은 200일 EMA를 장기 추세에 대한 참조로 도출한다. 이 전략의 주요 아이디어는 다른 주기 이동 평균의 교차를 사용하여 시장 추세의 변화를 포착하여 거래를 수행하는 것이다.
EMA 쌍평평선 교차 전략은 트렌드 시장에 적합한 간단한 거래 전략이다. 그것은 단기 및 장기 이동 평균의 교차를 사용하여 시장 추세의 변화를 포착하고 장기 트렌드 레퍼런스를 도입한다. 이 전략은 흔들리는 시장에서 좋지 않은 성과와 이동 평균의 후진성과 같은 몇 가지 제한이 있음에도 불구하고, 다른 지표, 최적화 매개 변수, 위험 제어 조치 등을 도입함으로써 전략의 안정성과 수익성을 더욱 향상시킬 수 있다.
/*backtest
start: 2023-03-23 00:00:00
end: 2024-03-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover Strategy by Peter Gangmei", overlay=true)
// Define the length for moving averages
short_ma_length = input.int(20, "Short MA Length")
long_ma_length = input.int(50, "Long MA Length")
long_ma_200_length = input.int(200, "Long MA 200 Length")
// Define start time for testing
start_time = timestamp(2024, 01, 01, 00, 00)
// Calculate current date and time
current_time = timenow
// Calculate moving averages
ema20 = ta.ema(close, short_ma_length)
ema50 = ta.ema(close, long_ma_length)
ema200 = ta.ema(close, long_ma_200_length)
// Crossing conditions
crossed_above = ta.crossover(ema20, ema50)
crossed_below = ta.crossunder(ema20, ema50)
// Entry and exit conditions within the specified time frame
if true
if (crossed_above)
strategy.entry("Buy", strategy.long)
alert("Buy Condition", alert.freq_once_per_bar_close)
if (crossed_below)
strategy.entry("Sell", strategy.short)
alert("Sell Condition", alert.freq_once_per_bar_close)
// Plotting moving averages for visualization
plot(ema20, color=color.green, title="EMA20")
plot(ema50, color=color.red, title="EMA50")
plot(ema200, color=color.blue, title="EMA200")
// Placing buy and sell markers
plotshape(series=crossed_above, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(series=crossed_below, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")