
이 전략은 다중 시간 프레임 지수 이동 평균 (EMA) 과 200 주간 EMA 필터에 기반한 트렌드 추적 전략이다. 주요 아이디어는 상이한 시간 프레임의 EMA를 사용하여 시장의 트렌드 방향을 식별하고, 트렌드가 상승하고 가격이 200 주간 EMA 위에 있을 때 다중 위치를 설정하는 것이다.
전략은 5분, 15분, 30분 세 시간 프레임을 사용하여 각각 빠른 EMA와 느린 EMA를 계산한다. 각 시간 프레임의 빠른 EMA와 느린 EMA를 비교하여 그 시간 프레임의 트렌드 방향을 판단할 수 있다. 그리고 세 시간 프레임의 트렌드 신호를 합쳐서 통합 트렌드 신호를 얻는다.
이 전략은 여러 시간 프레임의 EMA를 비교하여 트렌드 방향을 판단하고, 200주기 EMA를 트렌드 필터로 사용하며, 트렌드가 명확하게 상승하고 가격이 장기 평균선 위에 있을 때 다중 포지션을 구축하여 강력한 상승세를 잡습니다. 엄격한 포지션 개시 조건과 고정된 스톱 스톱은 위험을 제어하는 데 도움이됩니다. 그러나 이 전략은 트렌드 전환점에 반응이 느려지고, 스톱 스톱은 고정되어 있으며, 시장의 급격한 변동에 대응할 때 제한이 있습니다. 미래에 전략의 적응성과 안정성을 향상시킬 수 있습니다. 더 많은 시간 프레임을 도입하고, 스톱 스톱을 최적화하고, 더 많은 거래 신호를 추가하고, 변수 최적화를 통해 시장 기회를 더 잘 파악하고 위험을 통제 할 수 있습니다.
/*backtest
start: 2023-05-17 00:00:00
end: 2024-05-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Multi-Timeframe Trend Following with 200 EMA Filter - Longs Only", shorttitle="MTF_TF_200EMA_Longs", overlay=true, initial_capital=1000, default_qty_type=strategy.fixed, default_qty_value=1)
// Inputs
fast_length = input.int(9, title="Fast EMA Length", minval=1)
slow_length = input.int(21, title="Slow EMA Length", minval=1)
filter_length_200 = input.int(200, title="200 EMA Length", minval=1)
stop_loss_perc = input.float(1.0, title="Stop Loss Percentage", minval=0.1) / 100
take_profit_perc = input.float(3.0, title="Take Profit Percentage", minval=0.1) / 100
// Calculate EMAs for 5-minute, 15-minute, and 30-minute timeframes
ema_fast_5min = request.security(syminfo.tickerid, "5", ta.ema(close, fast_length), lookahead=barmerge.lookahead_on)
ema_slow_5min = request.security(syminfo.tickerid, "5", ta.ema(close, slow_length), lookahead=barmerge.lookahead_on)
ema_fast_15min = request.security(syminfo.tickerid, "15", ta.ema(close, fast_length), lookahead=barmerge.lookahead_on)
ema_slow_15min = request.security(syminfo.tickerid, "15", ta.ema(close, slow_length), lookahead=barmerge.lookahead_on)
ema_fast_30min = request.security(syminfo.tickerid, "30", ta.ema(close, fast_length), lookahead=barmerge.lookahead_on)
ema_slow_30min = request.security(syminfo.tickerid, "30", ta.ema(close, slow_length), lookahead=barmerge.lookahead_on)
// Calculate 200 EMA for the 5-minute timeframe
ema_200_5min = ta.ema(close, filter_length_200)
// Determine the trend for each timeframe
trend_5min = ema_fast_5min > ema_slow_5min ? 1 : -1
trend_15min = ema_fast_15min > ema_slow_15min ? 1 : -1
trend_30min = ema_fast_30min > ema_slow_30min ? 1 : -1
// Combine trend signals
combined_trend = trend_5min + trend_15min + trend_30min
// Define entry and exit conditions with 200 EMA filter
enter_long = combined_trend == 3 and close > ema_200_5min
exit_long = combined_trend < 3 or close < ema_200_5min
// Plot EMAs for the 5-minute timeframe
plot(ema_fast_5min, color=color.blue, linewidth=2, title="Fast EMA 5min")
plot(ema_slow_5min, color=color.red, linewidth=2, title="Slow EMA 5min")
plot(ema_200_5min, color=color.green, linewidth=2, title="200 EMA 5min")
// Strategy execution
if (enter_long)
strategy.entry("Long", strategy.long, stop=close * (1 - stop_loss_perc), limit=close * (1 + take_profit_perc))
if (exit_long)
strategy.close("Long")