20/50 EMA crossover: backtest results
A medium-speed trend crossover: buy when the 20-period EMA crosses above the 50-period EMA, sell when it crosses back below. We ran it on real daily data for 4 stocks. It beat simply buying and holding on 1 of 4 stocks.
Results by stock
| Stock | Period | Strategy | Buy & hold | Beat it? | Worst drop | Trades | Win rate | Caution |
|---|---|---|---|---|---|---|---|---|
| Apple (AAPL) | 2016 → 2025 | +431.6% | +1038.8% | no | -25.1% | 21 | 52.4% | includes a position still open at the end |
| Amazon (AMZN) | 2016 → 2025 | +227.0% | +613.2% | no | -53.9% | 24 | 37.5% | includes a position still open at the end; fell 54% at its worst |
| Robinhood (HOOD) | 2021 → 2025 | +274.0% | +223.5% | yes | -45.4% | 9 | 44.4% | only 9 closed trades; fell 45% at its worst |
| Tesla (TSLA) | 2016 → 2025 | +558.4% | +2877.2% | no | -63.7% | 22 | 27.3% | includes a position still open at the end; fell 64% at its worst |
Best: Tesla on +558.4%. One set of rules, fixed in advance, run on every stock: no tuning to make the numbers look better. A strategy with few trades or a big drop deserves less trust than its return suggests.
The exact rules
Buy Apple when the 20 day EMA crosses above the 50 day EMA. Sell when the 20 day EMA crosses below the 50 day EMA.
Paste those words into Extractor and it runs the same test, shows every trade on the chart with entry, stop loss and take profit, and compares it with buy & hold. Change a number and run it again in seconds.
Run these rules now, freeFree TradingView indicator (Pine Script v5)
Copy this into TradingView's Pine Editor and click Add to chart. It marks the buy and sell signals and draws the levels.
//@version=5
// Indicator generated by Extractor from your rules.
// Built for AAPL on the daily (1D) chart.
// Buy when: ema(20) crosses above ema(50)
// Sell when: ema(20) crosses below ema(50)
// Marks where your rules say buy and sell, and adds alerts you can turn on in TradingView.
indicator("20/50 EMA crossover signals", overlay=true)
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
cross1 = ta.crossover(ema20, ema50)
cross2 = ta.crossunder(ema20, ema50)
entrySignal = cross1
exitSignal = cross2
// Track whether the rules are in a trade, so signals don't repeat while already long.
var bool inTrade = false
var float entryPrice = na
stopHit = false
targetHit = false
buy = not inTrade and entrySignal
sell = inTrade and (exitSignal or stopHit or targetHit)
if sell
inTrade := false
entryPrice := na
else if buy
inTrade := true
entryPrice := close
// Levels stay drawn through the bar where the trade closes.
wasInTrade = inTrade or sell
levelBase = sell ? entryPrice[1] : entryPrice
plot(ema20, "EMA 20", color.orange)
plot(ema50, "EMA 50", color.aqua)
plotshape(buy, "Buy", shape.labelup, location.belowbar, color.new(color.teal, 0), text="BUY", textcolor=color.white, size=size.small)
plotshape(sell, "Sell", shape.labeldown, location.abovebar, color.new(color.red, 0), text="SELL", textcolor=color.white, size=size.small)
alertcondition(buy, "Buy signal", "20/50 EMA crossover: buy signal on {{ticker}} at {{close}}")
alertcondition(sell, "Sell signal", "20/50 EMA crossover: sell signal on {{ticker}} at {{close}}")
Test your own version
- Different stock, crypto or forex pair? Change the ticker in the description.
- Add a stop loss or take profit and see if it helps.
- Saw a strategy on YouTube? Paste the link and get the rules, the backtest and the indicator.