DEV Community

FMZQuant
FMZQuant

Posted on

Mean Reversion RSI(2) Momentum Breakout Trading Strategy with Moving Average Trend Filter

Overview
The Mean Reversion RSI(2) Momentum Breakout Trading Strategy with Moving Average Trend Filter is a quantitative trading system that combines short-term oversold indicators with long-term trend confirmation. This strategy primarily utilizes the extremely short-period (2-day) Relative Strength Index (RSI) to identify oversold market conditions, while incorporating a 200-day moving average as a trend filter to ensure trades are only executed within an overall uptrend. The strategy features a clearly defined profit target (the highest price of the previous two trading days) and a fixed holding period limit (5 trading days), without setting a fixed stop-loss, aiming to capture rebound opportunities after short-term price corrections.

Strategy Principles
The core concept of this strategy is based on the mean reversion characteristic of markets, particularly short-term pullbacks within strong uptrends. The specific implementation includes:

Entry Conditions:

  • RSI(2) indicator below 25, indicating severe short-term oversold conditions
  • Price remains above the 200-day moving average, confirming the long-term uptrend is still valid

Exit Conditions (meeting either one triggers exit):

  • Price reaches profit target: the highest price of the previous two trading days
  • Time limit: 5 trading days have passed since entry

No Fixed Stop-Loss Design:

  • The strategy assumes that in a strong trend, prices will eventually rebound after a decline
  • Positions are maintained until either the target price is reached or the time limit expires

The strategy is implemented in Pine Script language, using ta.rsi and ta.sma functions to calculate technical indicators, strategy.entry and strategy.close to manage trades, and variables to track entry prices and holding time.

Strategy Advantages
After in-depth analysis, this strategy shows the following significant advantages:

  1. Dual Confirmation Mechanism: The combination of RSI oversold signals and trend filters reduces the possibility of false signals

  2. Clear Entry and Exit Rules: Strategy rules are simple and clear, easy to understand and execute, reducing the impact of subjective judgment

  3. Trend Following: By filtering with the 200-day moving average, trades are only executed in long-term uptrends, improving win rates

  4. Flexible Profit Targets: Using the highest price of the previous two trading days as a dynamic target adapts to different market environments

  5. Time-Controlled Risk: The 5-day forced closing mechanism avoids long-term traps and ensures efficient capital turnover

  6. Simple Operation: Few strategy parameters, easy to adjust and optimize, suitable for different traders' needs

  7. Reduced Monitoring Need: Clear automatic exit conditions reduce psychological pressure and monitoring requirements for traders

Strategy Risks
Despite the reasonable design, the strategy still has the following potential risks:

No Stop-Loss Risk: The lack of a fixed stop-loss is a double-edged sword that may lead to significant losses under extreme market conditions

  • Solution: Consider adding an ATR-based dynamic stop-loss or setting a maximum acceptable loss percentage

Trend Reversal Risk: Even with prices above the 200-day moving average, markets can still experience sudden trend reversals

  • Solution: Incorporate additional trend confirmation indicators, such as MACD or trendline analysis

Parameter Sensitivity: RSI period and threshold settings significantly impact strategy performance

  • Solution: Conduct thorough historical backtesting to find the most suitable parameter combinations for specific markets

Time Risk: The 5-day fixed holding period may be too short or too long under certain market conditions

  • Solution: Adjust holding time parameters based on different market volatility characteristics

Liquidity Risk: In low-liquidity markets, it may be difficult to execute trades at ideal prices

  • Solution: Add liquidity filtering conditions, such as minimum volume requirements

Slippage and Trading Costs: The strategy does not consider slippage and commission costs in actual trading

  • Solution: Include these factors in backtesting and live trading to evaluate true profitability

Strategy Optimization Directions
Based on code analysis, the strategy has several potential optimization directions:

Dynamic RSI Threshold:

  • Change the fixed RSI threshold (25) to a dynamic threshold based on market volatility
  • Rationale: The definition of oversold conditions may vary in different market environments; a dynamic threshold can better adapt to market changes

Multi-Period Trend Confirmation:

  • In addition to the 200-day moving average, add medium and short-term moving averages (such as 50-day and 20-day) as additional trend filtering conditions
  • Rationale: Multiple timeframe analysis can provide more comprehensive trend confirmation and reduce false signals

Money Management Optimization:

  • Implement volatility-based position sizing adjustments instead of fixed percentages
  • Rationale: Adjusting positions based on market volatility can achieve balanced risk allocation and improve capital efficiency

