# Keltner Channel breakout on NQ futures, 5-minute bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-11-24 (approved by the owner the same day: "Aprob"; draft 1 unchanged)**, before any EMA, ATR, Keltner line, signal or trade of this test was computed. Once frozen, any change of a rule is documented and treated as a separate test; bugs may be fixed.

## Why this test, where the rules come from, and what was looked at before
- **Chosen by the owner** on 2026-11-24 from four untested candidates (Keltner NQ, a 5-minute ORB on ES, a pin bar on gold H1, Williams %R on SPY): "Keltner Channel breakout pe NQ". The design below was agreed the same day: the owner accepted every recommendation of the design questions ("Da, pe recomandări").
- **Not tested on the site: true.**
  - No Keltner breakout test is in `research/registry.js` (92 published tests) or in any of the 104 `research/*_spec.md` files.
  - **Disclosed:** a Keltner Channel is part of the **TTM Squeeze test on gold, 1-hour bars** (`sq_spec.md`, frozen 2026-10-14). There it is SMA(20) +/- 1.5 x ATR(20) and serves only as the squeeze filter (the Bollinger Bands inside the Keltner Channel); no trade was taken on a Keltner break. Its four versions scored 3 to 5 of 6, all Buried (best SQ-L-B 5 of 6). No Keltner line has been computed on NQ.
- **Sources, read on 2026-11-24:**
  - **StockCharts ChartSchool, "Keltner Channels"** (chartschool.stockcharts.com):
    - the **original** (Chester Keltner, *How to Make Money in Commodities*, 1960): a 10-day SMA of the typical price (high + low + close) / 3 as the centre line, +/- the 10-day SMA of the high-low range;
    - the **newer version**, which the page credits to Linda Raschke in the 1980s: **EMA(20) of the closes +/- 2 x ATR(10)**, the StockCharts default "(20, 2.0, 10)". The page also shows 1x and 3x ATR channels;
    - the use: a trend-following indicator, with channel breakouts signalling a new trend, and overbought and oversold levels when the trend is flat. The page warns that sometimes a trend does not take hold after a breakout and prices swing between the lines. It gives **no test results**.
  - **Wikipedia, "Keltner channel":** the same original formula ("the ten-day moving average trading rule"); a close above the upper line read as a strong bullish signal, below the lower line as bearish, traded with the trend. No test results.
  - Investopedia could not be read (the fetch tool refuses the host). Keltner's book was not read; the original formula comes from these secondary sources.
  - **Our choice (agreed):** the newer version with the StockCharts default settings. The original is a daily-chart rule with a simple average; it is named in the article as history and is not tested.
- **Looked at before (disclosed):**
  - **The breakout family** in the guides of 24 Nov 2026: **24 tests, 112 versions**; only two versions pass 6 of 6, both the noise area breakout on NQ in the New York session (NA-NQ-NY-L and NA-NQ-NY-LS, forward test running).
  - **On this NQ file:**
    - noise area breakout (New York 6 of 6; Asia and London 1 to 3 of 6);
    - opening range breakout (best 3 of 6), initial balance breakout (best 4 of 6), first 5-minute candle with a fair value gap (2 of 6), bull and bear flag (best 2 of 6);
    - indicator rules: MACD + RSI + EMA 200 and the EMA 5/8/13 ribbon, both on the continuous chart (best 4 of 6 each); the 9 EMA on a regular-session chart, whose one exit was also a close back through the average (1 of 6);
    - the others: change of character, POC bounce, internal bar strength, the liquidity sweep reversal (2010-2019).
  - **Bands and channels elsewhere:** Donchian channel breakout on ES 1-hour bars (all four 1 of 6), Bollinger Band reversal on ES 1-hour bars (the opposite idea, fading a close outside the band; best 4 of 6), Standard Error Bands on ES 2-minute bars (all 1 of 6). All Buried.
