Skip to content
The Casebook · A classic strategy

Stochastic oscillator crossing above 20, exit above 80

Buy when the stochastic oscillator (14, 3) crosses above 20 from below and sell when it rises above 80.
VerdictTested Nov 22, 2026

Killed by costs

There is something there before trading costs; after them, too little is left to count (under 0.04R a trade).

  • +0.067R a trade before costs, −0.009R after the spread and the selection haircut.
Trades on the laggards
2,757

42 large US stocks, 15 years

Per trade, after costs
−0.009R

Before costs +0.067R

Bar to clear
t > 2.01

By trade and by day, sized to a first try

What the numbers say

Across 2757 laggard trades the result was 0.067R before costs and −0.009R after them, so costs absorb the whole edge. Bull markets gave −0.018R and flat markets −0.022R; only bear markets were positive at 0.075R, with a t value of 2.01 as the bar. The 20 winners averaged 0.071R after costs.

How it was tested

Go long at the close when the stochastic oscillator (14,3) crosses up through 20 from below, and exit at the first close where it is above 80.

Side
Long
Its own exit
Exit at the close of the first day after entry on which the smoothed stochastic (14,3) is above 80., checked at each close
Time limit
Exit at the close after 30 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
  • Stochastic (14,3) taken as slow stochastic: raw %K over 14 bars, smoothed by a 3-bar SMA
  • 'Crosses above 20' means previous day's value <= 20 and today's value > 20
  • 'Sell when it rises above 80' read as closing the long position, not shorting
  • Exit trigger is the smoothed line closing above 80
  • No stop or target named, so a protective 3 x ATR(14) stop and 6 x ATR(14) target were chosen
  • Time limit set to the 30-day maximum since the idea gives none

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
Bull1,910−0.018R−1.00−0.90 · 1,097d−0.044R · beats 90%+0.080R
Flat539−0.022R−0.65−0.52 · 272d−0.047R · beats 65%+0.042R
Bear308+0.075R1.932.17 · 134d+0.037R · beats 85%+0.073R
All2,757−0.009R−0.035R+0.071R

R is the result per trade in units of the risk taken (entry to stop). Costs are each stock's own trading spread (median 14.2 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

from core.domain import Bar
from strategies.indicators import atr
from scanners.base import Candidate


class StochasticCrossAbove20Exit80:
    name = "stochastic_cross_above_20_exit_above_80"
    description = "Long when slow stochastic (14,3) crosses up through 20; exit when it closes above 80."

    def __init__(self, k_period: int = 14, smooth: int = 3, low_level: float = 20.0,
                 high_level: float = 80.0, atr_period: int = 14,
                 stop_mult: float = 3.0, target_mult: float = 6.0) -> None:
        self._k = k_period
        self._smooth = smooth
        self._low = low_level
        self._high = high_level
        self._atr_period = atr_period
        self._stop_mult = stop_mult
        self._target_mult = target_mult

    def _raw_k(self, bars, i):
        # raw %K at index i, using bars[i-k+1 : i+1]
        if i - self._k + 1 < 0:
            return None
        window = bars[i - self._k + 1:i + 1]
        hh = max(b.high for b in window)
        ll = min(b.low for b in window)
        rng = hh - ll
        if rng <= 0:
            return 50.0
        return float(100 * (bars[i].close - ll) / rng)

    def _smoothed(self, bars, last_idx):
        # SMA of raw %K over `smooth` bars ending at last_idx (inclusive)
        vals = []
        for i in range(last_idx - self._smooth + 1, last_idx + 1):
            if i < 0:
                return None
            v = self._raw_k(bars, i)
            if v is None:
                return None
            vals.append(v)
        return sum(vals) / len(vals)

    def scan(self, ticker: str, bars: list[Bar]) -> Candidate | None:
        min_len = max(self._k + self._smooth + 1, self._atr_period + 2)
        if len(bars) < min_len:
            return None
        today = self._smoothed(bars, len(bars) - 1)
        prev = self._smoothed(bars, len(bars) - 2)
        if today is None or prev is None:
            return None
        if not (prev <= self._low and today > self._low):
            return None

        atr_val = atr(bars, self._atr_period)
        if atr_val is None or atr_val <= 0:
            return None
        atr_dec = Decimal(str(atr_val))
        entry = bars[-1].close
        stop = entry - Decimal(str(self._stop_mult)) * atr_dec
        target = entry + Decimal(str(self._target_mult)) * atr_dec
        risk = entry - stop
        if risk <= 0 or stop >= entry or target <= entry:
            return None
        rr = (target - entry) / risk

        return Candidate(
            ticker=ticker,
            side="buy",
            entry=entry,
            stop=stop,
            target=target,
            risk_reward_ratio=rr.quantize(Decimal("0.01")),
            signal_strength=50,
            thesis=f"Slow stochastic (14,3) crossed up through {self._low:.0f} ({prev:.1f} -> {today:.1f}).",
        )

    def exit_now(self, ticker: str, bars: list[Bar], entry: Decimal,
                 side: str, bars_held: int) -> bool:
        if len(bars) < self._k + self._smooth:
            return False
        val = self._smoothed(bars, len(bars) - 1)
        if val is None:
            return False
        return val > self._high

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
Stochastic oscillator crossing above 20, exit above 80: Killed by costs · EdgeProven