Strategy vault / Mean reversion
Trend Reversal Trading Strategy Based on EMA Crossover
This strategy calculates the exponential moving average (EMA) of fast and slow periods, plots them on the chart, and monitors crossovers in real-time to determine trend reversals. Trading signals are formed by…

Overview
This strategy calculates the exponential moving average (EMA) of fast and slow periods, plots them on the chart, and monitors crossovers in real-time to determine trend reversals. Trading signals are formed by incorporating the RSI oscillator to avoid false signals. A buy signal is generated when the fast EMA crosses above the slow EMA. A sell signal is generated when the fast EMA crosses below the slow EMA.
Strategy Logic
- Calculate EMAs of fast and slow periods
- Plot on chart and monitor crossovers in real-time
- Fast EMA crossing above slow EMA indicates uptrend, buy signal
- Fast EMA crossing below slow EMA indicates downtrend, sell signal
- Incorporate RSI to avoid false signals
- Trend filter to trade only on trend change
Advantage Analysis
- EMAs smooth price action, less sensitive to minor fluctuations
- RSI filters out false reversal signals
- Customizable EMA and RSI parameters for different markets
- Simple and intuitive code, easy to understand
Risk Analysis
- EMAs have lag, may miss turning points
- Fail in ranging, volatile markets
- Need to adjust EMA and RSI parameters
- Should combine other indicators
Optimization
- Add filters to increase signal reliability
- Implement stop loss to control risk
- Test stability across periods
- Incorporate currency strength meter
- Optimize risk-reward ratio
Conclusion
The strategy has a clear logic using EMA crossovers to determine trend reversal, filtered by RSI to capture mid- to long-term trends. However, optimization of EMA/RSI parameters and stop loss, as well as the risk of missing reversals and failure in volatile markets remain. With tuned parameters and risk controls, it could serve to identify turning points and formulate investment decisions.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 10 | Fast EMA Period |
| v_input_2 | 50 | Slow EMA Period |
| v_input_3 | 14 | RSI Length |
| v_input_4 | 70 | Overbought Level |
| v_input_5 | 30 | Oversold Level |
Source Pine Script
/*backtest
start: 2022-12-18 00:00:00
end: 2023-12-24 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Trend Change with EMA Entry/Exit - Intraday", overlay=true)
// Define the fast and slow EMA periods
fast_ema_period = input(10, title="Fast EMA Period")
slow_ema_period = input(50, title="Slow EMA Period")
// Calculate the EMAs
ema_fast = ta.ema(close, fast_ema_period)
ema_slow = ta.ema(close, slow_ema_period)
// Plot the EMAs on the chart
plot(ema_fast, title="Fast EMA", color=color.blue, linewidth=2)
plot(ema_slow, title="Slow EMA", color=color.orange, linewidth=2)
// Detect trend changes (crossovers and crossunders)
is_uptrend = ta.crossover(ema_fast, ema_slow)
is_downtrend = ta.crossunder(ema_fast, ema_slow)
// Relative Strength Index (RSI)
rsi_length = input(14, title="RSI Length")
overbought_level = input(70, title="Overbought Level")
oversold_level = input(30, title="Oversold Level")
rsi_value = ta.rsi(close, rsi_length)
// Trend Filter
is_trending = ta.change(is_uptrend) != 0 or ta.change(is_downtrend) != 0
// Entry and Exit signals
enter_long = is_uptrend and rsi_value < overbought_level and is_trending
exit_long = is_downtrend and is_trending
enter_short = is_downtrend and rsi_value > oversold_level and is_trending
exit_short = is_uptrend and is_trending
strategy.entry("Buy", strategy.long, when=enter_long)
strategy.close("Buy", when=exit_long)
strategy.entry("Sell", strategy.short, when=enter_short)
strategy.close("Sell", when=exit_short)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-25. 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/Trend-Reversal-Trading-Strategy-Based-on-EMA-Crossover.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