Adding Stop-Loss Mechanism:

  • Introduce ATR-based or fixed percentage stop-loss settings
  • Rationale: Even with a strategy philosophy of waiting for rebounds, appropriate stop-losses can still avoid huge losses in extreme situations

Entry Optimization:

  • Implement staged entries, e.g., enter 50% when RSI falls below 25, add positions if it continues to drop to lower levels
  • Rationale: Staged entries can improve average cost and enhance adaptability in high volatility

Exit Optimization:

  • Implement partial profit-taking mechanisms, such as partial position closing when certain targets are reached
  • Rationale: Partial profit-taking can lock in some gains while retaining upside potential

Market Environment Filtering:

  • Add volatility indicators (such as ATR or VIX) as market environment filtering conditions
  • Rationale: Adjusting strategy parameters or pausing trading in different volatility environments can avoid unfavorable market conditions

Summary
The Mean Reversion RSI(2) Momentum Breakout Trading Strategy with Moving Average Trend Filter is a quantitative trading strategy that combines short-term oversold indicators with long-term trend filtering. By identifying short-term pullback opportunities within strong uptrends, this strategy can capture profit opportunities from price rebounds with relatively controlled risk.

The main advantages of the strategy lie in its clear rules, simple operation, and higher win rates provided by the dual confirmation mechanism. At the same time, its fixed holding period and dynamic profit target design provide a good framework for capital management and risk control.

However, the lack of a fixed stop-loss mechanism is the main risk point of this strategy, which requires special attention in practical applications. There is still significant room for optimization through adding dynamic stop-losses, optimizing parameter settings, improving money management, and adding market environment filtering.

Overall, this is a reasonably designed mean reversion strategy, particularly suitable for application in clearly defined uptrending markets, and offers high reference value for traders seeking to capture short-term pullback opportunities.

Strategy source code

/*backtest
start: 2024-07-09 00:00:00
end: 2025-07-04 08:00:00
period: 3d
basePeriod: 3d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("RSI(2) with MA200 + Target + Close after 5 Days (No Stop Loss)", overlay=true,
     default_qty_type=strategy.percent_of_equity, default_qty_value=100,
     initial_capital=1000, currency=currency.EUR)

// === PARAMETERS ===
rsi_threshold = 25
rsi_period = 2
valid_days = 5  // Auto-close after 5 useful candles

// === BASE CALCULATIONS ===
rsi = ta.rsi(close, rsi_period)
ma200 = ta.sma(close, 200)
trend_ok = close > ma200

// === ENTRY CONDITION ===
entry_condition = rsi < rsi_threshold and trend_ok

// === TAKE PROFIT LEVEL ===
max_2days = math.max(high[1], high[2])

// === POSITION MANAGEMENT VARIABLES ===
var float entry_price = na
var int bars_since_entry = na

if entry_condition and strategy.opentrades == 0
    strategy.entry("RSI(2) Long", strategy.long)
    entry_price := close
    bars_since_entry := 0

// === TIME COUNTER ===
bars_since_entry := strategy.opentrades > 0 ? (na(bars_since_entry) ? 1 : bars_since_entry + 1) : na
time_expired = bars_since_entry >= valid_days

// === EXIT ON TARGET OR TIME ===
target_hit = high >= max_2days

if strategy.opentrades > 0 and (target_hit or time_expired)
    reason = target_hit ? "🎯 Target Hit" : "⏳ Time Expired"
    strategy.close("RSI(2) Long", comment=reason)
    entry_price := na
    bars_since_entry := na

// === VISUALIZATION — SIGNAL & LEVELS ===
plot(entry_condition ? close : na, title="Entry Signal", color=color.green, style=plot.style_circles, linewidth=2)
plot(strategy.opentrades > 0 ? max_2days : na, title="Take Profit Level", color=color.lime, linewidth=1)
Enter fullscreen mode Exit fullscreen mode

The original address: Mean Reversion RSI(2) Momentum Breakout Trading Strategy with Moving Average Trend Filter

Top comments (1)

Collapse
 
gavin_g_ebd1d919ab190af19 profile image
Grace

This one’s got everything—RSI2 for the snapbacks, momentum for the punch, and a moving average filter to keep it all in line. It’s like the strategy version of a well-balanced breakfast. Love how it catches those quick reversals without getting whipsawed in a bad trend. Definitely adding this to my “strategies to overthink at 2am” list. Great work!