# ADX + DI trend strategy on the four forex majors, 1-hour bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-21 (approved by the owner the same day, draft 1 unchanged)**. No ADX value, signal or trade of this test has been computed. Looked at before writing: the first and last bar and the bar count of the four FX files. 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
- **Proposed to the owner on 2026-10-21** (rules drafted by the owner with another assistant, gaps closed by us; the owner chose "planul tau"). The question: does the ADX with the direction of the DI lines add useful information to a trend trade, against a fair control and after costs, or does it only show that the market is already moving?
- **ADX and DI** are J. Welles Wilder's (New Concepts in Technical Trading Systems, 1978). A threshold of 20 or 25 for "a trend" is common; we test **20 as the main version and 25 declared now as the second**, and no other threshold after the result.
- **Looked at before on the site:** the same four pairs on the same 1-hour bars in the FX study (Supertrend, MACD, Donchian and three others, all buried), and several single-pair tests since. ADX was used once as a filter in unpublished, unprotocolled Coppock tests on ES (disclosed in cc_spec.md); never as a strategy on FX.

## Instruments and data
- **EURUSD, GBPUSD, USDJPY, AUDUSD**, IC Markets MT4 demo, 1-minute bid history **2004-01-01 to 2026-09-28** (`fx_data.loadFx`), New York wall clock, close stamps.
- **1-hour bars** built from the minutes (`gh_lib.barsOf(M, 60)`: close stamp = the next whole hour, New York clock), as in the FX study; incomplete bars kept, empty hours do not exist.
- **Clock check:** the week-open hour in the clock-change windows for USDJPY and AUDUSD, as already done for EURUSD and GBPUSD (no week shifted there). **Holes (rule 3):** the gap audits `data_holes_eurusd.json` and `data_holes_gbpusd.json`, and the same audit for USDJPY and AUDUSD.

## The indicator (Wilder, period 14)
- TR = max(high - low, |high - previous close|, |low - previous close|); up = high - previous high, down = previous low - low; +DM = up if up > down and up > 0, else 0; -DM = down if down > up and down > 0, else 0.
- Wilder smoothing: the first value is the sum of the first 14; then S = S - S / 14 + x. +DI = 100 x smoothed +DM / smoothed TR; -DI the same with -DM.
- DX = 100 x |+DI - (-DI)| / (+DI + (-DI)) (0 if the sum is 0); ADX = the mean of the first 14 DX, then ADX = (previous ADX x 13 + DX) / 14.
- Signals only from the **500th bar** of each pair (the smoothing has no memory of its start after that).

## Rules (threshold X = 20 or 25)
- **Entry** at the close of bar k when ADX crosses above X (ADX[k-1] <= X and ADX[k] > X) and no position is open: **long if +DI > -DI, short if -DI > +DI** (equal: no trade). Fill at the open of the first minute after bar k.
- **Exit:** a long when -DI crosses above +DI at a bar close (-DI[k-1] <= +DI[k-1] and -DI[k] > +DI[k]); a short when +DI crosses above -DI; fill at the open of the first minute after that bar. **No stop, no target.**
- **Re-entry only on a new ADX cross:** after an exit, the next trade needs ADX to cross above X again (from at or below it). If the exit bar is itself an entry bar (ADX crosses above X at that close), the new position opens at the same fill.
- One position per pair and variant; a position open at the end of the data closes at the last close.
- **Eight pair-variants:** ADX-20 and ADX-25 on each of the four pairs.

## Costs and financing
- **1.0 pip per round trip (1.2 on USDJPY)**, as in the FX study (IC Markets Raw: $7 commission plus 0.3 pip of spread); trades here start at hourly closes, not at the London open, so the FX study's cost is kept. Results at 1.5 and 2.5 times the cost are shown; the verdict is that of the base cost.
- **Swap:** not in the base result (it changed sign over these years); a stress scenario charges **0.5 pip per night** held (Wednesday counting three).

## Results, periods, gates, control
- **Unit:** pips per trade (net), as in the FX study. Also reported: trades, holding time, long and short, by year, the share of time in the market.
- **Periods (by entry date):** development 2004 .. 2012; validation 2013 .. 2019; holdout 2020 .. 2026-09-28 (**already used** by the FX study).
- **Six gates per pair-variant:** validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.5** (the stricter FX bar of the FX study: many variants have been tried on these pairs); above the 95th percentile of 500 runs of the matched control; positive without the 10 best trades; holdout net positive (flagged used).
- **Cross-market rule (as in the FX study):** a variant counts as supported only if it passes every gate on **at least 3 of the 4 pairs**; one or two pairs is a single-pair result, not support.
- **Matched control (shifted holdings):** every real trade of a pair-variant moved, all together, by one random circular offset of whole hourly bars (at least 5% of them), keeping its direction and its length in bars; entry and exit at the open of the first minute after the moved bars; same costs. 500 runs, seeds 1000 + run. Statistic: average net pips per trade. It asks whether ADX picks better times to be in the market, in that direction, than the same holdings at random times.

## Engine and self-test (before the run)
New engine `adx_lib.js`, independent re-implementation `adx_ref.js`, `adx_selftest.js` that must pass before any result is printed: TR, DM, the Wilder sums, DI, DX and ADX against a hand calculation; crosses at exactly X; the direction rule and equal DIs; the exit crosses; the re-entry rule and the same-bar flip; costs and the swap scenario; the reference matched trade by trade on the real data for all eight pair-variants; the control at offset 0 reproducing the real trades.

## Before the article
Results go to the owner first: all eight pair-variants, every gate, the cross-market rule, long and short, by year. One article, published only with the owner's agreement. Working title for search: "ADX Indicator Strategy Backtest: Does It Work on Forex Majors?"

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. Four pairs, one broker's demo history, Wilder's default period, two thresholds.
