Overview
The Multi-Moving Average Trend Capture and Crossover Confirmation Trading System is a quantitative trading strategy based on a combination of multiple exponential moving averages (EMAs) of different periods, complemented by auxiliary indicators including Relative Strength Index (RSI), Moving Average Convergence Divergence (MACD), and Average True Range (ATR). The core of this strategy lies in determining market trend direction by comparing the relative positions of moving averages across different timeframes, entering positions when trends are clearly established, and exiting when trends weaken or reverse. The strategy features a specially designed multi-period trend confirmation mechanism that assesses trend strength and sustainability through the relative positions of short-term averages against medium and long-term averages, thereby improving win rates and stability.
Strategy Principles
The core principle of this strategy is to utilize multiple exponential moving averages (EMAs) of different periods to identify market trends and capture trading opportunities. The strategy employs five EMAs: instant average (14 periods), intermediate average (25 periods), short-term average (50 periods), medium-term average (100 periods), and long-term average (200 periods).
The main logic of the strategy is as follows:
Trend Determination Mechanism:
- Uptrend conditions: Instant EMA above short-term, medium-term, and long-term EMAs, with short-term EMA above medium-term EMA
- Downtrend conditions: Instant EMA below short-term, medium-term, and long-term EMAs, with short-term EMA below long-term EMA
Entry Signals:
- Long entry: When uptrend conditions are met and no position is currently open
- Short entry: When downtrend conditions are met, no position is currently open, and minimum ATR conditions are satisfied (sufficient market volatility)
Exit Signals:
- Long exit: When the instant EMA crosses below the short-term EMA
- Short exit: When the instant EMA crosses above the medium-term EMA
Risk Control:
- Uses the ATR indicator as a volatility filter, only executing short trades when volatility is sufficient (ATR greater than its average)
- Integrates RSI overbought and oversold levels as potential additional filters (though defined in the code but not currently utilized in the trading logic)
Position Tracking:
- The strategy uses boolean variables to track whether a position is currently open and the direction of the position (long or short)
Strategy Advantages
Multiple Moving Average Confirmation: By using multiple moving averages of different periods to jointly confirm trends, the strategy reduces false breakouts and erroneous signals, improving signal quality.
Precise Trend Identification: Compared to single moving average systems, multiple moving average systems can more accurately identify market trend turning points, especially when the relative position of the instant average changes in relation to other averages.
Flexible Risk Management: Different entry and exit criteria are applied to long and short positions, reflecting differentiated handling of risks in different market directions, with short trades requiring additional volatility filtering.
Visualized Trading Signals: The strategy clearly displays buy, sell, and exit points through graphical markers, facilitating backtesting analysis and real-time monitoring.
Trend Background Visualization: Using background colors to distinguish between uptrends and downtrends, providing an intuitive display of market conditions for traders to quickly assess the current market state.
Potential for Expansion: The strategy has already integrated RSI and MACD indicator calculations, which, although not currently used in the trading logic, provide a foundation for future optimization.
Parameter Adjustability: All key parameters can be controlled through inputs for adjustment, including moving average periods, RSI thresholds, MACD parameters, and ATR settings, making it convenient to optimize for different market environments and trading instruments.
Strategy Risks
Moving Average Lag: All systems based on moving averages have inherent lag, which may result in significant drawdowns in oscillating markets or during rapid reversals. Solutions include adjusting moving average periods or adding additional filters for oscillating market conditions.
Overtrading Risk: In oscillating markets, the instant moving average may frequently cross the short-term moving average, leading to excessive trading. This can be mitigated by introducing minimum holding periods or additional filters to reduce ineffective trades.
Market Adaptability Issues: Moving average strategies with fixed parameters tend to perform differently across various market environments and trading instruments. Parameters should be optimized for specific markets, or adaptive parameters should be considered.
Signal Conflicts: Although RSI and MACD indicators are calculated in the code, they are not effectively integrated into the trading logic, potentially leading to signal conflicts or missed optimization opportunities.
Long Bias: The current strategy applies different standards to long and short positions, with long positions not requiring volatility filtering while short positions must meet minimum ATR conditions, which may make the strategy more aggressive in bullish markets, increasing risk exposure.
Fixed Exit Mechanism: The strategy uses fixed technical indicator crossovers as exit points, lacking dynamic stop-loss and take-profit mechanisms that adjust according to market conditions, which may fail to effectively lock in profits or control risks.
Parameter Sensitivity: The strategy relies on multiple moving average period parameters, and small changes in these parameters can lead to significant differences in trading results, increasing the risk of overfitting.
Strategy Optimization Directions
Integrate Calculated Indicators: The strategy has already calculated RSI and MACD indicators but does not fully utilize them. RSI can be used to filter extreme market conditions, and MACD to confirm trend direction, improving signal quality. For example, requiring that RSI is not in overbought territory for long entries and not in oversold territory for short entries.
Dynamic Stop-Loss System: Introduce a dynamic stop-loss mechanism based on ATR, automatically adjusting stop-loss distances according to market volatility, enhancing risk management capabilities. This can be implemented by calculating entry points plus or minus a certain multiple of the ATR value.
Market State Classification: Add mechanisms to classify market states (trending vs. oscillating) and apply different trading strategies in different market states. For example, the slope of the long-term moving average or the ADX indicator can be used to assess trend strength.
Multi-Timeframe Analysis: Integrate trend information from higher timeframes, only trading when the trend direction aligns with higher timeframes, improving win rates.
Optimize Moving Average Parameters: The current strategy uses fixed moving average periods (14, 25, 50, 100, 200). Through backtesting different parameter combinations, optimal parameters for specific markets can be identified.
Volume Confirmation: Incorporate volume indicators to confirm trend strength, only trading in trends supported by volume, reducing losses from false breakouts.
Improve Entry Conditions: Optimize entry logic for both long and short positions to make them more symmetrical, or make more refined adjustments based on the characteristics of different market directions. For example, consider adding volatility filtering for long entries or adjusting the strictness of trend confirmation.
Add Time Filters: Incorporate trading time filters to avoid periods of high market volatility or poor liquidity, such as during important data releases or market opening/closing sessions.
Summary
The Multi-Moving Average Trend Capture and Crossover Confirmation Trading System is a quantitative trading strategy based on technical analysis that uses a combination of multiple moving averages of different periods to identify market trends, entering positions when trends are clearly established and exiting when trends weaken. The core advantage of the strategy lies in using multiple moving average crossovers to confirm trends, reducing erroneous signals and improving trading quality.
This strategy performs well in markets with clear trends but may face risks of overtrading in oscillating markets. By integrating the already calculated RSI and MACD indicators, introducing dynamic stop-loss mechanisms, optimizing moving average parameter combinations, and adding market state classification, the stability and adaptability of the strategy can be further enhanced.
For practical application, it is recommended to first conduct thorough backtesting across different market environments and trading instruments, adjusting parameters to adapt to specific market characteristics, and combining with money management strategies to control single-trade risk. Additionally, consider using this strategy as part of an investment portfolio, combined with other complementary strategies to diversify trading risk and improve overall portfolio stability.
Strategy source code
/*backtest
start: 2025-02-23 00:00:00
end: 2025-03-02 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("etude9", shorttitle="etude 9", overlay=true)
//we try to combine with the RSi a strategy that is not so bad on the long side
// a d7 r rsi which gives indications not bad for the shorts for the longs not very conclusive
// === Input parameters ===
// Price source
// and shit long term performance is more efficient without condition on ATR!!
// on the other hand I have the impression that the RSI will be good for shorts
// Well, with the RSi it doesn't give anything, and with the MACD, at this stage it's crap mmm
pricetype = input(close, title="Source de prix pour les moyennes mobiles")
// Moving Average Periods
instant = input(14, title="Instantaneous average period (10)")
interm = input(25, title="Intermediate period (25)")
shortperiod = input(50, title="Short Moving Average Period (20)")
mediumperiod = input(100, title="Moving Average Period (50)")
longperiod = input(200, title="Long Moving Average Period (100)")
// RSI parameters
rsi_length = input.int(14, title="RSI period")
rsi_overbought = input.int(78, title="Overbought level (RSI)")
rsi_oversold = input.int(30, title="Oversold level (RSI)")
// Parameters for MACD
fast_length = input.int(12, title="MACD Fast Length")
slow_length = input.int(26, title="MACD Slow Length")
signal_length = input.int(9, title="MACD Signal Length")
// ATR parameters
atr_length = input.int(14, title="ATR period")
atr_multiplier = input.float(1.5, title="ATR Multiplier for Stop-Loss")
// ATR calculation
atr = ta.atr(atr_length)
// === Calculating Moving Averages (EMA only) ===
instant_ma = ta.ema(pricetype, instant) // Instantaneous moving average
short_ma = ta.ema(pricetype, shortperiod) // Short Moving Average (20)
medium_ma = ta.ema(pricetype, mediumperiod) // Moving Average (50)
long_ma = ta.ema(pricetype, longperiod) // Long Moving Average (100)
interm_ma = ta.ema(pricetype, interm)
// RSI calculation
rsi = ta.rsi(close, rsi_length)
// MACD calculation
[macd_line, signal_line, hist_line] = ta.macd(close, fast_length, slow_length, signal_length)
// Store crossover and crossunder results in global variables
is_crossover = ta.crossover(macd_line, signal_line)
is_crossunder = ta.crossunder(macd_line, signal_line)
// ATR filter: we only trade if the volatility is sufficient
min_atr = atr > ta.sma(atr, atr_length) // ATR above its average
// === Trend conditions ===
trending_up = instant_ma > short_ma and instant_ma > medium_ma and instant_ma > long_ma and short_ma > medium_ma // Upward trend
trending_down = instant_ma< short_ma and instant_ma<medium_ma and instant_ma<long_ma and short_ma<long_ma // Downward trend
// RSI Filters
rsi_filter_buy = rsi < rsi_overbought // RSI is not overbought for a buy
rsi_filter_sell = rsi > rsi_oversold // RSI is not oversold for a sell
// === Position management ===
var bool in_position = false // Variable to track if a position is open
var bool is_long = false // Variable to track whether the position is long or short
// === Opening and closing signals ===
bool buy_signal = false // Signal to open a long position
bool close_signal = false // Signal to close a long position
bool sell_signal = false // Signal to open a short position
bool close_short_signal = false // Signal to close a short position
// Open a long position
if (trending_up and not in_position)
strategy.entry("Long", strategy.long)
in_position := true
is_long := true
buy_signal := true // Opening signal
else
buy_signal := false
// Close long position if instant_ma < medium_ma
if (in_position and is_long and instant_ma < short_ma)
strategy.close("Long")
in_position := false
is_long := false
close_signal := true // Signal de fermeture
else
close_signal := false
// Open a short position
if (trending_down and not in_position and min_atr)
strategy.entry("Short", strategy.short)
in_position := true
is_long := false
sell_signal := true // Opening signal
else
sell_signal := false
// Close short position if instant_ma > medium_ma
if (in_position and not is_long and instant_ma > medium_ma)
strategy.close("Short")
in_position := false
close_short_signal := true // Closing signal
else
close_short_signal := false
// === Displaying signals on the chart ===
plotshape(series=buy_signal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy", size=size.small)
plotshape(series=sell_signal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell", size=size.small)
plotshape(series=close_signal, title="Close Long Signal", location=location.abovebar, color=color.orange, style=shape.labeldown, text="Close Long", size=size.small)
plotshape(series=close_short_signal, title="Close Short Signal", location=location.belowbar, color=color.blue, style=shape.labelup, text="Close Short", size=size.small)
// === Displaying moving averages on the chart ===
plot(short_ma, color=color.blue, title="Moyenne mobile courte (20)", linewidth=2)
plot(medium_ma, color=color.orange, title="Moyenne mobile moyenne (50)", linewidth=2)
plot(long_ma, color=color.red, title="Moyenne mobile longue (100)", linewidth=2)
plot(instant_ma, color=color.rgb(43, 14, 111), title="Moyenne mobile instantanée (10)", linewidth=2)
plot(interm_ma, color=color.rgb(26, 192, 34), title="Moyenne mobile instantanée (10)", linewidth=2)
// Background coloring for trends
bgcolor(color=trending_up ? color.new(color.green, 90) : trending_down ? color.new(color.red, 90) : na, title="Coloration de fond")
Strategy Parameters
The original address: Multi-Moving Average Trend Capture and Crossover Confirmation Trading System