Strategy vault / Mean reversion
Moving Average and Relative Strength Index Strategy
This strategy combines two technical indicators: Moving Average (MA) and Relative Strength Index (RSI). It generates buy and sell signals based on the crossover of fast and slow moving averages and the…

Overview
This strategy combines two technical indicators: Moving Average (MA) and Relative Strength Index (RSI). It generates buy and sell signals based on the crossover of fast and slow moving averages and the overbought/oversold signals from RSI. A buy signal is generated when the fast moving average crosses above the slow moving average and RSI is above the oversold threshold. A sell signal is generated when the fast moving average crosses below the slow moving average or RSI is above the overbought threshold.
Strategy Principle
This strategy leverages the characteristics of moving averages and relative strength index. Moving averages can reflect the trend direction of prices. The fast moving average is more sensitive to price changes, while the slow moving average has a relatively lagging response. When the fast moving average crosses above the slow moving average, it indicates an upward price trend and a potential buying opportunity. Conversely, it indicates a downward price trend and a potential selling opportunity. The relative strength index measures the magnitude of price changes over a period of time. When RSI is above the overbought threshold (e.g., 70), it suggests that the market may be overheated and there is a risk of price pullback. When RSI is below the oversold threshold (e.g., 30), it suggests that the market may be overcooled and there is a chance of price rebound.
By combining the trend-following feature of moving averages and the overbought/oversold feature of relative strength index, this strategy can capture trending markets while avoiding some overbought/oversold risks. It is a quantitative strategy that incorporates both trend-following and mean-reversion approaches.
Strategy Advantages
- Simple and easy to use: The strategy logic is clear and only uses two common technical indicators, making it suitable for beginners in quantitative trading.
- Trend-following: By using the crossover of fast and slow moving averages, the strategy can trade in the direction of price trends.
- Risk control: The introduction of relative strength index as an auxiliary judgment helps control some overbought/oversold risks while trend trading.
- Adaptability: The parameters of moving averages and relative strength index can be optimized according to different market characteristics, providing good adaptability.
Strategy Risks
- Parameter sensitivity: The calculation period parameters of moving averages and relative strength index have a significant impact on the strategy performance. Different parameters may produce different results.
- Oscillating market risk: When the market exhibits wide-range oscillations, the strategy may generate more false signals, leading to increased losses.
- Trend reversal risk: When the market trend reverses, the strategy may experience consecutive losses.
- Ignoring fundamentals: The strategy is entirely based on price movements and does not consider the impact of macroeconomic factors, industry trends, and other fundamental factors.
Strategy Optimization Directions
- Parameter optimization: Conduct backtesting on historical data to find the optimal combination of moving average and relative strength index parameters to improve strategy stability.
- Trend filtering: Add long-term moving averages or price channels as trend filtering indicators. Confirm the major trend before trading to reduce false signals in oscillating markets.
- Stop-loss and take-profit: Set reasonable stop-loss and take-profit conditions to control single-trade risk and improve the strategy's risk-reward ratio.
- Position sizing: Dynamically adjust position sizes based on market trend strength, price volatility, and other factors to reduce drawdown during trend reversals.
- Multi-factor combination: Combine other technical indicators such as volume-price indicators and sentiment indicators to build a multi-factor model and enhance strategy robustness.
Summary
The Moving Average and Relative Strength Index strategy is a simple and practical quantitative trading strategy that captures market trends while controlling some risks through trend-following and overbought/oversold judgments. However, the strategy also has issues such as parameter sensitivity, oscillating market risks, and trend reversal risks. These problems need to be further addressed through parameter optimization, trend filtering, money management, and other methods. Additionally, quantitative traders need to flexibly adjust the strategy based on their risk preferences and market characteristics, and combine it with other signal factors to obtain more robust returns.
Source Pine Script
/*backtest
start: 2023-05-05 00:00:00
end: 2024-05-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © giancarlo_meneguetti
//@version=5
strategy("GM.MA.RSI.Stra", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Configurações para Médias Móveis
ema_short_length = input(9, title="EMA.9")
ema_long_length = input(21, title="EMA.21")
ema_short = ta.ema(close, ema_short_length)
ema_long = ta.ema(close, ema_long_length)
// Configurações para RSI
rsi_length = input(14, title="RSI.14")
rsi_upper_threshold = input(70, title="RSI>70")
rsi_lower_threshold = input(30, title="RSI<30")
rsi = ta.rsi(close, rsi_length)
// Sinais de Compra e Venda
// Sinal de Compra quando a EMA curta cruza acima da EMA longa e o RSI está acima do limite inferior
buy_signal = ta.crossover(ema_short, ema_long) and rsi > rsi_lower_threshold
// Sinal de Venda quando a EMA curta cruza abaixo da EMA longa ou o RSI está acima do limite superior
sell_signal = ta.crossunder(ema_short, ema_long) or rsi > rsi_upper_threshold
// Geração de Alertas
alertcondition(buy_signal, title="Sinal de Compra", message="A EMA curta cruzou acima da EMA longa e o RSI está acima do limite inferior. Considere comprar.")
alertcondition(sell_signal, title="Sinal de Venda", message="A EMA curta cruzou abaixo da EMA longa ou o RSI está acima do limite superior. Considere vender.")
// Execução da Estratégia
if buy_signal
strategy.entry("Compra", strategy.long)
if sell_signal
strategy.close("Venda")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-11. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Moving-Average-and-Relative-Strength-Index-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- BONK Multi Factor Trading StrategyPine Script · Mean reversion · 1d
- Chaikin Oscillator StrategyPine Script · Mean reversion · 3h