# Accumulation/Distribution (A/D) on SPY, daily bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-22 (approved by the owner the same day, draft 1 unchanged)**. No A/D value, signal or trade on SPY has been 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-22 ("da"), after the Bitcoin 4-hour test (`ad_spec.md`, all buried), whose article lists stocks on the daily chart, where Marc Chaikin designed the indicator, as untested. This test fills that gap; it is a **separate test with its own article**, not a rescue of the Bitcoin result.
- **The same three readings as on Bitcoin**, adapted to a stock index: **long only**, cash (T-bills) when out, as in our SMA 200 test on SPY. Shorting an index that rose about 17-fold with dividends would mostly measure that rise; long-only versions are compared with buy and hold instead.
- **Looked at before (disclosed):** the A/D results on Bitcoin (2026-10-22); on SPY, the 200-day moving average and Faber's 10-month rule (2026-10-21, both buried), so this SPY history has been used once; the S&P 500 from 2020 also through the ES tests.

## Instrument and data
- **SPY**, daily bars **1993-01-29 to 2026-10-20**, the Yahoo Finance history of the SMA 200 test (`data_spy/spy_daily.csv`, `spy_dividends.csv`), with Yahoo's daily **volume** (shares, all US venues). SPY has never split, so prices and volumes need no adjustment.
- **Total return** while invested: close plus dividends reinvested at the ex-date close, as in the SMA 200 test; signals use the traded prices. **Cash:** the 3-month T-bill rate (FRED DTB3) while out, reported with the strategy, not in the per-trade results.

## The indicator (as in `ad_spec.md`)
- Money flow multiplier = ((close - low) - (high - close)) / (high - low), 0 if high = low; money flow volume = multiplier x volume; **A/D** = its running sum from the first day; **Chaikin oscillator** = EMA(3) - EMA(10) of A/D; **A/D average** = SMA(20) of A/D. No signal in the first 60 trading days.

## Rules (signals at the close of day t, executed at the open of day t+1; long only, one position at a time)
- **ADS-DIV (bullish divergence):** a swing low is a day whose low is strictly below the lows of the 5 days before and after it, known at the close of the 5th day after; when a new swing low is lower than the previous one (at most 60 trading days earlier) while A/D at the new low is higher -> **buy**. Stop at the new swing low; target 2R (R = entry - stop); out at the open after 30 trading days in the trade if neither is hit. Daily bars only, so: a day whose low reaches the stop exits at the stop, or at the open if it opens below it; a day whose high reaches the target exits at the target (or the open if it opens above); **if one day reaches both, the stop is assumed first**. No trade if the entry is at or below the stop.
- **ADS-MA:** buy when A/D crosses above its 20-day SMA; sell (to cash) when it crosses below.
- **ADS-CHO:** buy when the Chaikin oscillator crosses above zero; sell when it crosses below.
- Crosses as in `ad_spec.md` (<= then >, >= then <). A position open at the end of the data closes at the last close (marked).

## Costs
- **0.04% of the price per round trip**, as in the SMA 200 test on SPY; a 0.10% scenario is shown; the verdict is that of 0.04%.

## Results, periods, gates, control
- **Unit:** net % per trade (total-return index, entry to exit, minus the cost). Also reported, not gated: the whole strategy with cash interest against buy-and-hold SPY and against the 200-day moving average (CAGR, worst drawdown, time invested).
- **Periods (by entry date), as in the SMA 200 test:** development 1993 .. 2005; validation 2006 .. 2015; holdout 2016 .. 2026-10-20 (**already used** by the SMA 200 test).
- **Six gates per variant:** validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.0** (three readings of an indicator not tested before on stocks); 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.
- **Expected weak point, stated now:** the divergence may give too few trades on daily bars (it found 364 divergences in nine years of 4-hour Bitcoin candles, about six times as many bars a day as here), so ADS-DIV may fail the trade-count gate or be Inconclusive.
- **Matched control (shifted holding periods, as in the SMA 200 test):** every real trade moved, all together, by one random circular offset of at least 5% of the trading days, keeping its length in trading days, entry and exit at the opens; same costs. 500 runs, seeds 1000 + run. Statistic: average net % per trade. It asks whether the A/D picks better times to be long than random times of the same length, so SPY's rise is in the control too.

## Engine and self-test (before the run)
New engine `adspy_lib.js`, independent re-implementation `adspy_ref.js`, `adspy_selftest.js` that must pass before any result is printed: A/D, its average and the oscillator against a hand calculation; crosses, entries and exits at the next open; swing confirmation, a divergence and a too-old previous swing; stop, target, a gap through the stop, both levels on one day and the 30-day exit; dividends inside a trade; costs; the reference matched trade by trade on the real data for all three variants; the control at offset 0 reproducing the real trades.

## Before the article
Results go to the owner first. One article, linked with the Bitcoin A/D post, published only with the owner's agreement. Working title for search: "Accumulation/Distribution Indicator on the S&P 500: 33 Years of SPY".

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. One ETF, one data source, three readings of an indicator with many uses.
