Strategy vault / Trend following
EMA Crossover with Short term Signals Strategy
This strategy uses three EMA lines with different periods (144-day, 34-day, and 76-day) to capture the medium to long-term market trends. It also incorporates 30-day highest price and lowest price EMA lines as…

Overview
This strategy uses three EMA lines with different periods (144-day, 34-day, and 76-day) to capture the medium to long-term market trends. It also incorporates 30-day highest price and lowest price EMA lines as short-term long and short signals. When the closing price breaks above the short-term long signal, it opens a long position; when the closing price breaks below the short-term short signal, it closes the position. This approach allows for flexible position management while grasping the main market trend.
Strategy Principle
- Calculate the 144-day, 34-day, and 76-day EMA lines, representing the ultra-long-term, medium-term, and long-term trends, respectively.
- Calculate the 30-day highest price and lowest price EMA lines as short-term long and short signals.
- Open a long position when the closing price breaks above the 30-day highest price EMA line; close the position when the closing price breaks below the 30-day lowest price EMA line.
- Plot the EMA lines and short-term long/short signal range on the chart for a visual representation of market trends and signals.
Strategy Advantages
- By combining EMA lines of different periods, it comprehensively captures the ultra-long-term, long-term, and medium-term market trends.
- Utilizing the 30-day highest and lowest price EMA lines as short-term signals enables flexible position management within the trend, improving capital utilization efficiency.
- Clear plotting of various signals and trends on the chart facilitates traders' intuitive judgment of market conditions.
Strategy Risks
- EMA lines have a certain degree of lag and may react slowly at market turning points.
- Short-term signals are greatly affected by market fluctuations, which may lead to frequent opening and closing of positions, increasing transaction costs.
- The strategy lacks stop-loss measures and may assume significant risks when the market experiences severe fluctuations.
Strategy Optimization Directions
- Introduce more EMA lines with different periods, such as 200-day and 50-day, to enrich the dimensions of trend judgment.
- Optimize the parameters of short-term signals, such as adjusting the period of the highest and lowest price EMA lines, to better adapt to different market conditions.
- Incorporate a stop-loss mechanism, such as setting a dynamic stop-loss level based on ATR, to control the maximum risk of a single trade.
- Consider adding trailing stop or trailing stop methods to better protect existing profits.
Summary
The EMA Crossover with Short-term Signals strategy captures market trends through multi-period EMA lines and achieves flexible position management using short-term price signals. It is a method that combines trend tracking with swing trading. However, this strategy also has issues such as lag, frequent trading, and lack of risk control, requiring further optimization to improve its robustness and profitability. By introducing more dimensions of trend judgment, dynamically adjusting signal parameters, incorporating reasonable stop-loss and take-profit mechanisms, and other methods, this strategy can be made more complete and reliable.
Source Pine Script
/*backtest
start: 2023-05-17 00:00:00
end: 2024-05-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover with Short-term Signals", overlay=true)
// DefinitionEMA
shortest = ta.ema(close, 144)
short = ta.ema(close, 34)
longer = ta.ema(close, 76)
// DrawEMA
plot(shortest, color=color.new(color.yellow, 0))
plot(short, color=color.new(color.orange, 0))
plot(longer, color=color.new(color.red, 0))
// Define short-term long-short signalsEMA
stLong = ta.ema(high, 30)
stShort = ta.ema(low, 30)
stLongPlot = plot(stLong, 'Short-term Long', color.new(color.aqua, 0))
stShortPlot = plot(stShort, 'Short-term Short', color.new(color.green, 0))
// Draw short-term long and short signals
clr = close > stLong ? color.green : color.aqua
fill(stLongPlot, stShortPlot, color=clr, transp=90)
// Trading signals
if (close > stLong)
strategy.entry("Buy", strategy.long)
if (close < stShort)
strategy.close("Buy")
// Show buy and sell signals
plotshape(series=close > stLong, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=close < stShort, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-23. 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-with-Short-term-Signals-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
- 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
- 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