This strategy is a trend-following strategy based on multi-timeframe Exponential Moving Averages (EMAs) and a 200-period EMA filter. The main idea is to use EMAs on different timeframes to identify the market trend direction and establish long positions when the trend is up and the price is above the 200-period EMA. This ensures that trades are only entered during strong uptrends, aiming to capture sustained upward movements while managing risk with defined stop-loss and take-profit mechanisms.
The strategy uses three timeframes: 5-minute, 15-minute, and 30-minute, calculating fast and slow EMAs for each. By comparing the fast and slow EMAs for each timeframe, the trend direction can be determined. The trend signals from the three timeframes are then summed to obtain a combined trend signal. When the combined trend signal is 3 (indicating an uptrend across all timeframes) and the current closing price is above the 200-period EMA on the 5-minute timeframe, the strategy enters a long position. The position is closed when the combined trend signal falls below 3 or the price drops below the 5-minute 200-period EMA.
This strategy determines the trend direction by comparing EMAs on multiple timeframes while using a 200-period EMA as a trend filter. It establishes long positions when the trend is clearly upward and the price is above the long-term moving average, aiming to capture strong uptrends. Strict entry and exit conditions and fixed stop-loss and take-profit levels help manage risk. However, the strategy may react slowly at trend turning points and has limitations in dealing with sudden market volatility due to fixed stop-loss and take-profit levels. In the future, the strategy’s adaptability and robustness can be improved by introducing more timeframes, optimizing stop-loss and take-profit levels, incorporating additional trading signals, optimizing parameters, etc. This will enable the strategy to better seize market opportunities while controlling risks.
/*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")