- **Development bar t >= 2.5.** The breakout family has 112 versions on the site, far more than four, so the protocol's stricter bar applies. It is a stricter bar for a crowded family, not a full correction for multiple testing; the article says so.
- **Why it might not work (written before any result):**
  - On 5-minute bars a close 2 ATR from a 20-bar average happens many times a week, often at the cash open and around news. StockCharts itself warns that many breakouts are followed by prices swinging between the lines.
  - The indicators run through the overnight session (the agreed chart). Night bars are quiet, so at 09:35 the channel is often narrow and the cash open's normal volatility can close a bar outside it without any trend. Signals by hour are reported.
  - The breakout family is crowded and has one survivor; a close through a line on NQ was tried by the flag, ORB and initial balance tests without an edge.

## Instrument and data
- **NQ** (E-mini Nasdaq-100 futures), `NQ_1min.csv`, the NinjaTrader export used by every NQ test: a back-adjusted continuous contract, 1-minute bars on the New York clock stamped at their close, all trading hours, with volume.
  - The file runs from 2020-01-01 18:01. It is **cut at 2026-09-25 17:00 New York** (`em_lib.CUT_MIN`), as in every published NQ test.
  - $20 a point, tick 0.25 point ($5). The back-adjustment shifts old prices but not point moves; the Keltner lines and every result in points or dollars are unchanged by it.
- **Regular session:** 09:30 to 16:00 New York, the minutes stamped 09:31 to 16:00. Calendar: `rb_lib.js`, as in our other NQ tests.
  - Early closes at 13:15 (the day after Thanksgiving, 24 December, 3 July when not the holiday) are **short regular sessions**, used, ending at 13:15.
  - The 13:00 closes on US market holidays (the stock market is closed; the futures trade a short holiday session) are **not regular sessions**: no trade is taken on them. Their bars stay on the chart (below), as on any continuous futures chart.
  - Days with no regular-hours minute are not sessions.
- **Periods (by entry date), as in all NQ tests:**
  - development: the file's first regular session (2020-01-02) to 2023-12-31. By its 09:35 bar the indicators have run for about 180 five-minute bars of the overnight session, many times their length;
  - validation: 2024-01-01 to 2025-03-31;
  - holdout: 2025-04-01 to 2026-09-25, **already used** by earlier NQ tests (flagged).

## The chart and the indicators
- **5-minute bars on the continuous chart, overnight session included**, like the default continuous futures chart on most platforms and as in the MACD + RSI + EMA 200 and EMA ribbon NQ tests:
  - bar E holds the minutes stamped E-4 to E (New York clock, stamped at the close); bars are built from the minutes that exist, so a 5-minute slot with no minute has no bar;
  - the bars run through the overnight session, the 13:00 holiday sessions, the daily break and weekends (no bars there) and the rolls (back-adjusted, no jump).
  - **Trades are taken only in the regular session** (day trading).
- **EMA(20)** of the 5-minute closes, alpha = 2 / 21, seeded with the simple average of the first 20 closes of the file.
- **ATR(10), Wilder's method**, on the same bars:
  - true range = the bar's high and low, extended to the previous bar's close (across the daily break and weekends too, as a chart does);
  - the file's first bar: its own high minus low;
  - seeded with the simple average of the first 10 true ranges, then ATR = (9 x the previous ATR + TR) / 10.
- **Keltner lines at bar k:** middle M(k) = EMA(20)(k); upper U(k) = M(k) + 2 x ATR(10)(k); lower D(k) = M(k) - 2 x ATR(10)(k). Bar k's own close, high and low are in its values (the line printed at the bar's close, as on the chart).

## The signal (fixed here)
Evaluated **at the close of each 5-minute bar k**, using bars up to and including k only.
- **Long signal:** close(k) > U(k) **and** close(k-1) <= U(k-1), where k-1 is the previous bar on the chart (at 09:35 an overnight bar). A close strictly above the line (tolerance 1e-9 point); a close exactly on it is no signal.
- **Short signal:** close(k) < D(k) **and** close(k-1) >= D(k-1).
- The previous-close condition makes each signal a **fresh break**: a run of closes outside the line gives one signal, at its first bar. A new signal needs a close back inside (or on) the line first.
- **Signal window:** signal bars stamped **09:35 to 15:30** New York; on a 13:15 day up to 12:45 (30 minutes before the close, as in the MACD + RSI NQ test). No signal on a 13:00 holiday session or outside regular hours.

