# CCI (Commodity Channel Index) on gold, 1-hour bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-11-08 (approved by the owner the same day, "Da, îngheață și rulează"; draft 1 unchanged)**, before any CCI value, signal or trade 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-11-08 ("CCI pe aur"), as the first of a series of classic indicators that traders search for (CCI, Williams %R, Parabolic SAR, Ichimoku).
- **The indicator:** Donald Lambert's Commodity Channel Index (1980), made for commodities. It measures how far the typical price is from its average, in units of its average deviation. Readings above +100 and below -100 are the classic signal levels, and the zero line is the mean.
- **The rules as commonly taught,** three of them tested here:
  - Lambert's own: buy when the CCI rises above +100, out when it falls back below +100, with the mirror for shorts at -100;
  - the reversal: buy when the CCI comes back above -100 from below, sell when it comes back below +100;
  - the zero-line cross.
- **Earlier work on this file:** many strategies have been tested on this gold file (the gold hub lists 18), among them Supertrend, RSI 30/70, EMA crossovers, TTM Squeeze and WaveTrend on 1-hour bars. No CCI has been computed on any market on this site.

## 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.
- **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 Supertrend, RSI, EMA, TTM Squeeze and WaveTrend tests.
- **Clock:** the file's labels are an hour early in many weeks of 2004-2010 (clock audit). No rule depends on the time of day, so a shifted label moves whole bars without changing their contents or order.
- **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
- Typical price TP = (high + low + close) / 3 of each 1-hour bar.
- **CCI(20)** = (TP - SMA20(TP)) / (0.015 x MD), where MD is the mean absolute deviation of the same 20 TP values from their SMA. If MD = 0 the CCI is 0. 20 is Lambert's period and the default of most charting platforms (MetaTrader's default is 14).
- Signals only from the **500th bar**, as in the other gold 1-hour tests (the R unit uses a Wilder ATR).

## Rules
- At each 1-hour bar close, the rule sets a **target position** (long, short or flat). A change fills at the **open of the first 1-minute bar after that bar**; a reversal closes and opens at the same fill.
- **Four variants:**
  1. **CCI-BRK-LS** (Lambert): long from the close where the CCI crosses above +100 (previous <= +100, now > +100) until the close where it is back at or below +100. Short from the close where it crosses below -100 until it is back at or above -100. Flat otherwise.
  2. **CCI-BRK-L:** the long side of CCI-BRK-LS only.
  3. **CCI-REV-LS** (the reversal):
     - long from the close where the CCI comes back above -100 (previous <= -100, now > -100), until the first close with the CCI at or above 0 (back to the mean) or at or below -100 (the reversal failed);
     - short from the close where it comes back below +100 (previous >= +100, now < +100), until the first close at or below 0 or at or above +100;
     - flat otherwise. An exit and a new signal on the same close: the new signal is taken.
  4. **CCI-ZERO-LS** (the zero-line cross): long while the CCI is above 0, short while it is below 0; a CCI of exactly 0 keeps the previous position. Always in the market after the first signal.
- **No stop and no target** beyond the indicator, as the rules are taught. The worst open loss of every trade is reported.
- **Held over the daily break and weekends**, as in every gold test on the site. 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.

## 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 to 2012; validation 2013 to 2019; holdout 2020 to 2026-10-07, **already used** by the earlier gold tests.
- **Six gates per variant:**
  1. validation profit factor >= 1.2;
  2. at least 50 trades in each period;
  3. development **t >= 2.5** (many strategies have been tried on this file);
  4. above the 95th percentile of 500 runs of the matched control;
  5. positive without the 10 best trades;
  6. holdout net positive (flagged as used).

  A variant with fewer than 30 trades is Inconclusive.
- **Matched control (shifted position series, as in the Supertrend gold test):**
  - The variant's real target-position series (long, short or flat at each 1-hour bar close) is shifted circularly, as a whole, by one random offset of at least 5% of the bars.
  - It is then traded with the same fills, costs and R at each control signal bar.
  - It keeps the number of trades, their lengths and the long/short/flat mix, and breaks only the timing.
  - 500 runs, seeds 1000 + run. Statistic: the 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 swap scenarios; without the 10 and the 20 best trades; the worst open loss per trade; the share of the result made across weekend gaps.

## Engine and self-test (before the run)
- The engine reuses the published gold 1-hour code (bars, R, fills, costs, swap scenarios, control).
- An **independent re-implementation** is written by a separate AI agent from this specification, the data loader and stated implementation facts, without the engine's code. The agent reports trade counts only.
- The self-test checks:
  1. the CCI against a hand calculation;
  2. hand-built bars: each variant's entries and exits, a reversal, long-only going flat, the end of the data, costs, R and both scenarios;
  3. engine against reference, trade by trade, for the four variants on the real data;
  4. the control at offset 0 against the real trades.

## Before the article
Results go to the owner first. One article, published only with the owner's agreement, after the queued posts (from 12 Nov 2026).

## 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, Lambert's settings only, a holdout already used.

### Run log
- 2026-11-08: frozen. sha256 of this file above the "### Run log" heading: c44bec39040f614bd0de19de2c0a2dd4e87924b8b5cc99348fd1ab02d254b2f3.
- 2026-11-08, before the run: the reference (cci_ref.js) was written by a separate agent from this specification, gx_lib.js/fx_data.js and stated implementation facts (bars, the 1e-9 rounding of the CCI, the start at bar index 500, exits checked before entries on a close), and it reported trade counts only. It matched the engine on CCI-BRK-LS, CCI-BRK-L and CCI-ZERO-LS (11,900, 6,111, 12,417 trades) and found an ambiguity in CCI-REV-LS: an opposite signal while the held position's own exit has not fired (5 cases). Reading fixed before any result, as the engine already had it and as the text says ('long ... until the first close with ...'): a held position is kept until its own exit; entries are taken only when flat after the exit check of that close. The reference was changed by its agent to this reading. Also stated: an entry on a close whose CCI is already past the exit level (806 REV entries) is taken, and its exit is tested from the next close (both implementations).
- 2026-11-12: published as /posts/cci-indicator-strategy-gold/ (the owner asked for the article on 2026-11-08: "Da, scrie-l").
- 2026-11-12: added to the gold hub (best-gold-trading-strategy): 4 versions; the hub now counts 115 versions of 19 strategies.
