# EMA 5/8/13 ribbon on NQ futures, 5-minute and 15-minute bars, US session - frozen specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-08 (approved by the owner the same evening), before any EMA 5/8/13 value, signal or trade was computed on NQ.** Any later change of a rule is documented and treated as a separate test; bugs may be fixed.

## What was looked at before, and why this test
- The owner picked the strategy (a popular scalping ribbon) and the market. The NQ file was used once before, by the EMA 9/21 test on 1-hour bars (ES, NQ, GC): no variant passed; NQ long only with no stop had the highest development t-statistic (1.98).
- The data audit of the NQ file (`data_manifest.md`, `data_holes.json`).
- No EMA 5/8/13 number on NQ was looked at.

## What is tested
**Entry when EMA 5, 8 and 13 line up**, exit when the alignment breaks, on **E-mini Nasdaq-100 futures (NQ)**, **5-minute (M5) and 15-minute (M15) bars**, **US session only**, long only and long and short, with no stop and with a 1 R stop and a 2 R target. One article, two timeframes. Other periods, timeframes, sessions and filters are not tested here and will not be tried after seeing the result.

## Data
- `NQ_1min.csv` (NinjaTrader, back-adjusted, SHA-256 in `data_manifest.md`), **2020-01-01 to 2026-09-25 17:00 New York**, the same cut as every futures test. $20 a point, tick 0.25.
- Holes: the NQ windows of `data_holes.json` (rule 3 of `data_manifest.md`): nothing is filled; trades open across a hole are counted and every gate and verdict is recomputed without them (gate 4 from the run); a changed verdict becomes Inconclusive. Because positions are closed every day, a hole inside a trade is rarer here than in the hourly tests.
- **The data is not fresh:** NQ 2020 to 2026 was used by the EMA 9/21 test.

## Rules
- **Bars:** M5 and M15 bars built from the 1-minute file (bar time = close time, New York clock; a bar holds the minutes with close times in (t - 5 or 15 min, t]). The averages and the ATR run on **all bars of the electronic session** (the chart default), so the ribbon exists at the US open; only trading is restricted to the US session.
- **Averages:** EMA(5), EMA(8), EMA(13) of the bar closes, each seeded with the simple average of its first n closes, then ema[k] = a x close[k] + (1 - a) x ema[k-1], a = 2 / (n + 1).
- **Alignment** at the close of bar k: **bull** if EMA5 > EMA8 > EMA13; **bear** if EMA5 < EMA8 < EMA13; otherwise none (differences below 1e-10 count as ties, i.e. not aligned).
- **Entry:** when an alignment **starts** at the close of bar k (bull at k and not bull at k-1: a long; bear at k and not bear at k-1: a short in the long-short versions), and the bar closes inside the US session window: after 09:30 and no later than 15:55 (M5) or 15:45 (M15) New York. Filled at the open of the next 1-minute bar. An alignment that started before the window does not give an entry later; only a new start does.
- **Exit:** at the open of the next 1-minute bar after the first bar whose close no longer shows the position's alignment; or at the stop or target (T2 versions); or **at the close of the 16:00 New York 1-minute bar**, or of the day's last bar if the market closes earlier (early-close days). No position is held overnight.
- **R = 1.5 x ATR(14)** of the bars of that timeframe at the signal bar. Stop 1 R; target 2 R; if a stop and a target are touched in the same minute the stop is taken; a level gapped through fills at the open of that minute.
- **8 variants (the only ones tested):** 2 timeframes x long only (L) and long and short (LS) x **N** (no stop, no target: exit on the broken alignment or at 16:00) and **T2** (stop 1 R and target 2 R, plus the same rule exits). Named `RB-M5-L-N` ... `RB-M15-LS-T2`.

## Costs, periods, units
- **Costs:** commission $5.76 per round trip plus one tick ($5) of slippage on every fill, **$15.76 a trade**, as in the EMA 9/21 test. No position is held through a contract roll or overnight, so there is no roll or financing cost. The commission is an assumption, not a broker quote.
- **Periods (by entry date):** development 2020-01-01 .. 2023-12-31; validation 2024-01-01 .. 2025-03-31; holdout 2025-04-01 .. 2026-09-25 (already used by the EMA 9/21 test, so not clean).
- **Units:** net R per trade, non-compounded; dollars per contract next to it.

## Gates and verdicts
Six gates per variant: validation profit factor >= 1.2; at least 50 trades in each period; development t >= **2.5** (more than four variants are tried: 8); above the 95th percentile of 500 runs of the matched control; positive without the 10 best trades; holdout net positive (flagged used). Fewer than 30 trades: Inconclusive; otherwise Buried or Survivor.

## Matched control
A circularly shifted state-series control: the state series (+1 bull alignment, -1 bear alignment, 0 none) of each timeframe is shifted by a random offset of at least 5% of its length and applied to the real prices with the same rules (entries only on a new alignment inside the session window, exits on the broken alignment, the stop, the target or 16:00) and the same costs, R recomputed at the shifted signal time. 500 runs, seeds 1000 + run, the same shifts for every variant of a timeframe. Statistic: average net R per trade.

## Engine and self-test (before the run)
The hourly engine exits only on an opposite signal; this test needs exits on a broken alignment and at the session end, so a small new simulation module is written for it. Before the run its self-test must pass: hand-built cases (entry on a new alignment only, no entry before 09:30 or after the last signal time, exit on a broken alignment, forced exit at 16:00 and on an early-close day, a stop and a target in the same minute, a stop in the entry minute, a level gapped through); the M5 and M15 bars against a naive aggregation; the three EMAs and the alignment against a naive recomputation; an independent re-implementation of the trade simulation matched trade by trade for all 8 variants; the shifted control with shift 0 reproducing the real trades. No result is printed.

## Before the article
The results go to the owner first: every variant, drawdown on closed trades and including open positions, the hole sensitivity. The article is built only after that.

## Always reported
Win rate with its 95% Wilson interval, how trades ended (broken alignment, stop, target, 16:00), average minutes held, long and short separately, gross and cost per trade in R, drawdown on closed trades and including open losses, the result by year, and the sign of every result in R and dollars.

## Bug fixed after the run, before publication (2026-10-08)
The forced exit used the last 1-minute bar of the day not after 16:00, so a data hole in the afternoon was treated as the session close (on 2023-04-05 the NQ data stops at 14:03). It now uses the exchange calendar of the US session close (16:00; 13:00 on US holidays when the market is open and on Thanksgiving; 13:15 on the day after Thanksgiving, 24 December and 3 July when they are not the observed holiday; 09:30 on 9 January 2025), checked against the ES and NQ data (every day matches except the known NQ hole). When a hole covers the scheduled close, the position leaves at the first price after it. Four 5-minute trades changed (about -0.2 R on each 5-minute variant); no 15-minute trade, gate or verdict changed. No rule was changed.
