Multiple Moving Average Crossover Trend Capture Strategy

SMA MA CROSSOVER CROSSUNDER LONG SHORT
Created on: 2025-02-20 11:31:18 Modified on: 2025-02-20 11:31:18
Copy: 0 Number of hits: 304
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 Multiple Moving Average Crossover Trend Capture Strategy  Multiple Moving Average Crossover Trend Capture Strategy

Overview

This strategy is a trading system based on the crossing signals of 1/2/4-period Simple Moving Averages (SMA). It captures market trend reversal points by observing the simultaneous crossing of short-period and medium-period moving averages over the long-period moving average, achieving trend following and timely stop-loss. The strategy design is concise, efficient, and easy to understand and implement.

Strategy Principle

The core of the strategy utilizes three SMAs of different periods (1/2/4), determining buy signals when both short-period (1-period) and medium-period (2-period) moving averages simultaneously cross above the long-period (4-period) moving average. Conversely, sell signals are generated when both shorter moving averages cross below the longer one. This multiple confirmation mechanism effectively reduces false signals and improves trading accuracy. In implementation, ta.crossover() and ta.crossunder() functions are used to detect crossovers, initiating long positions when buy conditions are met and short positions when sell conditions are satisfied.

Strategy Advantages

  1. Robust signal confirmation mechanism: requiring simultaneous crossing of two moving averages significantly reduces false signals
  2. Simple calculation logic: uses only simple moving averages, minimal computational load, high execution efficiency
  3. Flexible parameter settings: moving average periods can be adjusted according to different market characteristics
  4. Bi-directional trading: supports both long and short positions, fully capturing market opportunities
  5. Clear stop-loss mechanism: exits positions on reverse signals, providing explicit risk control

Strategy Risks

  1. Choppy market risk: may generate frequent false breakout signals in sideways markets
  2. Lag risk: moving averages have inherent lag, potentially missing optimal entry points
  3. Gap risk: price gaps may lead to suboptimal stop-loss execution
  4. Parameter sensitivity: different period combinations can yield significantly different results, requiring thorough testing

Strategy Optimization Directions

  1. Incorporate volume indicators: validate breakout effectiveness using volume changes
  2. Add trend filters: design trend identification modules to trade in the primary trend direction
  3. Optimize stop-loss mechanism: consider implementing trailing stops or volatility-based dynamic stops
  4. Enhance position management: dynamically adjust position sizes based on signal strength and market volatility
  5. Design signal confirmation: add price patterns and technical indicators as auxiliary confirmation mechanisms

Summary

This strategy captures market trends through multiple moving average crossovers, with clear design concepts and simple yet effective implementation. While it has certain lag and false signal risks, reasonable parameter optimization and supplementary indicators can build a more comprehensive trading system. The strategy offers strong extensibility and serves as an excellent foundation for further optimization and refinement.

Strategy source code
/*backtest
start: 2024-10-20 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy("1/2/4 Moving Average STR 1.0.0", overlay=true)


o_length = input(1, title="1 Closed")
t_length = input(2, title="2 Closed")
f_length = input(4, title="4 Closed")

// Calculate the simple moving averages.
ma_o = ta.sma(close, o_length)
ma_t = ta.sma(close, t_length)
ma_f = ta.sma(close, f_length)

// Plot the moving averages on the chart.
plot(ma_o, color=color.green, title="1 MA")
plot(ma_t, color=color.red, title="2 MA")
plot(ma_f, color=color.blue, title="4 MA")

// Assign the crossover and crossunder results to global variables.
crossover_o = ta.crossover(ma_o, ma_f)
crossover_t = ta.crossover(ma_t, ma_f)
crossunder_o = ta.crossunder(ma_o, ma_f)
crossunder_t = ta.crossunder(ma_t, ma_f)

// Generate signals based on the global crossover variables.
// Buy signal: both 1 and 2 SMAs cross over the 4 SMA on the same bar.
buy_signal = crossover_o and crossover_t
// Sell signal: both 1 and 2 SMAs cross under the 4 SMA on the same bar.
sell_signal = crossunder_o and crossunder_t

// Enter trades based on the signals.
// For a long position, enter on a buy signal and exit when a sell signal occurs.
if buy_signal
    strategy.entry("Long", strategy.long)
if sell_signal
    strategy.close("Long")

// For a short position, enter on a sell signal and exit when a buy signal occurs.
if sell_signal
    strategy.entry("Short", strategy.short)
if buy_signal
    strategy.close("Short")