Strategy vault / Trend following
An Advanced EMA Trend Following Strategy with Relaxed RSI and ATR Filters
This is an EMA trend following strategy incorporating RSI and ATR filters, aiming to capture long term trends. It utilizes fast and slow EMA crossovers along with a long term EMA trend filter, relaxed RSI…

Overview
This is an EMA trend following strategy incorporating RSI and ATR filters, aiming to capture long term trends. It utilizes fast and slow EMA crossovers along with a long term EMA trend filter, relaxed RSI oversold/overbought levels, and ATR-based consolidation detection to reduce whipsaws.
Strategy Logic
- Long when fast EMA (20) crosses above slow EMA (50)
- Short when fast EMA crosses below slow EMA
- Only trade in the direction of long term trend judged by 200 EMA
- Require RSI to be relatively oversold for longs and overbought for shorts
- Use ATR to detect consolidation zones to avoid false breakouts
Advantages
- EMA crossover system effective for trend following
- Additional long term filter avoids trading counter trend
- Relaxed RSI thresholds reduce missed profitable trends
- ATR filter helps navigate choppy consolidation periods
Risks
- Can underperform in strongly trending bull markets
- Whipsaws possible with EMA crossovers during consolidation
- RSI and ATR parameters need individual optimization per instrument
Enhancements
- Optimize EMA lengths for different instruments
- Fine tune RSI and ATR parameters to improve consolidation detection
- Consider adding profit taking via trailing stops
Conclusion
Overall an effective system for long term trend following across various instruments. Optimization of parameters combined with prudent risk management can lead to positive results, especially in persistent bull market environments. The incorporation of auxiliary indicators like RSI and ATR make this an advanced EMA trend system.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 20 | Short EMA |
| v_input_2 | 50 | Long EMA |
| v_input_3 | 200 | Trend EMA |
| v_input_4 | 14 | RSI Length |
| v_input_5 | 14 | ATR Length |
Source Pine Script
/*backtest
start: 2024-01-29 00:00:00
end: 2024-02-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Strategy with Trend Filter", overlay=true)
// Параметры EMA
shortEmaLength = input(20, title="Short EMA")
longEmaLength = input(50, title="Long EMA")
trendEmaLength = input(200, title="Trend EMA")
shortEma = ta.ema(close, shortEmaLength)
longEma = ta.ema(close, longEmaLength)
trendEma = ta.ema(close, trendEmaLength)
// Параметры RSI
rsiLength = input(14, title="RSI Length")
rsi = ta.rsi(close, rsiLength)
// Параметры ATR
atrLength = input(14, title="ATR Length")
atr = ta.atr(atrLength)
// Логика для сигналов покупки и продажи с фильтром по тренду
buySignal = ta.crossover(shortEma, longEma) and close > trendEma
sellSignal = ta.crossunder(shortEma, longEma) and close < trendEma
// Вход в сделки
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)
// Выход из сделок на основе EMA пересечений
exitBuySignal = ta.crossunder(shortEma, longEma)
exitSellSignal = ta.crossover(shortEma, longEma)
if (exitBuySignal)
strategy.close("Buy")
if (exitSellSignal)
strategy.close("Sell")
// Визуализация EMA
plot(shortEma, color=color.blue, title="Short EMA")
plot(longEma, color=color.red, title="Long EMA")
plot(trendEma, color=color.green, title="Trend EMA")
// Отдельная панель для RSI и его визуализация
plot(rsi, title="RSI", color=color.purple, linewidth=2)
// Отдельная панель для ATR и его визуализация
plot(atr, title="ATR", color=color.orange, linewidth=2)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-29. 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/An-Advanced-EMA-Trend-Following-Strategy-with-Relaxed-RSI-and-ATR-Filters.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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual Mode Adaptive Trend Trading Strategy EMA Crossover with ATR Volatility Based Risk Management SystemPine Script · Trend following · 1d
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- Dynamic Multi Timeframe ATR Crossover Strategy Optimizing Trend Following and Risk Management with Flexible ParametersPine Script · Trend following · 1h