Strategy vault / Trend following
Triple EMA Crossover Trading System with Smart R2R based Stop Loss Management
This is a trend-following trading system based on triple Exponential Moving Average (EMA) crossover signals. The system combines EMA8, EMA21, and EMA89 to generate trading signals through crossovers, and integrates…

Overview
This is a trend-following trading system based on triple Exponential Moving Average (EMA) crossover signals. The system combines EMA8, EMA21, and EMA89 to generate trading signals through crossovers, and integrates smart stop-loss management based on risk-to-reward ratio, achieving automated risk management.
Strategy Principles
The system consists of the following core functional modules:
- Signal Generation Module: Uses crossovers between fast EMA8 and medium EMA21 to determine trading direction, while requiring price to be above or below slow EMA89 to confirm the major trend
- Trade Execution Module: Automatically opens positions when long or short conditions are met, setting initial stop-loss and take-profit levels
- Risk Management Module: Automatically moves stop-loss to break-even when price movement reaches 1:1 risk-to-reward ratio, securing risk-free profits
- Visualization Module: Plots three EMAs, entry points, and stop-loss movement markers on the chart
Strategy Advantages
- Multiple Timeframe Validation: Confirms trends through three EMAs of different periods, improving trading reliability
- Smart Risk Management: Stop-loss mechanism based on risk-to-reward ratio reduces drawdowns while protecting profits
- High Automation: Fully automated process from signal generation to position management, reducing human intervention
- Adjustable Parameters: Key parameters like EMA periods and stop-loss percentages can be optimized for different market characteristics
Strategy Risks
- Choppy Market Risk: May generate frequent false breakout signals in sideways markets
- Slippage Risk: Stop-loss execution may experience slippage in fast-moving markets
- Systemic Risk: Sudden market movements may render stop-losses ineffective Solutions:
- Add trend filters to identify choppy markets
- Set reasonable stop-loss buffers
- Implement volatility-adaptive mechanisms
Strategy Optimization Directions
- Incorporate Volume Indicators: Add volume confirmation to EMA crossover signals to improve signal quality
- Develop Dynamic Stop-Loss: Adjust stop-loss distances based on market volatility to enhance strategy adaptability
- Optimize Break-Even Mechanism: Implement trailing stops after reaching target R2R to capture more potential profits
- Add Market Environment Filters: Design trend strength indicators to adjust strategy parameters in different market conditions
Summary
The strategy achieves a complete trend-following trading system by combining classical EMA crossover systems with modern risk management methods. The system's strengths lie in its reliable signal generation mechanism and intelligent risk control methods, but parameters still need to be optimized and functions extended based on specific market characteristics in practical applications. Through continuous improvement and optimization, the strategy has the potential to maintain stable performance across various market conditions.
Source Pine Script
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover with SL to BE", shorttitle="OmegaGalsky", overlay=true)
// Входни параметри
ema8_period = input.int(8, title="EMA 8 Period")
ema21_period = input.int(21, title="EMA 21 Period")
ema89_period = input.int(89, title="EMA 89 Period")
fixed_risk_reward = input.float(1.0, title="Risk/Reward Ratio (R2R)")
sl_percentage = input.float(0.001, title="Stop Loss Percentage", step=0.0001)
tp_percentage = input.float(0.0025, title="Take Profit Percentage", step=0.0001)
// Изчисляване на EMA
ema8 = ta.ema(close, ema8_period)
ema21 = ta.ema(close, ema21_period)
ema89 = ta.ema(close, ema89_period)
// Условия за BUY
buy_condition = ta.crossover(ema8, ema21) and close > ema89 and close > open
// Условия за SELL
sell_condition = ta.crossunder(ema8, ema21) and close < ema89 and close < open
// Вход в BUY позиция
if (buy_condition)
stop_loss = close * (1 - sl_percentage)
take_profit = close * (1 + tp_percentage)
strategy.entry("BUY", strategy.long)
strategy.exit("TP/SL", from_entry="BUY", stop=stop_loss, limit=take_profit)
// Вход в SELL позиция
if (sell_condition)
stop_loss = close * (1 + sl_percentage)
take_profit = close * (1 - tp_percentage)
strategy.entry("SELL", strategy.short)
strategy.exit("TP/SL", from_entry="SELL", stop=stop_loss, limit=take_profit)
// Логика за преместване на стоп към BE
if (strategy.position_size > 0)
entry_price = strategy.position_avg_price
// За LONG позиция
if (strategy.position_size > 0 and high >= entry_price + (entry_price * sl_percentage * fixed_risk_reward))
strategy.exit("SL to BE", from_entry="BUY", stop=entry_price)
label.new(bar_index, high, "SL moved to BE", color=color.green)
// За SHORT позиция
if (strategy.position_size < 0 and low <= entry_price - (entry_price * sl_percentage * fixed_risk_reward))
strategy.exit("SL to BE", from_entry="SELL", stop=entry_price)
label.new(bar_index, low, "SL moved to BE", color=color.red)
// Чертеж на EMA
plot(ema8, color=color.orange, title="EMA 8")
plot(ema21, color=color.blue, title="EMA 21")
plot(ema89, color=color.purple, title="EMA 89")
Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-06. 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/Triple-EMA-Crossover-Trading-System-with-Smart-R2R-based-Stop-Loss-Management.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