
This strategy is a trading system based on moving average crossover signals and trend filtering. It combines short-term SMA crossover signals (9-period and 15-period) with a long-term EMA (200-period) as a trend filter to capture market trends across different timeframes. The system also includes a re-entry mechanism that allows for position rebuilding during trend continuation.
The strategy employs a triple moving average system for trading decisions: 1. Uses 9-period and 15-period Simple Moving Averages (SMA) for generating trading signals 2. Employs 200-period Exponential Moving Average (EMA) as a trend filter 3. Generates long signals when the short-term SMA (9-period) crosses above the 15-period SMA and price is above the 200-period EMA 4. Generates short signals when the short-term SMA (9-period) crosses below the 15-period SMA and price is below the 200-period EMA 5. Includes re-entry logic allowing new positions after initial crossover signals as long as price maintains position relative to the 200 EMA
This strategy builds a comprehensive trend-following trading system by combining multiple moving average systems with trend filters. Its main advantage lies in capturing significant profits in trending markets while improving stability through moving average filtering and re-entry mechanisms. Although inherent risks exist, implementing the optimization directions can further enhance strategy performance. The strategy is suitable for tracking medium to long-term market trends and serves as a reliable trading tool for patient traders.
/*backtest
start: 2024-02-19 00:00:00
end: 2025-02-17 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SMA Crossover with EMA Filter", overlay=true)
// Define indicators
sma9 = ta.sma(close, 9)
sma15 = ta.sma(close, 15)
ema200 = ta.ema(close, 200)
// Crossover conditions
bullish_crossover = ta.crossover(sma9, sma15) // Buy signal
bearish_crossover = ta.crossunder(sma9, sma15) // Sell signal
// Filters
above_ema200 = close > ema200
below_ema200 = close < ema200
// Buy condition (only above 200 EMA)
buy_signal = bullish_crossover and above_ema200
if buy_signal
strategy.entry("Buy", strategy.long)
// Sell condition (only below 200 EMA)
sell_signal = bearish_crossover and below_ema200
if sell_signal
strategy.entry("Sell", strategy.short)
// Exit condition if the signal reverses
exit_long = bearish_crossover
exit_short = bullish_crossover
if exit_long
strategy.close("Buy")
if exit_short
strategy.close("Sell")
// Re-entry condition when price crosses EMA 200 after a prior crossover
buy_reentry = ta.barssince(bullish_crossover) > 0 and above_ema200
sell_reentry = ta.barssince(bearish_crossover) > 0 and below_ema200
if buy_reentry
strategy.entry("Buy", strategy.long)
if sell_reentry
strategy.entry("Sell", strategy.short)
// Plot indicators
plot(sma9, color=color.blue, title="SMA 9")
plot(sma15, color=color.red, title="SMA 15")
plot(ema200, color=color.orange, title="EMA 200")