## Trades
- **Entry:** at the **open of the first minute after the signal bar**, inside the same session. No such minute: no trade.
- **One position at a time** per version; a signal at the close of a bar at which the version still holds a position is ignored, even if that same bar triggers the exit (no reversal on one bar). A signal not taken is not stored.
- **Long only versions (-L):** short signals are ignored. **Long and short versions (-LS):** both.
- **No stop and no target** in any version; the only exits are below.
- **Exits:**
  - **KC-MID (the middle line):** at the close of each 5-minute bar from the bar that holds the entry minute, a long exits if the bar closes **at or below the middle line** M (a short: at or above M). The exit fills at the **open of the next minute**. Otherwise out at the session close. Several trades a session are possible.
  - **KC-CL (session close):** the position is held to the session close. At most one trade a session per version (a later signal comes while the position is open).
  - **Session close:** the close of the last minute stamped at or before 16:00, or 13:15 on a short session. If the middle-line exit is triggered by the last bar of the session (16:00 or 13:15), the trade closes at that minute's close (the session close). Every trade is closed the same session, so the test belongs in the day-trading guide.

## Versions (4: the two agreed exits x the two directions)
1. **KC-MID-LS:** middle-line exit, long and short.
2. **KC-MID-L:** middle-line exit, long only.
3. **KC-CL-LS:** held to the session close, long and short.
4. **KC-CL-L:** held to the session close, long only.

**Why only these:** EMA 20, ATR 10 and the multiplier 2 are the StockCharts defaults and are not varied. The fresh-break rule, the 09:35-15:30 window and the next-minute entry are the only readings added, each fixed once. The opposite band as an exit would almost never be reached within a session on 5-minute bars (it would be the session close in practice), and a trailing stop would add a free parameter; neither is tested. Long only is a separate version because NQ rose strongly in 2020-2026; in the LS versions longs and shorts are reported separately but not gated separately.

## Costs
- **$15.76 per round trip per contract**: commission $5.76 plus one tick of slippage ($5) on each fill, as in all NQ tests. Also shown at 1.5x and 2.5x (descriptive). No position is held overnight, so there is no roll or financing cost.
- Results in **dollars per contract** (and points). There is no stop, so no R unit; the channel half-width 2 x ATR(10) at the signal bar is reported as a scale (with the cost as a share of it).

## Expected number of trades (a guess from the rule, not computed)
Development has about 1,000 regular sessions, validation about 310, the holdout about 370. A fresh close beyond a 2-ATR line on 5-minute bars should happen at least once on most sessions, and several times on many. **Expected: KC-MID about 1 to 4 trades a session (LS) and KC-CL at most one, on most sessions; several hundred to a few thousand trades per version in development, and well above 50 in every period.** The 50-trade gate should not bind. If it does, the protocol applies unchanged.

## Gates and control
- **Six gates per version** (net dollars per contract):
  1. validation profit factor >= 1.2;
  2. at least 50 trades in each period;
  3. development **t >= 2.5**;
  4. above the 95th percentile of the control;
  5. positive without the 10 best trades;
  6. holdout net positive (flagged as used).

  A version with fewer than 30 trades in all is Inconclusive.
