# Supertrend on gold (XAUUSD), 1-hour bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-11-06 (approved by the owner the same day: "Da, îngheață și rulează"; draft 1 unchanged)**, before any Supertrend value, signal or trade was computed on gold. 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-11-06 ("Supertrend pe aur"), from three gold proposals of that day (Supertrend, London breakout, NFP day), after Web Analytics showed readers arriving on the gold pages from India, the United States and North Africa.
- **The claim:** Supertrend (credited to Olivier Seban; sources differ on its origin) draws a line from ATR below the price in an uptrend and above it in a downtrend; the usual rule is to be long while it is green and short while it is red. It is one of the most used indicators on TradingView, where its built-in strategy uses **ATR period 10, multiplier 3**. We test those defaults and do not tune anything.
- **Looked at before on the site (disclosed):** Supertrend on **ES** (ST60-LS, ST60-L, ST15-LS, ST5-LS and four stop versions: all buried) and its 60-minute versions on **four FX pairs** in the FX study (all buried); the Parabolic SAR on EUR/USD, a close relative (buried). On this gold file: 17 strategies in about 110 versions (the gold hub), among them the daily and 1-hour golden crosses, EMA 9/20 and 9/21, the Turtle rules and the TTM Squeeze. **No Supertrend value has been computed on gold.** Gold rose about elevenfold over the file, which favours long rules; a long-only variant is included for that reason, and the control keeps the same mix of long and short time, so the rise is in the control too.

## Instrument and data
- **XAUUSD** spot, IC Markets MT4 demo, 1-minute bid bars from 2004 to **2026-10-07 16:57 New York** (`gx_lib.loadGold({ fix: false })`), the part of the file read by the published gold studies. The later data is kept for forward tests.
- **Bars:** 1-hour bars on the New York clock, close time = bar time, built from the minutes that exist (`gh_lib.barsOf`), as in the RSI, EMA, TTM Squeeze and WaveTrend tests.
- **Clock:** the file's labels are an hour early in many weeks of 2004-2010 (clock audit). Nothing in the rules depends on the time of day, so a shifted label moves whole bars without changing their contents or order; 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 indicator (the published ES engine's definition, `st_protocol.js`)
- ATR = Wilder (RMA) average of the true range, period 10, on the 1-hour bars; hl2 = (high + low) / 2; basic bands hl2 +/- 3 x ATR.
- Final upper band = basic upper if basic upper < previous final upper or the previous close > previous final upper, else the previous final upper; the final lower band is the mirror.
- Direction: after an upper-band bar, UP if the close > final upper, else DOWN; after a lower-band bar, DOWN if the close < final lower, else UP.
- Signals only from the **500th bar** (the averages no longer depend on their start).

## Rules
- **Target position** at each 1-hour bar close: UP = long, DOWN = short (long-and-short) or flat (long only). A change fills at the **open of the first 1-minute bar after that 1-hour bar**; a reversal closes and opens at the same fill.
- **No stop and no target** beyond the Supertrend itself, as the indicator is used. The worst open loss of every trade is reported.
- **Held over the daily break and weekends**, as in every gold test on the site. This differs from the ES and FX 60-minute versions, which went flat before the weekend: on this file a Friday-hour rule would depend on clock labels that are an hour off in 2004-2010. The share of the result made across weekend gaps is reported.
- A position open at the end of the data closes at the last minute's close.
- **R** (the unit of the results): 1.5 x ATR(14) of the 1-hour bars at the signal bar (`E.indicators`), in dollars per ounce, as in the other gold tests; a normalisation unit, not a maximum loss. Results are also shown in dollars per ounce.
- **Two variants:** **ST-LS** (long and short, always in the market after the first signal) and **ST-L** (long while green, flat while red).

