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
| Setting | Default | Range | What it does |
|---|---|---|---|
| atr_period | 14 | 1 to 500 | ATR length (Wilder) for every buffer. |
| swing_k | 2 | 0.1 to 20 | Swing reversal in ATRs: a pivot is confirmed when a close moves this far back. |
| swing_min_pct | 0.1 | 0 to 10 | Smallest swing reversal, % of the close. |
| lookback | 10 | 1 to 100 | Candles searched back from a break for the block candle. |
| break_k | 0 | 0 to 5 | A swing level is broken only this many ATRs beyond it. |
| disp_k | 1.5 | 0.1 to 10 | Displacement: smallest body in ATRs. |
| close_frac | 0.25 | 0.01 to 0.5 | Displacement: the close lies in this top (bull) or bottom (bear) fraction of the range. |
| floor_pct | 0.05 | 0 to 10 | Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple). |
| invalid_k | 0.1 | 0 to 5 | A close this many ATRs beyond a zone's far edge ends the zone. |
| max_zones | 5 | 1 to 20 | Active zones kept (oldest dropped). |
| max_age_bars | 200 | 10 to 2000 | Candles after its birth until a zone or level expires. |
| breaker_bars | 50 | 1 to 1000 | Candles a broken block waits for its breaker retest. |
| require_sweep | no | Only a block whose break follows a sweep of the opposite liquidity (bull: a swept low). | |
| sweep_bars | 20 | 1 to 500 | With require_sweep: most candles from the sweep to the break. |
| sweep_k | 0.05 | 0 to 5 | With require_sweep: a sweep's wick must pass the level by this many ATRs. |
| require_fvg | no | Only a block whose move up to the break leaves a fair value gap of its side. | |
| gap_k | 0.1 | 0 to 5 | With require_fvg: smallest gap in ATRs (the fvg rule). |
| pick_rank | 1 | 1 to 5 | Pick outputs: 1 = the nearest zone, 2 = the next one out, … |
| pick_min_visits | 0 | 0 to 50 | Pick outputs: only zones visited at least this often. |
| pick_side | any | any, bull, bear | nearest_low/high: zones of any side, or only the bull (support) or bear (resistance) side. |
What it gives
| Output | What it is |
|---|---|
| In a block | True while the close is inside an active order block. |
| In a bull block | True while the close is inside a bull order block. |
| In a bear block | True while the close is inside a bear order block. |
| Low edge of the block above | Low edge of the nearest order block wholly above the close. |
| High edge of the block above | High edge of the nearest order block wholly above the close. |
| Low edge of the block below | Low edge of the nearest order block wholly below the close. |
| High edge of the block below | High edge of the nearest order block wholly below the close. |
| Active blocks | Active order blocks (both sides). |
| Visits of the nearest block | Visits of the nearest order block (the one holding the close, else the closer of above/below); one continuous stay is one visit. |
| New bull block | True on the candle a bull order block is born. |
| New bear block | True on the candle a bear order block is born. |
| Bull block invalidated | True on the candle a close goes through a bull order block (it ends). |
| Bear block invalidated | True on the candle a close goes through a bear order block (it ends). |
| Low edge of the block the close is in | Low 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 in | High 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 block | True on the candle the first visit of a bull order block starts (its visits become 1). |
| First touch of a bear block | True on the candle the first visit of a bear order block starts (its visits become 1). |
| Bullish breaker | True when a broken bearish block is retested from above and holds. |
| Bearish breaker | True when a broken bullish block is retested from below and holds. |
| Low edge of the picked block | Low 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 block | High 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 block | Low 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 block | High 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 block | Low 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 block | High 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 block | Low edge of the newest active bull order block, from the candle it is born (none before). |
| High edge of the newest bull block | High edge of the newest active bull order block, from the candle it is born (none before). |
| Low edge of the newest bear block | Low edge of the newest active bear order block, from the candle it is born (none before). |
| High edge of the newest bear block | High 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