Skip to content
The Casebook · A classic strategy

Buy 20-day EMA pullbacks above 50- and 200-day averages

Buy pullbacks to the 20-day EMA in stocks above their 50-day and 200-day moving averages.
VerdictTested Nov 22, 2026

Survivorship mirage

It clears the bar on today's winners, the stocks everyone wishes they had bought, but not on the laggards, which is where hindsight can't help.

  • It clears the bar on today's winners but not on the laggards: the winners' own rise did the work.
Trades on the laggards
3,146

42 large US stocks, 15 years

Per trade, after costs
−0.078R

Before costs +0.019R

Bar to clear
t > 2.01

By trade and by day, sized to a first try

What the numbers say

On the 22 laggards the idea averaged −0.078R per trade after costs over 3146 trades, against 0.091 on today's winners. Bull markets gave −0.041, flat −0.127, bear −0.476 (t by day −3.39), and in each regime it beat 35%, 10% and 0% of random-date draws. The winners' own rise did the work, hence the verdict.

How it was tested

Buy at the close when a stock that is above both its 50-day and 200-day moving averages pulls back to touch its 20-day EMA, with a 2 x ATR stop, a target at twice the risk, and a 20-day time limit.

Side
Long
Time limit
Exit at the close after 20 trading days, unless the stop, the target or its own exit comes first
Bar to clear
t > 2.01, by trade and by day, sized to a first try (one idea, tested once)
Prices
15 years of daily bars through 2026-11-20; judged 2026-11-22
Choices made where the idea was open
  • 'Pullback to the 20-day EMA' = low touches or pierces EMA(20) while the close finishes at or above it
  • 'Above 50-day and 200-day MAs' = close above both simple moving averages, plus SMA(50) > SMA(200) to confirm an established uptrend
  • Pullback must start from a prior extension above the EMA (5-day high close at least 1 x ATR(14) above EMA(20))
  • No stop or target was given, so stop = 2 x ATR(14) and target = 2R (4 x ATR(14))
  • No holding period was given, so a 20-trading-day time limit is used
  • EMA(20) uses the standard span-20 exponential smoothing; ATR(14) uses Wilder smoothing

The evidence

The laggards decide: 22 large stocks that lagged or fell, where hindsight can't flatter a rule. Today's winners sit beside them to show what survivorship would add.

MarketTradesPer tradet, by tradet, by dayRandom datesWinners, per trade
Bull2,503−0.041R−1.57−0.36 · 1,465d−0.030R · beats 35%+0.117R
Flat470−0.127R−2.19−1.02 · 297d−0.012R · beats 10%−0.058R
Bear173−0.476R−6.01−3.39 · 107d+0.032R · beats 0%+0.077R
All3,146−0.078R−0.024R+0.091R

R is the result per trade in units of the risk taken (entry to stop). Costs are each stock's own trading spread (median 13.6 bps) plus 0.045R for the fills a real order wouldn't get. “By day” groups trades opened the same day, so a rule that fires on the same dates for every stock counts as a few events. “Random dates” places the same plan on random days of the same stocks in the same kind of market, 20 times; the idea must beat 95% of those draws.

The scanner we wroteShow the code
from decimal import Decimal
import math

from core.domain import Bar
from scanners.base import Candidate


class Ema20PullbackInUptrendLong:
    name = "ema20_pullback_in_uptrend_long"
    description = "Long at the close when an uptrend stock touches EMA(20) and closes at or above it; 2 ATR stop, 4 ATR target."

    def __init__(self, ema_period: int = 20, atr_period: int = 14, stop_atr: float = 2.0, target_atr: float = 4.0, extension_atr: float = 1.0, extension_days: int = 5) -> None:
        self._ema_period = ema_period
        self._atr_period = atr_period
        self._stop_atr = stop_atr
        self._target_atr = target_atr
        self._ext_atr = extension_atr
        self._ext_days = extension_days

    def _ema_series(self, closes):
        p = self._ema_period
        if len(closes) < p:
            return None
        alpha = 2.0 / (p + 1)
        val = sum(closes[:p]) / p
        out = [None] * (p - 1) + [val]
        for c in closes[p:]:
            val = alpha * c + (1 - alpha) * val
            out.append(val)
        return out

    def _atr_last(self, highs, lows, closes):
        n = self._atr_period
        if len(closes) < n + 1:
            return None
        trs = []
        for i in range(1, len(closes)):
            trs.append(max(highs[i] - lows[i], abs(highs[i] - closes[i - 1]), abs(lows[i] - closes[i - 1])))
        val = sum(trs[:n]) / n
        for tr in trs[n:]:
            val = (val * (n - 1) + tr) / n
        return val

    def scan(self, ticker: str, bars: list[Bar]) -> Candidate | None:
        if len(bars) < 220:
            return None
        closes = [float(b.close) for b in bars]
        highs = [float(b.high) for b in bars]
        lows = [float(b.low) for b in bars]

        sma50 = sum(closes[-50:]) / 50.0
        sma200 = sum(closes[-200:]) / 200.0
        close = closes[-1]
        if not (close > sma50 and close > sma200 and sma50 > sma200):
            return None

        ema_s = self._ema_series(closes)
        if ema_s is None or ema_s[-1] is None or ema_s[-2] is None:
            return None
        ema_now = ema_s[-1]
        ema_prev = ema_s[-2]

        if not (lows[-1] <= ema_now and close >= ema_now):
            return None

        atr_val = self._atr_last(highs, lows, closes)
        if atr_val is None or atr_val <= 0 or math.isnan(atr_val):
            return None

        prior_above = closes[-2] > ema_prev
        recent_max = max(closes[-(self._ext_days + 1):-1])
        extended = (recent_max - ema_now) >= self._ext_atr * atr_val
        if not (prior_above or extended):
            return None

        entry = bars[-1].close
        atr_dec = Decimal(str(atr_val))
        stop = entry - Decimal(str(self._stop_atr)) * atr_dec
        target = entry + Decimal(str(self._target_atr)) * atr_dec
        if stop <= 0:
            return None
        risk = entry - stop
        if risk <= 0 or not (stop < entry < target):
            return None
        rr = (target - entry) / risk
        if rr < Decimal("1.5"):
            return None

        # strength: trend spread, prior extension, close location
        spread = sma50 / sma200 - 1.0
        trend_score = min(35, max(0, int(spread * 350)))
        ext = (recent_max - ema_now) / atr_val
        ext_score = min(30, max(0, int(ext * 10)))
        rng = highs[-1] - lows[-1]
        pos = (close - lows[-1]) / rng if rng > 0 else 0.5
        close_score = min(35, max(0, int(pos * 35)))
        strength = max(0, min(100, trend_score + ext_score + close_score))

        return Candidate(
            ticker=ticker,
            side="buy",
            entry=entry,
            stop=stop,
            target=target,
            risk_reward_ratio=rr.quantize(Decimal("0.01")),
            signal_strength=strength,
            thesis="Uptrend stock (above SMA50/SMA200, SMA50>SMA200) touched EMA(20) and held on a closing basis after pulling back from above; 2 ATR stop, 2R target.",
        )

Hypothetical results from our own backtest of the rule as restated, on 42 large US stocks over 15 years. Past performance, real or simulated, does not predict future results. Research and education only; not investment advice.

Have an idea of your own?

Describe it in plain words and get the same honest test in about a minute.

Run the Gauntlet
Buy 20-day EMA pullbacks above 50- and 200-day averages: Survivorship mirage · EdgeProven