Strategy vault / Trend following
EMA Crossover Strategy with Stop Loss and Take Profit Optimization System
This strategy is a quantitative trading system based on the crossover of 5-period and 15-period Exponential Moving Averages (EMA). It aims to achieve stable returns while protecting capital through reasonable…

Overview
This strategy is a quantitative trading system based on the crossover of 5-period and 15-period Exponential Moving Averages (EMA). It aims to achieve stable returns while protecting capital through reasonable stop-loss and take-profit levels. The strategy uses classic moving average crossover signals to identify market trend changes and combines them with risk management mechanisms to control the risk-reward ratio of each trade.
Strategy Principles
The core of the strategy is monitoring the crossover between the fast-moving average (5-period EMA) and the slow-moving average (15-period EMA). A long signal is generated when the 5-period EMA crosses above the 15-period EMA, while a short signal is generated when the 5-period EMA crosses below the 15-period EMA. For each trading signal, the system automatically sets a 1.5% stop-loss level and a 3% take-profit level, ensuring a favorable risk-reward ratio. The stop-loss and take-profit levels are calculated based on the entry price, effectively controlling risk exposure.
Strategy Advantages
- Signal generation mechanism is objective and easy to understand, not affected by subjective judgment
- Uses exponential moving averages to reduce the impact of false breakouts
- Fixed percentage stop-loss and take-profit levels facilitate capital management
- Risk-reward ratio of 1:2 follows professional trading principles
- Simple strategy logic, easy to implement and maintain
- Applicable to multiple markets and timeframes
Strategy Risks
- May generate frequent false signals in ranging markets, increasing transaction costs
- Fixed stop-loss and take-profit settings may not suit all market conditions
- Fast EMA is sensitive to price movements, potentially leading to overtrading
- Does not consider market volatility changes, risk control lacks flexibility
- Stop-loss execution may be delayed in extreme market conditions
Strategy Optimization Directions
- Introduce volatility indicators to dynamically adjust stop-loss and take-profit levels
- Add trend filters to reduce false signals in ranging markets
- Dynamically adjust EMA periods based on different market characteristics
- Add volume confirmation mechanism to improve signal reliability
- Implement time filters to avoid trading during unfavorable periods
- Consider adding trailing stop mechanism to optimize profit-taking
Summary
This is a well-structured quantitative trading strategy with clear logic. It captures trend reversal points through moving average crossovers and implements risk control with fixed stop-loss and take-profit levels. The strategy is simple to use, suitable for beginners, and provides a good foundation for further optimization. Traders are advised to conduct thorough backtesting before live implementation and optimize parameters according to specific market characteristics.
Source Pine Script
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-26 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("5 EMA and 15 EMA Crossover with Stop Loss and Target", overlay=true)
// Define EMAs
ema5 = ta.ema(close, 5)
ema15 = ta.ema(close, 15)
// Plot EMAs on the chart
plot(ema5, title="5 EMA", color=color.blue)
plot(ema15, title="15 EMA", color=color.red)
// Crossover conditions
longCondition = ta.crossover(ema5, ema15)
shortCondition = ta.crossunder(ema5, ema15)
// Stop-loss and take-profit percentage
stopLossPercent = 1.5 // Stop-loss at 1.5%
takeProfitPercent = 3.0 // Take-profit at 3%
// Calculate stop-loss and take-profit levels for long and short positions
longStopLoss = strategy.position_avg_price * (1 - stopLossPercent / 100)
longTakeProfit = strategy.position_avg_price * (1 + takeProfitPercent / 100)
shortStopLoss = strategy.position_avg_price * (1 + stopLossPercent / 100)
shortTakeProfit = strategy.position_avg_price * (1 - takeProfitPercent / 100)
// Enter long position with stop-loss and take-profit
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Long", stop=longStopLoss, limit=longTakeProfit)
// Enter short position with stop-loss and take-profit
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit/Stop Loss", "Short", stop=shortStopLoss, limit=shortTakeProfit)
// Plot stop-loss and take-profit levels
plot(longStopLoss, title="Long Stop Loss", color=color.red, linewidth=1, style=plot.style_linebr)
plot(longTakeProfit, title="Long Take Profit", color=color.green, linewidth=1, style=plot.style_linebr)
plot(shortStopLoss, title="Short Stop Loss", color=color.red, linewidth=1, style=plot.style_linebr)
plot(shortTakeProfit, title="Short Take Profit", color=color.green, linewidth=1, style=plot.style_linebr)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-11-27. 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/EMA-Crossover-Strategy-with-Stop-Loss-and-Take-Profit-Optimization-System.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
- CM Multiple EMA Crossover StrategyPine Script · Trend following · 6h
- Dynamic Dual EMA Trend Following StrategyPine Script · Trend following · 1d
- EMA 200 Crossover with Volume and Trend StrategyPine Script · Trend following · 1d
- EMA SMA Trend Following with Swing Trading Strategy Combined Volume Filter and Percentage Take Profit Stop Loss SystemPine Script · Trend following · 1d
- Fixed Range Volume Profile And Anchored VWAP Trend Identification Strategy With Dynamic Stop LossPine Script · Trend following · 1h
- Multi Exponential Moving Average Crossover Strategy with Volume Based ATR Dynamic Stop Loss OptimizationPine Script · Trend following · 2d