# WaveTrend oscillator on XAUUSD, 1-hour 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 WaveTrend 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-16: the WaveTrend oscillator on gold (XAUUSD), 1-hour bars.
- WaveTrend is the oscillator LazyBear published on TradingView as "WaveTrend Oscillator [WT]" (a port, he wrote, of an older MetaTrader / TradeStation indicator); it is also the core of the paid Market Cipher B and of free copies of it. We test **LazyBear's formula and default settings**. His script draws the lines, the crosses and the overbought and oversold levels but gives no trading rule; the rule below is the usual reading of it ("buy a cross up in the oversold zone, sell a cross down in the overbought zone"), written down by us. Other settings will not be tried after seeing the result.
- Earlier tests on this gold file: daily and 1-hour golden crosses, EMA 9/20, the opening-range breakout, the Turtle rules, the noise area breakout, RSI 30/70 (an overbought/oversold rule: buried) and the TTM Squeeze. **No WaveTrend value has been computed on the site.** 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:** 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 and TTM Squeeze tests; 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 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.

## The indicator (LazyBear's defaults: channel length 10, average length 21, signal 4; levels +60, +53, -53, -60)
- **AP** = (high + low + close) / 3 of each 1-hour bar.
- **ESA** = EMA(AP, 10); **D** = EMA(|AP - ESA|, 10); **CI** = (AP - ESA) / (0.015 x D) (CI = 0 if D = 0).
- **WT1** = EMA(CI, 21); **WT2** = SMA(WT1, 4).
- EMAs use alpha = 2 / (n + 1), seeded with the first value, as on TradingView; signals are counted only after a warm-up of 500 bars, so the seed has no effect.
- **Cross up** at bar k: WT1[k-1] <= WT2[k-1] and WT1[k] > WT2[k]. **Cross down:** WT1[k-1] >= WT2[k-1] and WT1[k] < WT2[k].
- **Buy signal:** a cross up with **WT2[k] <= -53** (the cross happens in the oversold zone). **Sell signal:** a cross down with **WT2[k] >= +53** (in the overbought zone).

## Rules
- **Entry:** at the open of the first 1-minute bar after the 1-hour bar k with a buy signal (long) or a sell signal (short; long-only variants ignore sell signals as entries). One position at a time.
- **Exit X (the next cross):** a long is closed at the first **cross down** after the entry, at any level; a short at the first cross up. If that cross is also an opposite signal, the long-and-short variant opens the opposite position at the same fill (a flip).
- **Exit R (the next opposite signal):** a long is closed only at the next **sell signal** (a cross down in the overbought zone); a short at the next buy signal. The long-and-short variant reverses there (it is always in the market after its first signal); the long-only variant goes flat and waits for the next buy signal.
- Exits at the open of the first 1-minute bar after the signal bar. **No stop, no target**, as the indicator is usually used; the article reports the worst open loss of every trade.
- **R** (the unit of the results): 1.5 x ATR(14) of the 1-hour bars at the signal bar (`E.indicators`, as in the other gold tests), in dollars per ounce; a normalisation unit, not a maximum loss.
- **Four variants:** **WT-LS-X, WT-L-X, WT-LS-R, WT-L-R** (long and short / long only x exit X / exit R).

## Costs
- **Baseline:** $0.30 per ounce per round trip, as in every gold test on the site; a flip pays two; 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; from there managed by the same exit rule (X or R), costs and one-position rule. 500 runs, seeds 1000 + run. Statistic: the average net R per trade. It asks whether the WaveTrend signals pick better moments than the same trades placed on other days.

## Engine and self-test (before the run)
A new engine (`wt_lib.js`) and a self-test that must pass before any result is printed:
1. Hand-worked cases: ESA, D, CI, WT1 and WT2 against a hand calculation; crosses up and down, including equal values; buy and sell signals only inside the zones; entries at the next minute; exit X at the first opposite cross and the flip; exit R at the next opposite signal and the reversal; long only ignoring sell entries; one position at a time; costs, R and the financing scenarios.
2. The indicator against a naive recomputation on the real data.
3. An **independent re-implementation** 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, 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, 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, the default settings only.
