# Classic RSI 14 (30/70) on XAUUSD, 5-minute and 1-hour bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-14 (approved by the owner the same day; draft 2, which added the protected versions before any number)**, before any RSI value, signal or trade of this test was computed. Written before any RSI value, signal or trade of this test was computed. 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-14 after a search-demand check: "RSI strategy" is the most searched indicator strategy of the ones we compared on Google Trends, and Google's suggestions name gold and forex as the markets and the 5-minute chart first among timeframes ("best rsi settings for 5 minutes chart"); the owner proposed 1 hour. Market and timeframes chosen the same day: **gold (XAUUSD), 5-minute and 1-hour bars**.
- **Two families, chosen by the owner before any number:** the textbook rule (no stop, both directions at any time), and a **protected** version that answers the two risks we named in advance (a counter-trend rule on a market where trend rules did best, and no stop): a 200-bar EMA trend filter and a stop at 1R. The protected version was added because of those risks, not because of any result; if only it passed, it would be a candidate, not a proof.
- The site has tested other RSI rules before: RSI(2) dip buying on ES and on four currency pairs, and RSI divergence on ES. **The classic 14-period RSI with the 30 and 70 levels has not been tested**; no RSI(14) number on gold was looked at.
- Earlier tests on this gold file: daily and 1-hour golden crosses, EMA 9/20 (15-minute and 1-hour), the opening-range breakout, the Turtle rules and the noise area breakout. Trend-following rules did best on gold so far; RSI 30/70 is a counter-trend rule.

## 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:** 5-minute and 1-hour bars on the New York clock, close time = bar time, built from the minutes that exist (`gh_lib.barsOf`); 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 here are continuous and cut on whole 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.

## Rules (the classic reading of "buy at 30, sell at 70")
- **RSI(14)** of the bar closes, Wilder's method: the first average gain and loss are the simple averages of the first 14 changes, then avg = (13 x previous + current) / 14; RSI = 100 - 100 / (1 + avg gain / avg loss) (100 when there is no loss).
- **Long entry** at the close of bar k: RSI[k-1] <= 30 and RSI[k] > 30 (RSI turns back up through 30). **Short entry** (long-and-short variants): RSI[k-1] >= 70 and RSI[k] < 70.
- **Exit:** a long is closed at the close of the first bar with RSI >= 70; a short at the first bar with RSI <= 30. **Classic versions: no stop, no target**, as in the textbook rule; the article reports the worst open loss of every trade.
- **Protected versions (F):** the same entries and exits, plus (1) a **trend filter**: a long entry only if the signal bar closes above its EMA(200), a short entry only if it closes below (EMA of the closes of that timeframe, seeded with the simple average of the first 200); (2) a **stop at 1R** from the entry fill (below for longs, above for shorts), checked on every 1-minute bar from the entry minute on; a stop gapped through fills at that minute's open. After a stop the position stays flat until the next entry signal.
- **Execution:** entries and exits at the open of the first 1-minute bar after the signal bar. One position at a time; a signal while a position is open is ignored.
- **R** (the unit of the results): 1.5 x ATR(14) of the bars of that timeframe at the entry signal bar (`E.indicators`, as in the gold EMA test), in dollars per ounce. In the classic versions R is a normalisation unit, not a maximum loss; in the protected versions it is the stop distance.
- **Eight variants:** classic **RS-M5-LS, RS-M5-L, RS-H1-LS, RS-H1-L** and protected **RS-M5-LS-F, RS-M5-L-F, RS-H1-LS-F, RS-H1-L-F** (timeframe x long and short / long only x classic / protected).

## 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:** today's IC Markets XAUUSD swap as recorded by the forward-test EA on 2026-10-12 06:39 server time (swap type in points: **long -57.03, short +39.767** per lot per night, i.e. -$0.5703 and +$0.39767 per ounce; Wednesday counting three nights, as in the earlier gold tests): 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.5** (RSI rules have been tried in more than four variants 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; from there the position is managed by the same RSI exit, costs and one-position rule. 500 runs, seeds 1000 + run. Statistic: the average net R per trade. It asks whether RSI 30/70 picks better entry moments than the same trades on other days.

## Engine and self-test (before the run)
A new engine (`rs_lib.js`) and a self-test that must pass before any result is printed:
1. Hand-worked cases: RSI with its seed and the no-loss case; the 30 and 70 crossings; entry and exit at the next minute; one position at a time; long only ignoring short signals; the EMA200 filter; the 1R stop, also in the entry minute and gapped through; costs and the result in R; the financing scenarios.
2. RSI against a naive recomputation on the real data.
3. An **independent re-implementation** matched trade by trade for all eight 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 eight variants, every gate, long and short separately, by year, the worst open loss per trade, how long trades last, the cost per trade against the gross, both scenarios, the hole check. One article (gold, both timeframes), 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 broker's demo history, the classic parameters only.
