
## 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.
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:
Entry Signals:
Exit Signals:
Risk Control:
Position Tracking:
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.
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.
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.
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.
/*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)
//on tente de comlbiner avec le RSi un stratégie pas si mauvaise sur les longs
// un d7 r rsi qui donne des indiciataions pas mal pour les short pour les long pas très concluant
// === Paramètres d'entrée ===
// Source de prix
// et merde rendement sur long est plus efficace sans condition sur ATR !!
// par contre j'ai l'imression que le rsi ça va être bien pour les shorts
// bon avec le RSi ça donne rien, et avec le macd, ç ce stade c'est foireux mmm
pricetype = input(close, title="Source de prix pour les moyennes mobiles")
// Périodes des moyennes mobiles
instant = input(14, title="Période de la moyenne instantanée (10)")
interm = input(25, title="Perdiode intermediaire (25)")
shortperiod = input(50, title="Période de la moyenne mobile courte (20)")
mediumperiod = input(100, title="Période de la moyenne mobile moyenne (50)")
longperiod = input(200, title="Période de la moyenne mobile longue (100)")
// Paramètres du RSI
rsi_length = input.int(14, title="Période RSI")
rsi_overbought = input.int(78, title="Niveau de surachat (RSI)")
rsi_oversold = input.int(30, title="Niveau de survente (RSI)")
// Paramètres pour le MACD
fast_length = input.int(12, title="Longueur Rapide MACD")
slow_length = input.int(26, title="Longueur Lente MACD")
signal_length = input.int(9, title="Longueur du Signal MACD")
// Paramètres de l'ATR
atr_length = input.int(14, title="Période ATR")
atr_multiplier = input.float(1.5, title="Multiplicateur ATR pour le Stop-Loss")
// Calcul de l'ATR
atr = ta.atr(atr_length)
// === Calcul des moyennes mobiles (EMA uniquement) ===
instant_ma = ta.ema(pricetype, instant) // Moyenne mobile instantanée
short_ma = ta.ema(pricetype, shortperiod) // Moyenne mobile courte (20)
medium_ma = ta.ema(pricetype, mediumperiod) // Moyenne mobile moyenne (50)
long_ma = ta.ema(pricetype, longperiod) // Moyenne mobile longue (100)
interm_ma = ta.ema(pricetype, interm)
// Calcul du RSI
rsi = ta.rsi(close, rsi_length)
// Calcul du MACD
[macd_line, signal_line, hist_line] = ta.macd(close, fast_length, slow_length, signal_length)
// Stocker les résultats de crossover et crossunder dans des variables globales
is_crossover = ta.crossover(macd_line, signal_line)
is_crossunder = ta.crossunder(macd_line, signal_line)
// Filtre ATR : on ne trade que si la volatilité est suffisante
min_atr = atr > ta.sma(atr, atr_length) // ATR supérieur à sa moyenne
// === Conditions de tendance ===
trending_up = instant_ma > short_ma and instant_ma > medium_ma and instant_ma > long_ma and short_ma > medium_ma // Tendance haussière
trending_down = instant_ma< short_ma and instant_ma<medium_ma and instant_ma<long_ma and short_ma<long_ma // Tendance baissière
// Filtre RSI
rsi_filter_buy = rsi < rsi_overbought // RSI n'est pas en surachat pour un achat
rsi_filter_sell = rsi > rsi_oversold // RSI n'est pas en survente pour une vente
// === Gestion des positions ===
var bool in_position = false // Variable pour suivre si une position est ouverte
var bool is_long = false // Variable pour suivre si la position est longue ou courte
// === Signaux d'ouverture et de fermeture ===
bool buy_signal = false // Signal d'ouverture d'une position longue
bool close_signal = false // Signal de fermeture d'une position longue
bool sell_signal = false // Signal d'ouverture d'une position courte
bool close_short_signal = false // Signal de fermeture d'une position courte
// Ouvrir une position longue
if (trending_up and not in_position)
strategy.entry("Long", strategy.long)
in_position := true
is_long := true
buy_signal := true // Signal d'ouverture
else
buy_signal := false
// Fermer la position longue si 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
// Ouvrir une position courte
if (trending_down and not in_position and min_atr)
strategy.entry("Short", strategy.short)
in_position := true
is_long := false
sell_signal := true // Signal d'ouverture
else
sell_signal := false
// Fermer la position courte si 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 // Signal de fermeture
else
close_short_signal := false
// === Affichage des signaux sur le graphique ===
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)
// === Affichage des moyennes mobiles sur le graphique ===
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)
// Coloration de fond pour les tendances
bgcolor(color=trending_up ? color.new(color.green, 90) : trending_down ? color.new(color.red, 90) : na, title="Coloration de fond")