Strategy vault / Mean reversion
Multi Period EMA Trend Detection with RSI Overbought Strategy
This strategy is a trend-following trading system based on multiple-period Exponential Moving Averages (EMA) and the Relative Strength Index (RSI). It makes trading decisions by analyzing the trends of 20, 50, and…

Overview
This strategy is a trend-following trading system based on multiple-period Exponential Moving Averages (EMA) and the Relative Strength Index (RSI). It makes trading decisions by analyzing the trends of 20, 50, and 100-period EMAs, combined with price breakouts and RSI overbought signals. The strategy is primarily designed for trending markets, using multiple technical indicators to enhance trading accuracy.
Strategy Principles
The core logic includes the following key components:
- Trend Detection: Comparing current and previous EMA values to determine if all three periods (20/50/100) are in upward trends
- Entry Conditions: Generates a buy signal when price crosses above the 20-period EMA and all EMAs are trending upward
- Exit Conditions: Closes positions when RSI exceeds 70 (overbought) or price falls below the 20-period EMA
- Position Management: Uses a percentage (10%) of account equity for position sizing
Strategy Advantages
- Multiple Confirmation Mechanism: Reduces false breakout risks through validation of three different EMA periods and RSI
- Trend Following: Effectively captures medium to long-term trends, enhancing profit potential
- Risk Control: Uses RSI overbought signals and EMA crossunders as stop-loss conditions
- Money Management: Implements percentage-based position sizing that scales with account size
- Systematic Operation: Clear rules minimize subjective judgment interference
Strategy Risks
- Lag Effect: EMAs as lagging indicators may cause delayed entries and exits
- Sideways Market Risk: May generate frequent false signals in ranging markets
- Gap Risk: Large market gaps may render stop-loss levels ineffective
- Parameter Sensitivity: EMA periods and RSI thresholds may need adjustment in different market conditions
- Transaction Costs: Frequent trading may incur significant costs
Strategy Optimization Directions
- Market Environment Recognition: Add market state identification to reduce position size or pause trading in ranging markets
- Dynamic Parameter Optimization: Automatically adjust EMA periods and RSI thresholds based on market volatility
- Stop-Loss Enhancement: Implement trailing stop-loss mechanisms to better protect profits
- Entry Refinement: Add volume confirmation to improve breakout signal reliability
- Position Sizing Enhancement: Dynamically adjust position size based on trend strength and market volatility
Summary
This is a composite strategy system combining trend following and momentum reversal. Through the coordinated use of multiple technical indicators, it achieves a favorable risk-reward profile while maintaining simplicity. The strategy's core strengths lie in its strict trend confirmation mechanism and comprehensive risk control system, though practical application requires attention to parameter optimization and market environment adaptability. Through the suggested optimization directions, there is room for further strategy enhancement.
Source Pine Script
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-17 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover + RSI Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// Calculate EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
// Calculate RSI
rsiPeriod = 14
rsiValue = ta.rsi(close, rsiPeriod)
// Determine if each EMA is trending up (current value greater than the previous value)
ema20_trending_up = ema20 > ema20[1]
ema50_trending_up = ema50 > ema50[1]
ema100_trending_up = ema100 > ema100[1]
all_emas_trending_up = ema20_trending_up and ema50_trending_up and ema100_trending_up
// Buy condition:
// 1. Price crosses above the EMA20 from below (using ta.crossover)
// 2. All three EMAs are trending upward
buySignal = ta.crossover(close, ema20) and all_emas_trending_up
// Sell conditions:
// Sell if RSI is above 70 OR price crosses below the EMA20 from above (using ta.crossunder)
sellSignal = (rsiValue > 70) or ta.crossunder(close, ema20)
// Enter a long position if the buy condition is met
if (buySignal)
strategy.entry("Long", strategy.long)
// Exit the long position if either sell condition is met
if (sellSignal)
strategy.close("Long")
// Plot the EMAs on the chart for visualization
plot(ema20, color=color.blue, title="EMA 20")
plot(ema50, color=color.orange, title="EMA 50")
plot(ema100, color=color.green, title="EMA 100")
// (Optional) Plot the RSI and a horizontal line at 70 for reference
plot(rsiValue, title="RSI", color=color.purple)
hline(70, title="Overbought (70)", color=color.red)Published by ChaoZhang on the FMZ strategy square · last modified 2025-02-18. 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/Multi-Period-EMA-Trend-Detection-with-RSI-Overbought-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
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- Fast RSI Reversal Trading StrategyPine Script · Mean reversion · 1h
- Multi EMA Trend Reversal Trading StrategyPine Script · Mean reversion · 1d
- Enhanced Multi Indicator Trend Reversal Intelligence StrategyPine Script · Mean reversion · 1d
- PowerZone Trading StrategyPine Script · Mean reversion · 1d