Strategy vault / Mean reversion
MA and EMA Crossover Trend Reversal Strategy
This strategy uses EMA and MA crossover to determine trend reversals, belonging to typical trend following strategies.
Overview
This strategy uses EMA and MA crossover to determine trend reversals, belonging to typical trend following strategies.
Strategy Logic
Calculate EMA and MA with specified periods respectively.
EMA crossover above MA generates buy signals.
EMA crossover below MA generates sell signals.
Can set trading only in specific months and date ranges.
Hold only one direction at a time, no reverse openings.
Simple and clear rules easy to implement.
Advantages
EMA and MA crossovers can capture trend reversal opportunities.
Date filter avoids erroneous trades around major events.
Holding one direction reduces unnecessary reverse trades.
Higher capital usage efficiency.
Suitable for short-term trend trading.
Risks
Crossovers may have false signals causing unnecessary losses.
No effective control over loss size per trade.
Larger loss risks without a stop loss.
Rigid date settings may miss trading opportunities.
Inappropriate parameters negatively affect performance.
Enhancement
Test different MA periods to find optimal values.
Evaluate additional filters on crossovers.
Incorporate stop loss to control loss per trade.
Optimize date filter rules to maintain flexibility.
Research proper take profit positioning.
Consider dynamic position sizing.
Conclusion
This strategy trades EMA and MA crossover reversals simply and efficiently but has some room for improvement. Further refinements like parameter optimization and risk controls can turn it into a steady short-term system.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 34 | emaLength |
| v_input_2 | 89 | maLength |
| v_input_3 | 8 | monthfrom |
| v_input_4 | 12 | monthuntil |
| v_input_5 | true | dayfrom |
| v_input_6 | 31 | dayuntil |
Source Pine Script
//@version=2
strategy(title = "MA + EMA Crossover Strategy ",shorttitle="eMA", overlay = true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100,commission_type=strategy.commission.percent,commission_value=0.1,initial_capital=100000)
emaLength =input(34)
maLength = input(89)
ema=ema(close,emaLength)
ma=sma(close,maLength)
plot(ema,linewidth=3,color=green)
plot(ma,linewidth=3,color=red)
longCond= crossover(ema,ma)
shortCond=crossover(ma,ema)
monthfrom =input(8)
monthuntil =input(12)
dayfrom=input(1)
dayuntil=input(31)
if ( longCond and month>=monthfrom and month <=monthuntil and dayofmonth>=dayfrom and dayofmonth < dayuntil)
strategy.entry("LONG", strategy.long, stop=close, oca_name="TREND", comment="LONG")
else
strategy.cancel(id="LONG")
if ( shortCond and month>=monthfrom and month <=monthuntil and dayofmonth>=dayfrom and dayofmonth < dayuntil )
strategy.entry("SHORT", strategy.short,stop=close, oca_name="TREND", comment="SHORT")
else
strategy.cancel(id="SHORT")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-20. 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/MA-and-EMA-Crossover-Trend-Reversal-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
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- Advanced Quantitative Trend Following and Cloud Reversal Composite Trading StrategyPine Script · Mean reversion · 1d
- BONK Multi Factor Trading StrategyPine Script · Mean reversion · 1d
- Bidirectional Moving Average Reversion Trading StrategyPine Script · Mean reversion · 1h