# Heikin Ashi strategy on Bitcoin (BTCUSDT), 4-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 Heikin Ashi candle, signal or trade of this test 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-21 (option 1 of three proposed: Heikin Ashi, Parabolic SAR, ICT Silver Bullet), as one of the most searched indicator strategies not yet tested on the site.
- **The idea:** Heikin Ashi ("average bar" in Japanese) candles smooth price so that trends show as runs of one colour. The common tutorial rule: buy when the candles turn green, especially a strong green candle **with no lower wick**; get out at the first red candle; the mirror for shorts. Many versions add a 200-period moving average so that you only trade with the trend. We fix three common readings and try no others after the result.
- **Looked at before on Bitcoin (disclosed):** our published Turtle trading (daily), intraday trend pullback (15-minute), noise area breakout and CME gap fill tests, all buried. Heikin Ashi has not been tested on the site on any market.

## Data
- **Bitcoin:** the Binance BTCUSDT 1-minute file of the earlier Bitcoin tests (`BTCUSDT_1min.csv`, 2017-08-17 to 2026-09-30 23:59 UTC), spot prices, UTC clock; the known gaps of `btc_gaps.json`.
- **4-hour bars:** 00:00-04:00, 04:00-08:00 ... 20:00-24:00 UTC, every calendar day (Bitcoin trades all week), built from the minutes (open = first minute's open, high/low = extremes, close = last minute's close). A 4-hour bar with fewer than 120 minutes is **not used** (no signal is taken on it); the Heikin Ashi chain simply continues over it from the last used bar.

## Heikin Ashi candles (standard formulas)
- HA close = (open + high + low + close) / 4 of the real bar.
- HA open = (previous HA open + previous HA close) / 2; the first bar's HA open = (open + close) / 2.
- HA high = max(real high, HA open, HA close); HA low = min(real low, HA open, HA close).
- **Green** if HA close > HA open, **red** if HA close < HA open (equal: neither, no colour change). **No lower wick:** HA low = HA open on a green candle; **no upper wick:** HA high = HA open on a red candle (exact equality, with a tolerance of 1e-9 of the price for floating point).
- The first 30 days of data only warm up the chain and the 200-bar average (no trades before 2017-10-01).

## Rules (signals on a completed 4-hour bar, executed at the open of the next bar)
- **HA-FLIP (always in the market):** a green candle after a red one -> long; a red candle after a green one -> short; each colour change reverses the position.
- **HA-NOWICK:** enter long on a green candle with **no lower wick**, short on a red candle with **no upper wick**; exit a long at the first red candle, a short at the first green candle (flat in between). If the exit candle is itself a strong candle of the other colour, the exit and the new entry happen together (a reversal).
- **HA-NOWICK-200:** HA-NOWICK, but longs only when the real close of the signal bar is above its **200-bar simple moving average** (of real 4-hour closes, about 33 days), shorts only when below. Exits as in HA-NOWICK, not by the average.
- **Execution:** at the open of the first minute of the next 4-hour bar (the signal is known only when its bar closes). No stop or target beyond the rules (the colour change is the stop, as in the tutorials). A position open at the end of the data closes at the last minute's close.

## Costs
- **0.05% of the price on every fill** (about 0.1% a round trip), the Binance USD-margined perpetual taker fee, as in our other Bitcoin tests, so that shorts are possible. A reversal counts as two fills.
- **Funding sensitivity (reported, not gated):** the result again with 10% a year of the entry price per day held charged to longs and shorts alike, as in the Turtle Bitcoin test.
- Results in % per trade (of the entry price) and as the compound growth of 1 unit fully invested.

## Periods, gates, control
- **Periods (by entry date), as in the other Bitcoin tests:** development 2017-10-01 to 2021-06-30; validation 2021-07-01 to 2023-12-31; holdout 2024-01-01 to 2026-09-30 (**already used** by four earlier Bitcoin tests).
- **Six gates per variant** (net % per trade): validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.0** (three variants of an indicator 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 (shifted holdings):** each variant's real position series (long, short or flat on every 4-hour bar) shifted, as a whole, by one random circular offset of whole days (at least 5% of them; seeds 1000 + run, 500 runs), and traded on the real prices with the same costs. It keeps the number of trades, the holding times and the long/short mix and breaks only the timing. Statistic: average net % per trade.
- **Rule 3:** recomputed without trades open over a known data gap of at least 60 minutes.
- **Also reported:** win rate with its Wilson interval; average and median holding time; long and short; by year; how often the HA colour changed; the compound result against buy and hold over the same span (descriptive).

## Engine and self-test (before the run)
New engine `ha_lib.js`, independent re-implementation `ha_ref.js`, `ha_selftest.js` that must pass before any result is printed: the HA formulas against hand-worked candles; the wick tests; a short bar skipped; the signal on bar close executed at the next open; a reversal; the 200-bar filter; the end-of-data close; 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, published only with the owner's agreement. Working title for search: "Heikin Ashi Strategy Backtest: Does It Work on Bitcoin?".

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. One market, one timeframe, three readings of a rule with many versions.
