Order blocks

The last opposite candle before a strong break of a swing level, kept as a zone.

Order block: when a close breaks the last unbroken swing high by max(floor_pct % × close, break_k × ATR) (swing params as swing), the newest red candle among the lookback candles before it is the bull block (its full high-low range) if a bull displacement (disp_k, close_frac) follows it up to the break; bear is the mirror. A close beyond the far edge by invalid_k ATRs ends the block and makes it a breaker of the other side for breaker_bars candles: bear_breaker = a later candle reaches the broken bull block from below and closes back under it; bull_breaker is the mirror. Blocks expire max_age_bars after birth; at most max_zones are kept. require_sweep (off by default): a bull block counts only when a sweep of the last swing low (a wick below it by max(floor_pct % × close, sweep_k × ATR) closing back above, the liquidity rule) came at most sweep_bars candles before the break; bear needs a swept swing high. require_fvg (off by default): the candles from the block to the break must hold a fair value gap of the block's side (the fvg rule with gap_k).

Order blocks 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.
lookback101 to 100Candles searched back from a break for the block candle.
break_k00 to 5A swing level is broken only this many ATRs beyond it.
disp_k1.50.1 to 10Displacement: smallest body in ATRs.
close_frac0.250.01 to 0.5Displacement: the close lies in this top (bull) or bottom (bear) fraction of the range.
floor_pct0.050 to 10Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple).
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.
breaker_bars501 to 1000Candles a broken block waits for its breaker retest.
require_sweepnoOnly a block whose break follows a sweep of the opposite liquidity (bull: a swept low).
sweep_bars201 to 500With require_sweep: most candles from the sweep to the break.
sweep_k0.050 to 5With require_sweep: a sweep's wick must pass the level by this many ATRs.
require_fvgnoOnly a block whose move up to the break leaves a fair value gap of its side.
gap_k0.10 to 5With require_fvg: smallest gap in ATRs (the fvg rule).
pick_rank11 to 5Pick outputs: 1 = the nearest zone, 2 = the next one out, …
pick_min_visits00 to 50Pick outputs: only zones visited at least this often.
pick_sideanyany, bull, bearnearest_low/high: zones of any side, or only the bull (support) or bear (resistance) side.

What it gives

OutputWhat it is
In a blockTrue while the close is inside an active order block.
In a bull blockTrue while the close is inside a bull order block.
In a bear blockTrue while the close is inside a bear order block.
Low edge of the block aboveLow edge of the nearest order block wholly above the close.
High edge of the block aboveHigh edge of the nearest order block wholly above the close.
Low edge of the block belowLow edge of the nearest order block wholly below the close.
High edge of the block belowHigh edge of the nearest order block wholly below the close.
Active blocksActive order blocks (both sides).
Visits of the nearest blockVisits of the nearest order block (the one holding the close, else the closer of above/below); one continuous stay is one visit.
New bull blockTrue on the candle a bull order block is born.
New bear blockTrue on the candle a bear order block is born.
Bull block invalidatedTrue on the candle a close goes through a bull order block (it ends).
Bear block invalidatedTrue on the candle a close goes through a bear order block (it ends).
Low edge of the block the close is inLow edge of the order block the close is inside (the most recently created if several); none outside every zone. A long's stop below the zone.
High edge of the block the close is inHigh edge of the order block the close is inside (the most recently created if several); none outside every zone. A short's stop above the zone.
First touch of a bull blockTrue on the candle the first visit of a bull order block starts (its visits become 1).
First touch of a bear blockTrue on the candle the first visit of a bear order block starts (its visits become 1).
Bullish breakerTrue when a broken bearish block is retested from above and holds.
Bearish breakerTrue when a broken bullish block is retested from below and holds.
Low edge of the picked blockLow edge of the pick_rank-th order block (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits, of the pick_side side; inside it or not.
High edge of the picked blockHigh edge of the pick_rank-th order block (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits, of the pick_side side; inside it or not.
Low edge of the picked bull blockLow edge of the bull pick_rank-th order block (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
High edge of the picked bull blockHigh edge of the bull pick_rank-th order block (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
Low edge of the picked bear blockLow edge of the bear pick_rank-th order block (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
High edge of the picked bear blockHigh edge of the bear pick_rank-th order block (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
Low edge of the newest bull blockLow edge of the newest active bull order block, from the candle it is born (none before).
High edge of the newest bull blockHigh edge of the newest active bull order block, from the candle it is born (none before).
Low edge of the newest bear blockLow edge of the newest active bear order block, from the candle it is born (none before).
High edge of the newest bear blockHigh edge of the newest active bear order block, from the candle it is born (none before).

What it reads

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

Warm-up

With its default settings, Order blocks needs 521 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 Order blocks with its default settings