- **Control (moved entries), as in the flag, POC and MACD + RSI NQ tests:**
  - every real trade keeps its entry time of day, its direction and its exit rule (KC-MID: the middle-line exit on the new day's chart; KC-CL: the session close);
  - all trades move together to other regular sessions by one random circular offset of whole sessions, at least 5% of them;
  - on the new day each trade enters at the market, at the open of the first minute at or after the same time; a trade that would start after that session's close is dropped;
  - each moved trade is simulated on its own, with the same costs (moved trades may overlap; the one-position rule does not apply to them);
  - 500 runs, seeds 1000 + run. Statistic: the average net dollars per trade.
  - It asks whether the Keltner break picks better moments than the same trades placed on other days.
- **Rule 3 (data holes):**
  - the suspect data: the NQ holes in `data_holes.json`, plus any run of 10 or more missing minutes inside regular hours, any session with unusually low regular-hours volume and the mis-stamped days found by the data check;
  - a trade is flagged if suspect data lies between 20 five-minute bars before its signal bar (the EMA's length) and its exit, or it is taken on a suspect session;
  - flagged trades are reported, and every gate and verdict is recomputed without them; a changed verdict becomes Inconclusive.

## Extra check on 2010-2019 (only if a version passes all six gates)
- If any version passes 6 of 6, that version (and only that one) is run **once** on `data_nq_old/NQ_1min.csv` (the second NinjaTrader export, 2010-2026, checked for the LSR test on 2026-11-16) over **2010-01-04 to 2019-12-31**: the same rules, the same cost, the same control (500 runs), the same rule 3 with that file's holes.
- It is **reported separately** (net per trade, t, profit factor, control percentile, by year) and **does not change the six-gate verdict**. The article reports it next to the verdict.
- The cost weighs more there: $15.76 is 0.79 point against median NQ day ranges of 30-60 points in 2010-2017 (210-490 in 2020-2026).
- If no version passes, these years are not touched.

## Also reported (descriptive; nothing here can change a rule or a verdict)
- **The funnel:** long and short signals in the window; taken, ignored (position open), untradable (no next minute); signals outside the window (counted, not traded).
- **Signals and results by hour of entry**, with the 09:35 bar on its own (the open question above).
- Exits by reason (middle line, session close); holding time; channel half-width (2 x ATR) in points and the cost as a share of it; the distance from the entry to the middle line at entry.
- Win rate with its Wilson interval; best and worst move within each trade in points; trades per session; longs and shorts; by year; drawdown on closed trades.
- The share of KC-MID trades that reached the opposite band before the session close (to show what the excluded exit would have meant).

## Data check (automated, after the freeze, before any indicator)
`keltner_datacheck.js`, written to `keltner_out/keltner_datacheck.txt` (the same items as the flag test's check of this file, plus the overnight bars):
1. First and last stamp and the cut; the file sorted with no duplicate stamp; every price on the 0.25 grid; high >= open, close >= low; no zero or negative price; minutes with zero volume counted.
2. Every New York weekday classed by the calendar: regular (16:00), short (13:15), market holiday with a 13:00 futures session, closed. Expected and found regular-hours minutes per session; sessions per year and per period.
3. Missing minutes inside regular hours: every run of 10 or more listed; sessions whose first minute is not 09:31 or whose last minute is not the close listed; compared with `data_holes.json` (NQ). 5-minute bars with fewer than 5 minutes counted, inside and outside regular hours.
4. **Overnight bars:** 5-minute bars per overnight session (18:00 to 09:30) and per year; overnight gaps of 30 minutes or more outside the daily break and weekends listed.
5. **Mis-stamped days:** the share of each session's volume inside regular hours, with outliers listed (the week of 2020-10-19 to 2020-10-22 was mis-stamped in the ES and NQ files).
6. Roll days: the session-open gap and the largest 1-minute move against other days; any 1-minute move above 1% listed. Sessions with regular-hours volume below 30% of the median of the previous 20 sessions are listed (for rule 3).

The check computes no EMA, ATR, line, signal or trade. Its result is reported with the run.

## Engine and self-test (before the run)
- An engine, `keltner_lib.js`.
- A **separate re-implementation**, `keltner_ref.js`, written from this specification without the engine's code: its own reader, its own calendar lists, its own bars, EMA, ATR, signals and exits. It is written by the same author (Claude), not by another agent, to save cost, as in the flag and Market Profile tests; that is stated. It reports trade counts only before the comparison.
- A self-test, `keltner_selftest.js`:
  1. EMA(20) and ATR(10) by hand on built bars: the seeds, a true range across the daily break and across a weekend, the Wilder step.
  2. Hand-built signals: a close exactly on U (no signal) and 1 tick above (signal); a second close above U after one above (no signal); a close back inside then out again (a new signal); the mirror for shorts; a 09:35 signal whose previous bar is overnight; the 09:35 and 15:30 window edges, a 13:15 day (12:45) and a 13:00 holiday (bars on the chart, no trade).
  3. Hand-built trades: the entry minute; no next minute; a signal while a position is open; an exit bar that also signals the other way (ignored); long only ignoring shorts; the middle-line exit at the next minute's open, at or beyond M; an exit triggered by the last bar (session close); KC-CL one trade a session; the session close at 16:00 and 13:15 and with the last minute missing.
  4. **No look-ahead (truncation test):** the data cut at 50 random minutes; every signal, entry and middle-line exit before each cut must be identical to the full run's.
  5. Engine against reference, trade by trade, for the four versions on the real data.
  6. The control at offset 0 equal to the real trades.
  7. **Mutations** that must be detected (the engine changed, the reference not):
     - an SMA(20) instead of the EMA;
     - a simple ATR instead of Wilder's;
     - a multiplier of 1.5;
     - the fresh-break condition removed;
     - the entry at the signal bar's own close (look-ahead);
     - indicators on regular-hours bars only;
     - the middle-line exit taken at the bar's close instead of the next minute's open.
- `keltner_run.js` refuses to run unless this file is frozen (its sha256 matches the one in `keltner_lib.js` and the run log) and the self-test passed on the current code. **One run**; outputs in `keltner_out/`. A second run is refused; `node keltner_run.js --reproduce` recomputes everything into a scratch folder and checks it against the saved outputs without replacing them.

## Before the article
- Results go to the owner first (in Romanian), with every version and every gate.
- One article, only if the owner asks for it; the pace is 3 to 4 posts a week. Deploys only with the owner's explicit agreement.
- Working title: "Keltner Channel Breakout Strategy Backtest: NQ Futures, 5-Minute Bars". The page must say that the bands run through the overnight session and that shorts are in two of the versions.
- If it is published, the test joins the day-trading guide at the next weekly recompute. NQ only: ES or other markets would be separate tests and separate posts, only if the owner picks them.

## Reading the result
"Buried" or "Inconclusive" mean a convincing edge was not demonstrated, not proof that none exists. The result covers one market, one 5-minute chart, the default Keltner settings and two exits. Other lengths, multipliers, timeframes or filters are other tests; none will be tried after seeing this result.

### Run log
- 2026-11-24: draft 1 written. Nothing computed on the rule or the data. Sources read (StockCharts ChartSchool, Wikipedia; Investopedia refused by the fetch tool). The registry and all specs were searched: no Keltner breakout test; the TTM Squeeze gold test's Keltner filter disclosed. The owner accepted every design recommendation ("Da, pe recomandări"); the draft waits for "Aprob".
- 2026-11-24: frozen (owner: "Aprob"), draft 1 unchanged apart from this status line. sha256 of this file above the "### Run log" heading: 5d6c5fa737d43e7c43d00677d08344f19350da86525f5628369d01689e5a1ba4.
- 2026-11-24, the data check (`node keltner_datacheck.js`, `keltner_out/keltner_datacheck.txt`), before any EMA, ATR, line or signal:
  - the same file as the flag test (SHA-256 7980d835...) and the same findings: 2,373,779 minutes to the cut, no backward or duplicate stamp, every price on the grid; 1,677 regular and 12 short (13:15) sessions, 46 market holidays with a 13:00 futures session (not sessions here), 22 closed weekdays; regular sessions by period 1,005 / 312 / 372; ten runs of 10 or more missing minutes inside regular hours; the mis-stamped week 2020-10-19 to 2020-10-22; 18 low-volume sessions.
  - Item 4, the continuous chart: 475,280 five-minute bars, 343,979 outside regular hours (1,340 with fewer than 5 minutes), none mixing regular and other minutes; a median of 186 overnight bars before each regular session. 96 gaps of 30 minutes or more other than the daily break and the weekend, mostly holiday closes; the unusual ones (March 2020 nights, 2021-10-03, 2022-11-06/07, 2023-04-05, 2025-08-28/29, 2025-11-27/28, 2026-01-18, 2026-01-22 to 25, 2026-06-11) are all windows of `data_holes.json`.
- 2026-11-24, before the run: `keltner_lib.js` (engine; it reuses flag_lib's reader and session list), `keltner_ref.js` (the separate re-implementation: its own reader, NYSE lists, bars, EMA and ATR formulas and one chronological pass with a position state per version) and `keltner_selftest.js` written. The reference reported its counts first: 5,543 signals; trades 2,962 (KC-MID-LS), 1,460 (KC-MID-L), 1,599 (KC-CL-LS), 1,116 (KC-CL-L).
  - The first self-test run failed 2 of 54 checks, both in one hand-built case of the test itself: 70 flat bars before the break put it on the 15:25 bar, not 15:30 (bar 0 is 09:35); changed to 71 and 72 bars. No engine or reference code changed. The self-test then PASSED: 54 checks (37 hand-built indicator, signal and trade checks; 50 truncation cuts with 126,442 signal and 67,935 trade comparisons, all identical; engine = reference trade by trade for the four versions, with the same sessions, bars and signals; the control at offset 0; seven mutations caught). It prints no average of the real trades.
  - The spec's trade-count guess held: KC-MID-LS 1.85 trades a trading session; KC-CL one trade on 1,599 of 1,689 sessions.
- 2026-11-24, the run (`node keltner_run.js`, once, 500 control runs, outputs in `keltner_out/`): **all four Buried; every one positive before and after costs, none passes the development t bar.**
  - Funnel: 5,543 signals (2,847 long, 2,696 short), 3.28 a session, 431 on the 09:35 bar; median channel half-width 48.73 points against a cost of 0.79 point.
  - **KC-MID-LS 4 of 6:** 2,962 trades (1,836 / 532 / 594), +$63.09 a trade net (gross +$78.85), PF 1.11; win rate 39.8%; DEV t 0.54 (fail), VAL PF 1.1955 (fail, shown as 1.20), control 100th percentile (beat all 500 runs), without the 10 best +$43,311, holdout +$94,304.
  - **KC-MID-L 4 of 6:** 1,460 trades, +$84.81 (gross +$100.57), PF 1.17; DEV t 1.12, VAL PF 1.18, control 99.2nd, without the 10 best +$19,088, holdout +$55,812.
  - **KC-CL-LS 4 of 6:** 1,599 trades, +$125.97 (gross +$141.73), PF 1.11; DEV t 0.75, VAL PF 1.18, control 97.0th, without the 10 best +$48,917, holdout +$78,507.
  - **KC-CL-L 3 of 6:** 1,116 trades, +$119.20 (gross +$134.96), PF 1.12; DEV t 0.89, VAL PF 1.13, control 89.8th (fail), without the 10 best +$11,609, holdout +$49,312.
  - Rule 3 (36 / 11 / 22 / 13 trades flagged) changes no verdict; without its trades KC-MID-LS passes 5 of 6 (still Buried on DEV t).
  - No version passed all six gates, so the 2010-2019 data was not touched.
  - `node keltner_run.js --reproduce` recomputed all 11 output files identically; a second run is refused. Nothing was rerun or changed.
- 2026-11-24, the article: the owner asked for it ("Da, scrie-l"). `build_keltner_post.js` builds it from the outputs of the single run, unchanged, and asserts every number and claim it prints; `wire_keltner.js` wires it on the publication day, only with the owner's OK. A rerun from the post's own files (the data check, the self-test and the run, with NQ_1min.csv one folder above) reproduced every output byte for byte, apart from the dated first lines and the timing lines. Added in the article only, computed from the run's files (descriptive): the shares of each version's net by period, in its 10 best trades and on the 09:35 bar, the best trade's date (2025-04-09) and the monthly equity. **This specification's guess that the opposite band "would almost never be reached within a session" was wrong:** a bar closed beyond it before the session close in 34.4% of KC-MID-LS trades and 45.2% of KC-CL-LS trades; the article says so.
- 2026-11-24: published as /posts/keltner-channel-breakout-strategy-nq/ on 24 Nov 2026 (the owner asked for the article on 2026-11-24: "Da, scrie-l"; deployed with the owner's explicit agreement).
