# Head and shoulders on XAUUSD, 15-minute bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-16 (approved by the owner the same day, draft 1 unchanged)**, before any zigzag, pattern, signal or trade of this test was computed on the gold data. Once frozen, any change of a rule is documented and treated as a separate test; bugs may be fixed.

## Why this test, and what was looked at before
- **Chosen by the owner** on 2026-10-16: the head-and-shoulders pattern on gold (XAUUSD), 15-minute bars.
- The pattern is usually drawn by eye, so a test needs a mechanical definition fixed in advance. We use a **published algorithm**: the one of Osler and Chang (Federal Reserve Bank of New York, Staff Report 4, 1995; daily exchange rates, 1973-1994), as described by Boainain and Pereira (Revista Brasileira de Financas 7(3), 2009, which adapts it to stocks), **adapted here to 15-minute bars**. The trade around it is the textbook one: enter only after a close beyond the neckline (Edwards and Magee, as cited by Boainain and Pereira), stop beyond the right shoulder, target the pattern's height projected from the neckline (the "measure rule", as on Bulkowski's pattern site). Other definitions, scales and exits will not be tried after seeing the result.
- **Earlier tests on this gold file:** 78 protocolled variants in 9 tests (the opening-range breakout, daily and 1-hour golden crosses, EMA 9/20 on 15-minute and 1-hour bars, the Turtle rules, the noise area breakout, RSI 30/70, the TTM Squeeze, WaveTrend); none passed every gate. **No head-and-shoulders pattern has been computed on this file**, on the site or in our earlier private research (a pattern-breakout indicator tested privately in September 2026 found flags, pennants, wedges and triangles, not this pattern).
- Gold rose about elevenfold over the file, which favours long rules; long-only variants are included for that reason, and the control trades the same direction at other times, so the market's rise is in the control too.

## Instrument and data
- **XAUUSD** on the IC Markets MetaTrader 4 demo server, a spot gold CFD in US dollars per ounce; 1-minute bid history from the first bar of 2004 to **2026-10-07 16:57 New York**, the part of the file read by the published gold studies (`gx_lib.loadGold({ fix: false })`).
- **Bars:** 15-minute bars on the New York clock, closing at :00, :15, :30 and :45, containing the 1-minute bars with close times in (t - 15 min, t], built from the minutes that exist (`gh_lib.barsOf`, as in the EMA 9/20 test); incomplete bars are kept as they are, empty ones do not exist. Positions are held over the daily break, weekends and holidays.
- **Clock:** the file's time labels are an hour early in many weeks of 2004-2010 (clock audit). The bars are cut on quarter hours, so a shifted label moves whole bars in time without changing their contents or order; nothing in the rules depends on the time of day. Stated in the article; no second run.
- **Holes (rule 3):** `data_holes_xau.json`; trades open across a suspect or unclear gap are counted, and every gate and verdict is recomputed without them; a changed verdict becomes Inconclusive.

