# Engulfing candle strategy on XAUUSD, 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 engulfing pattern, 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: engulfing candle, turn of the month on SPY, Parabolic SAR), as one of the most searched candlestick patterns not yet tested on the site.
- **The idea:** a **bullish engulfing** candle is an up candle whose body completely covers the body of the down candle before it; a **bearish engulfing** is the mirror. It is read as buyers (or sellers) taking over. The usual trade: enter after the pattern, stop beyond the engulfing candle, target a multiple of the risk. Write-ups add either a "reversal context" (the pattern only counts after a move the other way) or a trend filter. We fix four common readings and try no others after the result.
- **Earlier tests on this gold file (disclosed):** daily and 1-hour golden crosses, EMA 9/20, the opening range breakout, Turtle, noise area breakout, RSI 30/70, TTM Squeeze, WaveTrend, head and shoulders (15-minute), the H1 Open Trap and the night/day test. Candlestick patterns tested on the site: the inside bar (EUR/USD daily) and head and shoulders (gold). **No engulfing pattern has been computed on the site.**

## Instrument and data
- **XAUUSD** on the IC Markets MetaTrader 4 demo server, 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 })`), as in the WaveTrend and TTM Squeeze tests.
- **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 other 1-hour gold tests. Nothing in the rules depends on the time of day, so the known early time labels of 2004-2010 move whole bars without changing them (stated, no second run).
- **Holes (rule 3):** `data_holes_xau.json`; every gate and verdict is recomputed without trades open across a suspect or unclear gap; a changed verdict becomes Inconclusive.

## The pattern (on two consecutive 1-hour bars, the earlier P and the engulfing bar E)
- **Bullish engulfing:** P is a down bar (close < open), E is an up bar (close > open), **E's open <= P's close and E's close > P's open** (E's body covers P's body, a strictly higher close).
- **Bearish engulfing:** P is an up bar, E is a down bar, E's open >= P's close and E's close < P's open.
- Bars with open = close are neither up nor down and never form part of a pattern.

## Rules (one position at a time; a pattern while a trade is open is ignored)
- **Entry:** at the open of the first 1-minute bar after E closes: long after a bullish engulfing, short after a bearish one.
- **Stop:** the low of E for a long, the high of E for a short (no extra buffer). **R** = |entry - stop| in dollars per ounce. No trade if the entry is already at or beyond the stop.
- **Management on 1-minute bars** from the entry minute: the stop is tested before the target in every minute; a minute that opens beyond a level fills at its open; otherwise at the level. No time exit; a trade still open at the end of the data closes at the last close.
- **Four variants:**
  - **EG-1R:** every pattern; target 1R.
  - **EG-2R:** every pattern; target 2R.
  - **EG-2R-REV (reversal context):** target 2R; a bullish engulfing only when P's close is **below** the 20-bar simple moving average of 1-hour closes (taken at P), a bearish one only when P's close is above it (the pattern follows a move the other way).
  - **EG-2R-200 (trend filter):** target 2R; longs only when E's close is above the 200-bar exponential moving average of 1-hour closes, shorts only when below.
- Averages need their full history; no signal in the first 500 bars of the file.

## Costs
- **Baseline:** $0.30 per ounce per round trip, as in every gold test on the site; slippage zero beyond fills at a gapped open (optimistic, stated).
- **Scenario A (reported, not gated):** 3% a year of the entry price per calendar day held, longs and shorts alike.
- Results in R per trade and in dollars per ounce.

## 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** (net R): validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.0** (four variants of a pattern 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 whole days (at least 5% of them), to the first minute at or after the same time of day on the new day, same direction, the same stop and target distances in dollars, the same management, costs and one-position rule. 500 runs, seeds 1000 + run. Statistic: average net R per trade.
- **Also reported:** patterns per year; win rate with its Wilson interval; exits by reason; long and short; by year; by R size (descriptive); the cost per trade in R against the gross.

## Engine and self-test (before the run)
New engine `eg_lib.js`, independent re-implementation `eg_ref.js`, `eg_selftest.js` that must pass before any result is printed: hand-worked patterns (bullish and bearish, equal opens and closes, a doji, the strict close), entry at the next minute, the stop at the engulfing extreme, a gapped open through the stop, stop and target in the same minute, the 20-bar and 200-bar filters, one position at a time; the reference matched trade by trade on the real data for all four 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: "Engulfing Candle Strategy Backtest: 22 Years of Gold on the 1-Hour Chart".

## 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, four readings of a pattern with many versions.