## Costs
- **Baseline:** $0.30 per ounce per round trip, as in every gold test; a reversal closes one trade and opens the next, each paying its own round trip. Slippage zero (optimistic, 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 recorded on 2026-10-12 (long -57.03, short +39.767 points per lot per night, Wednesday counting three), today's rate, not a historical one. 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.5** (Supertrend has more than four versions on the site, and many strategies have been tried on this file); 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 (shifted direction, as in the FX study's Supertrend):** the real Supertrend direction series (UP or DOWN at each 1-hour bar close) shifted circularly, as a whole, by one random offset of at least 5% of the bars, then traded by the same rules (long only or long and short, fills, costs, R at each control signal bar). It keeps the number of changes, their lengths and the long/short mix and breaks only the timing. 500 runs, seeds 1000 + run. Statistic: average net R per trade.

## Also reported (descriptive, after the gates; nothing here can change the rule or the verdict)
Long and short separately; by year and by period; holding times and time in the market; win rate with its Wilson interval; the cost per trade against the gross; both cost scenarios; without the 10 and the 20 best trades; the worst open loss per trade; the weekend-gap share; the hole check; the gold result next to the published ES and FX Supertrend results.

## Engine and self-test (before the run)
New engine `stau_lib.js`, an independent re-implementation `stau_ref.js`, and `stau_selftest.js`, which must pass before any result is printed:
1. Hand-worked bars: ATR (Wilder), the basic and final bands, both direction rules, a flip each way; the fill at the next minute's open; a reversal; long only going flat; the end of the data; costs, R and both scenarios.
2. The direction series equal to the published `st_protocol.js` Supertrend on the same gold bars.
3. The independent re-implementation matched trade by trade for both variants on the real data.
4. The control at offset 0 reproducing the real trades.
5. A mutation check: deliberate changes to the rules (multiplier, fill bar, band rule) must make the test fail.
`stau_run.js` refuses to run unless the self-test passed on the current code and this file is frozen.

## Before the article
Results go to the owner first (in Romanian), with every gate. One article, only with the owner's agreement, linked to the Supertrend ES post and the gold hub (with correction notes there). Working title for search: "Supertrend Strategy on Gold: XAUUSD 1-Hour Backtest (ATR 10, 3)".

## 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 with thin early years, the default settings only, a holdout already used.

## Log
- 2026-11-06: draft 1 written. Nothing computed.
- 2026-11-06: frozen (draft 1 unchanged), approved by the owner ("Da, îngheață și rulează"). SHA-256 of the frozen text (before this log grew): 4102c5531319f7f1dbce7a48761f61c50d8120ea72a50dbf7f62f2bd431510c3.
- 2026-11-06, before any result: stau_selftest.js passed on the first run (hand-worked bands, directions and trades; the direction series equal to st_protocol.js on all 129,857 one-hour bars; engine = independent reference trade by trade; control at offset 0 = real trades; all four mutations detected). Counts only: ST-LS 3,164 trades, ST-L 1,582.
- 2026-11-06, the run (`node stau_run.js`, once, outputs in `stau_out/`): **ST-LS Buried 4/6** (fails validation PF 1.05 and development t 1.92; passes the trade counts, the control at the 99.8th percentile, without the 10 best +164 R, holdout +151 R; longs +547 R, shorts -135 R). **ST-L Buried 5/6** (fails only validation PF 1.02; development t 3.78, control 99.6th percentile, without the 10 best +347 R, holdout +231 R PF 1.51; today's swap, scenario B, leaves +7 R of +547 R). Rule 3: without the trades open across suspect gaps both stay Buried (2/6). Descriptive check after the gates (`stau_holes_check.js`): those trades are the longer ones (79-83 h against 54-58 h), mostly 2004-2010 when the file is thin; the price moves across the hole windows inside them add only -11 R (ST-LS) and +53 R (ST-L), so the profit is not a data jump. Nothing was rerun or changed.
- 2026-11-06: the owner asked for the article ("Da, scrie-l"). Published from the outputs of the single run, unchanged.
