该策略是一个基于多时间框架指数移动平均线(EMA)和200期EMA过滤器的趋势跟踪策略。它的主要思路是利用不同时间框架的EMA来识别市场的趋势方向,并在趋势向上且价格在200期EMA之上时建立做多头寸。这样可以确保只在强势上涨趋势中进行交易,以把握持续的上涨行情,同时利用止损和止盈机制来控制风险。
策略使用5分钟、15分钟和30分钟三个时间框架,分别计算快速EMA和慢速EMA。通过比较每个时间框架的快速EMA和慢速EMA,可以判断该时间框架的趋势方向。然后将三个时间框架的趋势信号加总,得到一个综合的趋势信号。当综合趋势信号为3(即所有时间框架都是上涨趋势)且当前收盘价在5分钟200期EMA之上时,策略开仓做多;当综合趋势信号小于3或者价格跌破5分钟200期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")