Strategy vault / Trend following
Dual Moving Average Trend Following Trading System with Risk Reward Ratio Optimization Strategy
This strategy uses 20-day and 200-day exponential moving averages (EMA) as primary indicators, combined with a 3:1 risk-reward ratio for trading decisions. Buy signals are generated when the price breaks above the…

In the field of quantitative trading, trend following strategies have always been one of the most popular trading methods. This article introduces a trend following strategy based on a dual moving average system, which improves trading efficiency through optimized risk-reward ratios.
Strategy Overview
This strategy uses 20-day and 200-day exponential moving averages (EMA) as primary indicators, combined with a 3:1 risk-reward ratio for trading decisions. Buy signals are generated when the price breaks above the 20-day EMA and the 20-day EMA is above the 200-day EMA. Each trade has fixed stop-loss (-0.5%) and take-profit (1.5%) levels to ensure controlled risk.
Strategy Principles
The core logic includes several key elements:
- Uses 20-day and 200-day EMAs to judge market trends, with the 200-day EMA representing long-term trend and 20-day EMA reflecting short-term movements
- A buy signal is generated when price breaks above the 20-day EMA and the 20-day EMA is above the 200-day EMA, indicating an upward trend
- Employs a 3:1 risk-reward ratio, with take-profit level (1.5%) being three times the stop-loss level (0.5%)
- Uses variables to track trade status and avoid duplicate entries
- Resets trade status when price falls below 20-day EMA, preparing for the next trade
Strategy Advantages
- Dual moving average system effectively filters market noise and improves signal reliability
- Fixed risk-reward ratio supports long-term profitable trading
- Clear entry and exit rules reduce subjective judgment
- High degree of automation, easy to implement and backtest
- Comprehensive risk control mechanism with clear stop-loss levels for each trade
Strategy Risks
- May generate frequent false signals in ranging markets
- Fixed stop-loss and take-profit levels may not suit all market conditions
- Trading costs not considered may affect actual returns
- Stop-loss placement may be too close to entry in high-volatility markets
- Market liquidity factors not considered
Optimization Directions
- Introduce volume indicators to improve trend judgment accuracy
- Dynamically adjust stop-loss and take-profit levels based on market volatility
- Add trend strength filters to reduce false signals
- Consider incorporating market sentiment indicators
- Optimize position management system for better money management
Summary
This is a well-structured trend following strategy with clear logic. By combining a dual moving average system with fixed risk-reward ratios, the strategy achieves good returns while maintaining risk control. Though there are areas for optimization, it's overall a trading system worthy of further research and improvement.
Source Pine Script
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Estrategia de Compra con Ratio 3:1", overlay=true)
// Parámetros de la temporalidad diaria y las EMAs
ema20 = ta.ema(close, 20)
ema200 = ta.ema(close, 200)
// Condiciones para la entrada en largo
cierre_por_encima_ema20 = close > ema20
ema20_mayor_ema200 = ema20 > ema200
// Variable para registrar si ya se realizó una compra
var bool compra_realizada = false
// Condición para registrar una compra: primera vez que cierra por encima de EMA 20 con EMA 20 > EMA 200
if (cierre_por_encima_ema20 and ema20_mayor_ema200 and not compra_realizada)
// Abrir una operación de compra
strategy.entry("Compra", strategy.long)
compra_realizada := true // Registrar que se realizó una compra
// Definir los niveles de stop loss y take profit basados en el ratio 3:1
stop_loss = strategy.position_avg_price * 0.995 // -0.50% (rendimiento)
take_profit = strategy.position_avg_price * 1.015 // +1.50% (3:1 ratio)
// Establecer el stop loss y take profit
strategy.exit("Take Profit / Stop Loss", from_entry="Compra", stop=stop_loss, limit=take_profit)
// Condición para resetear la compra: cuando el precio cierra por debajo de la EMA de 20
if (close < ema20)
compra_realizada := false // Permitir una nueva operación
// Ploteo de las EMAs
plot(ema20, title="EMA 20", color=color.blue, linewidth=2)
plot(ema200, title="EMA 200", color=color.red, linewidth=2)
// Colorear el fondo cuando el precio está por encima de ambas EMAs
bgcolor(cierre_por_encima_ema20 and ema20_mayor_ema200 ? color.new(color.green, 80) : na)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-11-28. 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/Dual-Moving-Average-Trend-Following-Trading-System-with-Risk-Reward-Ratio-Optimization-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
- 200 EMA VWAP MFI Trend Following StrategyPine Script · Trend following · 1d
- 4 EMA Trend StrategyPine Script · Trend following · 1d
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m