# XAUUSD M5 trend pullback: 1-hour EMA 200 trend, 5-minute EMA 20/50 alignment, pullback to the EMA 20 with a confirmation candle - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-28 (approved by the owner the same day, draft 1 unchanged: "Da, îngheaț-o")**. Once frozen, any change of a rule is documented and treated as a separate test; bugs may be fixed. No bar, average, signal or trade of this test has been computed. (A data check only was run before freezing: the number of gold minutes per calendar year, below.)

## Why this test, where the rules come from, and what was looked at before
- **Proposed by the owner** on 2026-10-28 as a generic, mechanical intraday trend-pullback rule for gold (not taken from a named video or author), then tightened in three rounds of discussion the same day (the minimum stop, the trading window, the costs, the forward test). The rules below are those agreed; where a choice was left open, it is fixed here and marked as ours.
- **The idea:** trade only with the 1-hour trend; on the 5-minute chart wait for the fast averages to agree, for a pullback to the 20-period EMA and for a candle closing back in the trend's direction; enter on the next candle; stop beyond the pullback; fixed target in R; London and New York morning only.
- **Looked at before on this gold file (disclosed):** 16 strategies in 105 versions (the gold hub), among them the **EMA 9/20 crossover** on 15-minute and 1-hour bars (all 12 15-minute versions lost after costs, about 0.16 R of cost a trade), **RSI 30/70 on 5-minute bars** (all lost), **Brad Goh's 5-minute sweep model with a 1-hour and 15-minute trend filter** (buried), the **H1 Open Trap** (a median stop of $1.37; costs about 0.29 R a trade) and TheStrat on 60-minute bars (buried by costs). On other files: MACD + RSI with a 200 EMA trend filter on NQ 5-minute bars (buried). Trend-filtered entries on fast gold charts have been tried several times and lost mainly to costs; that is why the stop has a minimum and why the bar below is t >= 2.5. **The results are exploratory:** the holdout years have been used before and cannot confirm anything independently.

