# Intraday momentum: first half-hour -> last half-hour, on ES and NQ futures - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-11 (approved by the owner the same day, draft 1 unchanged)**, before any first- or last-half-hour return was computed for this test.

## The idea and why it was chosen
- Chosen by the owner on 2026-10-11 ("First Half-Hour -> Last Half-Hour, ES and NQ"); two separate articles, one per market, and both definitions of the first half-hour, chosen from proposals the same day.
- The idea is the "market intraday momentum" result of Gao, Han, Li and Zhou (Journal of Financial Economics, 2018): on the S&P 500 ETF, the return of the first half-hour (from the previous close to 10:00 New York) predicted the return of the last half-hour. We test the rule, not the paper's statistics.
- Earlier tests on these files: several ES studies, the EMA 9/21 test (ES, NQ, GC) and the EMA 5/8/13 ribbon (NQ). No first- or last-half-hour number was looked at.

## Rules
- **Signal at 10:00 New York** (the close of the 1-minute bar ending 10:00):
  - **OV** (as in the paper): first-half-hour return = price at 10:00 - the close of the previous US session (16:00, or the earlier scheduled close on early-close days);
  - **RTH** (session only): price at 10:00 - the open of the session (the open of the 1-minute bar starting 09:30).
  - Positive: long; negative: short (in the long-only variants, no trade); exactly zero: no trade.
- **Trade:** enter at the open of the 1-minute bar starting **30 minutes before the scheduled close** (15:30, or 12:30 / 12:45 on early-close days), exit at the close of the bar ending at the scheduled close. One contract, one trade a day at most. The scheduled close comes from the exchange calendar used in the ribbon test (`rb_lib.js`); the day of 9 January 2025 (closed at 09:30) has no trade.
- **Missing data:** if any of the needed minute bars (the reference price, 10:00, the entry bar, the exit bar) is missing, the day has no trade and is counted. Prices are never filled.
- **Four variants per market:** **OV-LS, OV-L, RTH-LS, RTH-L** (LS = long and short, L = long only), named IM-ES-... and IM-NQ-...; eight in total.

## Data and costs
- **ES:** `ES_1min.csv` (NinjaTrader, back-adjusted, SHA-256 ce7d44...), **NQ:** `NQ_1min.csv` (SHA-256 7980d835...), both from 2020-01-01 to **2026-09-25 17:00 New York** (the common end of the futures studies). Back-adjustment shifts prices by constants at rolls, which changes no return inside a day.
- **Costs per round trip:** ES **$30.76**, NQ **$15.76** (commission $5.76 plus one tick of slippage on each fill), as in all our ES and NQ tests. Point values: ES $50, NQ $20.
- **Holes (rule 3):** the known holes of each file (`data_holes.json`); days whose needed bars fall in a hole have no trade, and days touching a hole are reported.

## Periods, gates, control
- Periods by trade date: development 2020-2023, validation 2024-01 to 2025-03, holdout 2025-04 to 2026-09 (**already used** by the earlier ES and NQ tests).
- Six gates per variant, results in dollars per contract: validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.5** (eight variants of this idea are tried); above the 95th percentile of the control; positive without the 10 best trades; holdout net positive (flagged used). Fewer than 30 trades: Inconclusive.
- **Control:** the series of daily signals (long, short or none) is circularly shifted by a random offset of at least 5% of the number of days and applied to the real last half-hours, with the same costs; 500 runs, seeds 1000 + run. It asks whether the first half-hour says anything about the last half-hour beyond how often and in which direction the rule trades.
- Also reported: the average last-half-hour move, an always-long last half-hour for reference, the win rate with its Wilson interval, long and short separately, results by year, before and after costs.

## Engine and self-test (before the run)
A new engine (`ih_lib.js`) using the existing futures loader and exchange calendar. Self-test: hand-worked days (both signals, long, short, zero, an early-close day, a missing bar), the session close against the calendar on the real data, an independent re-implementation matched trade by trade for all eight variants, and the control at offset 0 reproducing the real trades. No result is printed.

## Before the articles
Results go to the owner first. Then two articles, one for ES and one for NQ, each published only with the owner's agreement.