## The pattern (Osler and Chang's rules, on 15-minute closes)
- **Volatility:** s(t) = the standard deviation of the log changes between consecutive 15-minute closes over the 2,000 bars before bar t (about a month), recomputed at every bar. Patterns are counted only after a warm-up of 2,000 bars.
- **Zigzag** (Osler and Chang use a zigzag of closing prices whose cut-off is a multiple of the volatility): a **peak** is confirmed at the first bar whose close is at least k x s(t) below (in log terms) the highest close since the last trough; a **trough** at the first bar whose close is at least k x s(t) above the lowest close since the last peak. The pivot's time and price are those of that highest (lowest) close, the first one if several are equal; the pivot is known only from the bar that confirms it (no look-ahead). The zigzag starts after the warm-up tracking both the highest and the lowest close; the first move of k x s(t) decides the first pivot.
- **Two scales, k = 3 and k = 6** (Osler and Chang scan cut-offs from 1.5 to 6 times the volatility; 3 and 6 are the middle and the top of that range). With bars of 15 minutes, k = 3 finds patterns lasting roughly half a day to a day, and k = 6 patterns of several days.
- **Head and shoulders top**, checked each time a peak is confirmed: the last seven pivots are peak P0, trough T0, left shoulder LS (peak), trough T1, head H (peak), trough T2, right shoulder RS (peak; the one just confirmed). The pattern is valid if:
  1. **a rise before it:** LS > P0 and T1 > T0;
  2. **the head is the highest:** H > LS and H > RS;
  3. **time symmetry:** the bars from LS to H are fewer than 2.5 times the bars from H to RS, and the bars from H to RS fewer than 2.5 times the bars from LS to H;
  4. **height symmetry (Osler and Chang's version):** RS > (LS + T1) / 2 and T2 < (LS + T1) / 2; LS > (RS + T2) / 2 and T1 < (RS + T2) / 2.
- **Neckline:** the straight line through T1 and T2 (the two troughs), extended to the right.
- **Break:** the first 15-minute close **below the neckline** (its value at that bar), at or after the bar that confirms RS, provided that (a) the next zigzag pivot after RS (a trough) has not been confirmed before it, and (b) it comes **within as many bars after RS as there are from LS to RS** (Osler and Chang's time limit). Otherwise the pattern is dropped.
- **Inverse head and shoulders** (a bottom): the mirror image, checked each time a trough is confirmed (troughs and peaks swapped, every inequality reversed, the break a close above the neckline through the two peaks).
- **Height h:** the vertical distance from the head to the neckline at the head's time, in dollars per ounce.

## The trade
- **Entry:** at the open of the first 1-minute bar after the break bar: a sell after a top, a buy after an inverse pattern. One position at a time: a break that comes while a trade is open is not taken. The long-only variants ignore tops.
- **Target (the measure rule):** the height h projected from the neckline at the break bar: break level - h for a sell, break level + h for a buy.
- **Stop (beyond the right shoulder):** for a sell, the highest high of the 15-minute bars from the bar after T2 to the break bar; for a buy, the lowest low over the same bars.
- **Exits** checked inside each 1-minute bar from the entry minute on: if the stop and the target are both touched in the same minute, the stop is taken; a level gapped through fills at that minute's open. No time limit. A position open on the last bar is closed at its close and flagged.
- **R** (the unit of the results) = h, the pattern's height: a trade that reaches the target makes +1 R before costs. The distance to the stop is reported in R too.
- **Four variants:** **HS-LS-3, HS-L-3, HS-LS-6, HS-L-6** (tops and inverse patterns / inverse patterns only, long x zigzag scale k = 3 / k = 6).

## Costs
- **Baseline:** $0.30 per ounce per round trip, as in every gold test on the site; slippage zero, which is optimistic and stated.
- **Scenario A:** 3% a year of the entry price per calendar day held, longs and shorts alike. **Scenario B:** the IC Markets XAUUSD swap as recorded on 2026-10-12 (long -57.03, short +39.767 points per lot per night; Wednesday counting three), not a historical swap. The verdict is that of the baseline.

## Periods, gates, control
- **Periods (by entry date):** development 2004 .. 2012; validation 2013 .. 2019; holdout 2020 .. 2026-10-07 (**already used** by the earlier gold tests).
- **Six gates per variant:** validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.0** (four variants of a strategy not tested before on the site); 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 entry moved, all together, by one random circular offset of at least 5% of the days, to the same time of day on the new day, same direction; the stop and the target placed at the same distances from the new fill as in the real trade, **measured in units of the volatility** (s x price at the entry bar), so that a pattern of 2004 moved to 2024 keeps its size relative to the market; R scaled the same way; same costs and one-position rule. 500 runs, seeds 1000 + run. Statistic: the average net R per trade. It asks whether the pattern's breaks pick better moments than the same trades placed at other times.

## Engine and self-test (before the run)
A new engine (`hs_lib.js`) and a self-test that must pass before any result is printed:
1. Hand-worked cases on made-up closes: the volatility, the zigzag (confirmation, equal closes, the cut-off changing with s), each pattern rule accepting and rejecting, the neckline and its slope, the break at the confirming bar and later, the time limit, a pattern dropped when the next pivot comes first, the inverse pattern; the entry at the next minute; target and stop, both in one minute (stop taken), in the entry minute, gapped through; one position at a time; long only ignoring tops; R, costs and the two financing scenarios.
2. The 15-minute bars checked against a naive aggregation of the minutes.
3. An **independent re-implementation** of the zigzag, the patterns and the trades, matched trade by trade for all four variants on the real data.
4. The control at offset 0 reproduces the real trades.

## Before the article
Results go to the owner first: all four variants and every gate; tops and inverse patterns separately; by year; the number of patterns found per year and per scale; the share of trades reaching the target and the stop (Bulkowski reports 51% of tops meeting the target on stocks); the share that came back to the neckline before the exit (his "pullback rate", 68%); the average height in dollars and the cost per trade against the gross; time in trade; both financing scenarios; the hole check. One article, published only with the owner's agreement.

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. One market, one timeframe, one broker's demo history, one published definition of the pattern at two scales; traders who pick patterns by eye may select differently.
