Skip to content
The Casebook · An idea an AI invented

Gap up on volume, then tight range, buy at a 5-day high

Entry at latest close if within the last 8 sessions a gap up of at least 4% occurred on volume at least 2x average, the close stays above the midpoint of the gap-day range, the last 3 sessions' ranges are below the 10-day average range, and the close is at a 5-day high. Stop below the gap-day low. Target 3 ATR above.
Why the AI thought it might work

After a large gap up on volume, funds that missed the move build positions gradually, so tight consolidation holding the gap's upper half shows supply being absorbed and the late buyers still need to be filled. Late-arriving institutional demand drives continuation as the narrowing completes.

VerdictTested Nov 22, 2026

Too rare to judge

Too few trades in 15 years to tell anything either way.

  • 11 trades on the laggard stocks in 15 years; 30 are needed to judge.
Trades on the laggards
11

42 large US stocks, 15 years

Per trade, after costs
−0.127R

Before costs +0.004R

Bar to clear
t > 2.95

By trade and by day, sized to 362 rules

What the numbers say

The laggard stocks gave only 11 trades in 15 years, short of the 30 needed, and averaged −0.127R per trade after costs. Bull markets showed 8 trades at −0.43R, flat markets 3 trades at 0.68R, and bear markets none. The winners averaged 1.275R, but with so few laggard trades the verdict is too rare to judge.

How it was tested

The rule as written, coded once, run on every stock the same way.

Side
Long
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.95, by trade and by day, sized to the 362 rules in the search it came from
Prices
15 years of daily bars through 2026-11-20; judged 2026-11-22

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
Bull8−0.430R−0.92−0.92 · 8d+0.042R · beats 10%+0.880R
Flat3+0.680R0.750.75 · 3d−0.093R · beats 90%+1.801R
Bear0—————
All11−0.127R+0.005R+1.275R

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


class NarrowRangeWeekAfterGapUpHoldLong:
    name = "narrow_range_week_after_gap_up_hold_long"
    description = "Held 4%+ volume gap-up followed by pre-gap-relative range compression and a 5-day closing high"

    def __init__(self, gap_pct: float = 0.04, vol_mult: float = 2.0, max_lookback: int = 8,
                 min_post_bars: int = 3, base_len: int = 10, atr_len: int = 14,
                 target_atr: float = 3.0, stop_buf_atr: float = 0.1, min_rr: float = 1.5) -> None:
        self._gap_pct = gap_pct
        self._vol_mult = vol_mult
        self._max_lookback = max_lookback
        self._min_post = min_post_bars
        self._base_len = base_len
        self._atr_len = atr_len
        self._target_atr = target_atr
        self._stop_buf = stop_buf_atr
        self._min_rr = min_rr

    def scan(self, ticker: str, bars: list[Bar]) -> Candidate | None:
        n = len(bars)
        if n < 60:
            return None
        i = n - 1
        o = [float(b.open) for b in bars]
        h = [float(b.high) for b in bars]
        l = [float(b.low) for b in bars]
        c = [float(b.close) for b in bars]
        v = [float(b.volume) for b in bars]

        # Find most recent qualifying gap day, leaving >= min_post bars after it
        g = None
        avg_v_g = 0.0
        for k in range(i - self._min_post, i - self._max_lookback, -1):
            if k < 25:
                break
            pc = c[k - 1]
            if pc <= 0 or o[k] < pc * (1.0 + self._gap_pct):
                continue
            prev_vols = v[k - 20:k]
            avg_v = sum(prev_vols) / 20.0
            if avg_v <= 0 or v[k] < self._vol_mult * avg_v:
                continue
            g = k
            avg_v_g = avg_v
            break
        if g is None:
            return None

        gap_hi, gap_lo = h[g], l[g]
        if gap_hi <= gap_lo:
            return None
        mid = (gap_hi + gap_lo) / 2.0
        # Gap must be held: every post-gap close above the gap-day midpoint
        for k in range(g + 1, i + 1):
            if c[k] <= mid:
                return None

        # Contraction baseline from bars strictly BEFORE the gap (percent ranges)
        base = [(h[k] - l[k]) / c[k] for k in range(g - self._base_len, g) if c[k] > 0]
        if len(base) < self._base_len:
            return None
        base_r = sum(base) / len(base)
        if base_r <= 0:
            return None
        last3 = [(h[k] - l[k]) / c[k] for k in range(i - 2, i + 1)]
        if any(r >= base_r for r in last3):
            return None
        comp_ratio = (sum(last3) / 3.0) / base_r

        # Close at a 5-day closing high
        if c[i] < max(c[i - 4:i + 1]):
            return None

        # ATR excluding the gap bar's true range so the shock doesn't inflate it
        trs = []
        for k in range(i, 0, -1):
            if k == g:
                continue
            tr = max(h[k] - l[k], abs(h[k] - c[k - 1]), abs(l[k] - c[k - 1]))
            trs.append(tr)
            if len(trs) >= self._atr_len:
                break
        if len(trs) < self._atr_len:
            return None
        atr_v = sum(trs) / len(trs)
        if atr_v <= 0:
            return None

        entry = bars[-1].close
        stop_f = gap_lo - self._stop_buf * atr_v
        target_f = c[i] + self._target_atr * atr_v
        stop = Decimal(str(round(stop_f, 4)))
        target = Decimal(str(round(target_f, 4)))
        if not (stop < entry < target):
            return None
        risk = entry - stop
        if risk <= 0:
            return None
        rr = (target - entry) / risk
        if rr < Decimal(str(self._min_rr)):
            return None

        # Strength: compression depth, gap volume, hold quality, gap size
        comp_score = min(35.0, max(0.0, (1.0 - comp_ratio) * 60.0))
        vol_score = min(25.0, max(0.0, 8.0 + (v[g] / avg_v_g - self._vol_mult) * 6.0))
        hold_pos = (c[i] - mid) / max(gap_hi - mid, 1e-9)
        hold_score = min(20.0, max(0.0, hold_pos * 15.0))
        gap_size = o[g] / c[g - 1] - 1.0
        gap_score = min(20.0, max(0.0, (gap_size - self._gap_pct) * 300.0))
        strength = int(max(0, min(100, round(comp_score + vol_score + hold_score + gap_score))))

        days_since = i - g
        thesis = (
            f"{gap_size * 100:.1f}% gap-up {days_since} sessions ago on {v[g] / avg_v_g:.1f}x volume; "
            f"price held above gap-day midpoint {mid:.2f} while last 3 ranges compressed to "
            f"{comp_ratio * 100:.0f}% of the pre-gap baseline, now a 5-day closing high. Late institutional "
            f"demand absorbing supply should drive continuation; stop under gap-day low, target 3 ex-gap ATR."
        )

        return Candidate(
            ticker=ticker,
            side="buy",
            entry=entry,
            stop=stop,
            target=target,
            risk_reward_ratio=rr.quantize(Decimal("0.01")),
            signal_strength=strength,
            thesis=thesis,
        )

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
Gap up on volume, then tight range, buy at a 5-day high: Too rare to judge · EdgeProven