Breakout and retest

A close through a support or resistance zone, then a pullback to it that holds.

Support zones from confirmed swing lows, resistance zones from confirmed swing highs (swing params as swing). A new zone is zone_k ATRs thick from the pivot inward; a pivot within merge_k ATRs of the nearest zone of its side widens it (new version) while the zone stays at most width_k ATRs wide; zones never merge with each other. A close beyond the far edge by invalid_k ATRs breaks the zone (support_break / resistance_break) and removes it. Every buffer has the floor_pct % floor. Zones expire max_age_bars after birth; at most max_zones are kept. Built-in setup: a broken zone is frozen (the newest break replaces an older setup). bull_retest = a later candle touches the frozen resistance (low ≤ its high) and closes above it; bear_retest is the mirror. The setup ends at the retest, after retest_bars candles, or on a close back through the far edge (by invalid_k ATRs). frozen_level_low/high are the frozen zone's edges while a setup is open and on its retest candle (the retested zone wins over a break on the same candle), so a stop beyond the retested zone is ready on the signal candle.

Breakout and retest is a structure detector: it marks price structure on the chart and counts against the plan's detector limit.

Settings

SettingDefaultRangeWhat it does
atr_period141 to 500ATR length (Wilder) for every buffer.
swing_k20.1 to 20Swing reversal in ATRs: a pivot is confirmed when a close moves this far back.
swing_min_pct0.10 to 10Smallest swing reversal, % of the close.
floor_pct0.050 to 10Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple).
zone_k0.250 to 5Thickness of a new zone in ATRs (from the pivot inward).
merge_k0.50 to 5A pivot this many ATRs or closer to a zone of its side joins it.
width_k1.50.1 to 10Widest zone after a merge, in ATRs.
invalid_k0.10 to 5A close this many ATRs beyond a zone's far edge ends the zone.
max_zones51 to 20Active zones kept (oldest dropped).
max_age_bars20010 to 2000Candles after its birth until a zone or level expires.
retest_bars201 to 500Candles after the break in which the retest must come.

What it gives

OutputWhat it is
Bullish retestTrue on the candle a broken resistance is retested from above and holds.
Bearish retestTrue on the candle a broken support is retested from below and holds.
Broken zone low edgeLow edge of the frozen broken zone (also on its retest candle).
Broken zone high edgeHigh edge of the frozen broken zone (also on its retest candle).

What it reads

It reads the whole candle (open, high, low, close and volume).

Warm-up

With its default settings, Breakout and retest needs 461 closed candles before its first value. A backtest loads them before its start date, so the first trade can already use it.

Test it

Copy this sentence into the Algonney chat to backtest it:

Backtest a strategy on BTC that uses Breakout and retest with its default settings