## Instrument and data
- **XAUUSD** spot, IC Markets MT4 demo, 1-minute **bid** bars, 2004-06-11 to **2026-10-07 16:57 New York**, loaded with `gx_lib.loadGold({ fix: true })` (clock corrected; the whole run is repeated on the uncorrected clock and the difference reported). No historical spread is available in this data; costs are a fixed amount (below).
- **Coverage (data check, minutes per calendar year):** 2004 (from 11 June) 79,588; 2005 140,683; 2006 166,248; 2007 241,895; 2008 to 2025 about 316,000 to 356,000 a year; 2026 (to 7 Oct) 266,934. **2004 to 2007 have far fewer minutes than later years** (the broker's early history skips many quiet minutes). Missing minutes are never filled. A day enters the test only if its trading window (below) has **at least 80% of its minutes**; the number of days kept and dropped is reported for every year, and the results of 2004-2007 are shown separately.
- **Bars:** 5-minute and 1-hour bars on the New York clock, stamped at their close, built from the minutes that exist, overnight included; the averages run continuously across days and weekends.
- **Holes (rule 3):** `data_holes_xau.json`; a trade is dropped if a known hole window overlaps the span from 4 hours before its entry to its exit, and every gate and verdict is recomputed without those trades.

## Rules (for a long; a short is the mirror image, and longs and shorts are separate variants)
- **Averages:** EMA(n) of the bar closes with the usual factor 2 / (n + 1), seeded with the simple mean of the first n closes. **1-hour EMA 200**; **5-minute EMA 20 and EMA 50**.
- **Trend (1 hour):** long allowed while the **last closed 1-hour bar closes above its EMA 200** (known at the close of the 5-minute signal bar: the 1-hour bar that closed at or before it).
- **Alignment (5 minutes):** at the close of the signal bar k, **EMA 20 above EMA 50**.
- **Pullback:** the **low** of at least one of bars k-2, k-1, k (the signal bar included) **at or below that bar's own EMA 20**.
- **Confirmation:** bar k is **bullish (close > open) and closes above its EMA 20**.
- **Entry:** at the **open of the first minute after bar k closes** (no fill at the signal close).
- **Stop:** the **lowest low of bars k-2, k-1, k minus $0.30**. **Minimum stop:** if the entry is less than **$2.00** above that stop, **no trade** (the stop is never widened to $2.00). **R** = entry to stop.
- **Target:** **1.5R** or **2R** from the entry (two variants). The stop is checked from the entry minute (a minute opening beyond it exits at its open), the target from the next minute (likewise; the stop first when a minute reaches both).
- **Trading window (one window, real local clocks):** signals and entries from **08:00 London time** to **11:30 New York time**, converted to the New York clock of the data with the real daylight-saving rules of each city (so the window is 03:00 to 11:30 New York in most weeks, and 04:00 to 11:30 New York in the two to three weeks each spring and autumn when the two cities' clock changes differ). A position still open at **11:30 New York** closes at the close of the last minute stamped at or before 11:30.
- **Frequency:** at most **one trade per direction per day**; **one position at a time** per variant; a signal while a position is open is missed (not queued).

## Variants (the only ones tested)
**MTP-L-1.5R, MTP-L-2R, MTP-S-1.5R, MTP-S-2R.** Each reported on its own; none is chosen after the results.

## Costs
- **$0.30 per ounce per round trip** (the cost of every gold test on the site: spread and commission together); also shown at **1.5x ($0.45)** and **2.5x ($0.75)**. With the $2.00 minimum stop the base cost is at most 0.15 R a trade. Results in dollars per ounce and in R.

## Periods, gates, control
- **Periods (by trade date), as in every gold test:** development 2004 to 2012 (with the thin years noted above); validation 2013 to 2019; holdout 2020 to 2026-10-07 (**already used** by many gold tests; reported, not presented as independent confirmation).
- **Six gates per variant** (net dollars per ounce): validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.5**; 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.
- **Matched control (moved entries):** every real trade moved, all together, by one random circular offset of whole usable days (at least 5% of them), entered at the open of the first minute of the new day at or after the same time, same direction, the same stop and target distances, the same 11:30 exit and costs. 500 runs, seeds 1000 + run. Statistic: average net dollars per ounce per trade.
- **Also reported (descriptive, no gates, no verdict):** how often each condition held and how many signals were refused by the minimum stop; the **minimum-stop sensitivity on the same signals** (no minimum, $1, $3, $5), descriptive only; the London-only part of the window (before 08:00 New York) against the overlap with New York; win rate with its Wilson interval; exits by reason; median stop in dollars and the cost in R; by year; by hour of entry; the run on the uncorrected clock.

## Engine and self-test (before the run)
New engine `mtp_lib.js` (the gold loader; the window from the IANA time zones Europe/London and America/New_York), independent re-implementation `mtp_ref.js`, `mtp_selftest.js` that must pass before any result is printed: the EMAs against hand-worked values, the 1-hour trend read from the last closed 1-hour bar only, the alignment, a pullback on the signal bar and two bars earlier, a pullback three bars earlier (not valid), a red candle or a close under the EMA 20 (no signal), the stop at the lowest of the three lows minus $0.30, a stop under $2.00 (no trade), the entry at the next minute's open, stop and target in one minute, a gap through the stop, the 11:30 exit, the window in a normal week and in each kind of daylight-saving mismatch week, one trade per direction per day, a day under 80% coverage (skipped), a short; the reference matched trade by trade on the real data for all four variants; the control at offset 0 entering at the real minutes.

## Documented clarification after freezing (2026-10-28, before any signal or trade was computed)
- **The window's description, not its rule.** The parenthesis above says the window starts at 04:00 New York in the weeks when the clock changes differ. That holds from 2007; before 2007 the United States moved its clocks in April, so in the late-March weeks of 2004-2006 08:00 London was **02:00 New York**. The rule (08:00 London converted with the real rules of each year) is unchanged; found while checking the engine's window dates, with only window times and day counts printed.

## Forward test
Only if the historical result justifies it, under a separate protocol frozen before its first day (as for SQ-L-B and MRE-15-1.5R). Not started by this specification.

## Before the article
Results go to the owner first: all four variants, every gate, by year and window part, the exits, the cost in R, the minimum-stop sensitivity. One article, published only with the owner's agreement, linked to the gold hub and the EMA 9/20 gold post. Working title for search: "Gold 5-Minute Trend Pullback Strategy Backtest: EMA 20/50 With a 200 EMA Filter on 22 Years of XAUUSD".

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. Exploratory: one market, one broker's bid-only data with thin early years, a holdout already used, a fixed cost instead of a historical spread.
