Strategy vault / Trend following
EMA SAR Medium to Long Term Trend Following Strategy
The EMA SAR Medium-to-Long-Term Trend Following Strategy is a quantitative trading strategy that utilizes a combination of Exponential Moving Averages (EMAs) and the Parabolic Stop and Reverse (SAR) indicator to…

Overview
The EMA SAR Medium-to-Long-Term Trend Following Strategy is a quantitative trading strategy that utilizes a combination of Exponential Moving Averages (EMAs) and the Parabolic Stop and Reverse (SAR) indicator to capture medium-to-long-term trends in the market. The strategy determines the current market trend direction by comparing the 20-period and 60-period EMAs and confirming with the SAR indicator. The main objective of the strategy is to enter trades early in the formation of a trend and hold positions until a reversal signal appears.
Strategy Principle
The core of this strategy is to use the crossover of two EMAs with different periods (20 and 60) to determine the trend direction. When the 20-period EMA crosses above the 60-period EMA from below, it indicates that an uptrend may be forming; conversely, when the 20-period EMA crosses below the 60-period EMA from above, it suggests a potential downtrend. To further confirm the authenticity of the trend, the strategy also incorporates the SAR indicator. The strategy will only consider entering a trade when the EMA crossover occurs simultaneously with the SAR indicator showing a signal consistent with the trend (SAR below price in an uptrend, SAR above price in a downtrend).
Advantage Analysis
- By combining the EMA and SAR indicators, the strategy effectively filters out noise and false signals, improving the accuracy of trend identification.
- The strategy has a relatively low trading frequency, making it more suitable for capturing medium-to-long-term trends, which helps reduce trading costs and risks associated with frequent trading.
- Entering trades early in the formation of a trend allows the strategy to maximize the profit potential of each trend.
- The stop-loss is set at the previous trading day's high (for long positions) or low (for short positions), effectively controlling the risk of individual trades.
Risk Analysis
- The strategy may generate numerous false signals during range-bound markets, leading to frequent trading and capital losses.
- The performance of the strategy heavily depends on the selection of EMA and SAR parameters, and different parameter settings may result in significant performance variations.
- In strong trending markets, the strategy may miss the best entry opportunities as it requires confirmation from both EMA crossover and SAR.
- The strategy lacks dynamic risk-reward balancing, and the risk taken in each trade may not be consistent.
Optimization Direction
- Consider incorporating additional technical indicators or market sentiment indicators to further improve the accuracy and reliability of trend identification.
- Optimize the parameters of the EMA and SAR to find the best-performing combinations under different market conditions.
- Introduce dynamic stop-loss and take-profit mechanisms to adjust risk control in real-time based on market volatility and individual stock characteristics.
- Combine with market leadership or sector rotation strategies to enhance adaptability and profit potential in strong trending markets.
Summary
The EMA SAR Medium-to-Long-Term Trend Following Strategy combines EMA and SAR indicators to enter trades early in the formation of a trend, aiming to capture medium-to-long-term trending opportunities in the market. The strategy's advantages lie in its ability to filter out noise and hold positions once a trend is established to maximize profits. However, it may generate numerous false signals in range-bound markets, and its performance is significantly influenced by parameter selection. Future enhancements to the strategy could involve incorporating additional indicators, parameter optimization, dynamic risk management, and integration with other strategies to improve its robustness and profit potential across different market environments.
Source Pine Script
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA SAR Strategy", overlay=true)
// EMA Settings
ema_20 = ta.ema(close, 20)
ema_60 = ta.ema(close, 60)
/// SAR Settings
sar = ta.sar(0.02, 0.2, 0.2)
sar_value = sar
is_trend_up = sar[1] > sar[2] ? true : false // Evaluating the trend direction
/// Condition for Buy Signal
buy_condition = ta.crossover(ema_20, ema_60) and (sar_value < ema_20) and (is_trend_up)
// Condition for Sell Signal
sell_condition = ta.crossunder(ema_20, ema_60) and (sar_value > ema_20) and (not is_trend_up)
// Define Entry Time
entry_time = time + 180000
// Strategy Entry
strategy.entry("Buy", strategy.long, when=buy_condition, comment="Buy Signal", stop=high[1])
strategy.entry("Sell", strategy.short, when=sell_condition, comment="Sell Signal", stop=low[1], when=entry_time)
// Plot EMAs
plot(ema_20, color=#f3e221, linewidth=1, title="EMA 20")
plot(ema_60, color=#8724f0, linewidth=1, title="EMA 60")
// Plot SAR
plotshape(sar_value, style=shape.triangleup, location=location.abovebar, color=color.green, size=size.small, title="SAR Up")
plotshape(sar_value, style=shape.triangledown, location=location.belowbar, color=color.red, size=size.small, title="SAR Down")
// Plot Buy and Sell Signals
plotshape(series=buy_condition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=sell_condition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
// Send Alerts
alertcondition(condition=buy_condition, title="Buy Signal", message="Buy Signal - EMA SAR Strategy")
alertcondition(condition=sell_condition, title="Sell Signal", message="Sell Signal - EMA SAR Strategy")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-17. 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-SAR-Medium-to-Long-Term-Trend-Following-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
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- PSAR and EMA Based Quantitative Trading StrategyPine Script · Trend following · 1h
- An Optimization of Dual Moving Average Trend Following Strategy Based on Indicators CombinationPine Script · Trend following · 4h
- Multi Indicator Trend Following Trading Strategy with Parabolic SAR and SuperTrend CloudPine Script · Trend following
- Adaptive Trend Following with Dynamic Risk Control StrategyPine Script · Trend following · 1h
- An Intraday Trend Following Quantitative Strategy Based on Multi indicator Condition FilteringPine Script · Trend following · 1d