A rule-based definition — the last opposing candle before a displacement move — for a concept that is usually defined only after the fact.
An order block, in smart-money-concepts terminology, is a candle (or the price zone it covers) said to mark where institutions accumulated positions just before a strong move, with the expectation that the zone will matter again if price returns to it. Honesty first: there is no verifiable public evidence that institutions systematically leave retrievable 'blocks' of orders at these candles. Institutional execution is deliberately fragmented across venues and time precisely to avoid leaving footprints, and the story as usually told is unfalsifiable — any zone that holds 'proves' it and any zone that fails is explained away. What can be done honestly is to strip the narrative and keep a testable pattern: define an order block objectively as the last opposing candle immediately before a displacement candle — for example, the final down candle before an up candle whose body exceeds a stated multiple of ATR. That definition is measurable and reproducible, which means its retest behavior can actually be studied rather than asserted. The marks it produces describe past price arrangements only; nothing about the definition predicts future behavior. This is educational material, not financial advice, and trading involves risk of loss.
The rule has two parts. First, displacement: a candle counts as a displacement candle when its body (the absolute distance from open to close) exceeds a chosen multiple of the Average True Range — say 1.5x ATR(14) — which normalizes 'unusually strong' across instruments and volatility regimes instead of relying on eyeballing. Second, the opposing candle: a bullish order block is the down candle immediately preceding an up displacement candle, and a bearish order block is the up candle immediately preceding a down displacement candle. The zone is then defined from that opposing candle — its full high-to-low range, or the body only; both variants exist and the choice must be stated because they produce different zones. A retest (often called 'mitigation') is simply price later trading back into the zone, which is equally codeable. The parameters — ATR length, displacement multiple, zone variant — control everything: a stricter multiple marks fewer, larger events; a looser one floods the chart. Because every piece is explicit, you can count how many zones a rule produces, measure how price behaved on return visits across a large sample, and test claims about order blocks instead of curating flattering examples in hindsight.
A typical starting point is ATR length 14 with a displacement body threshold of 1.5-2.0x ATR, and the zone taken from the opposing candle's high and low. Body-only zones are a stricter variant. Lower thresholds mark far more zones; there is no correct value, only stated ones whose consequences you have measured.
//@version=6
indicator("Rule-Based Order Block Marker", overlay = true)
atrLen = input.int(14, "ATR Length", minval = 1)
dispMult = input.float(1.5, "Displacement Body (x ATR)", minval = 0.5, step = 0.1)
atrVal = ta.atr(atrLen)
body = math.abs(close - open)
// Displacement: a candle whose body exceeds dispMult x ATR
dispUp = close > open and body > dispMult * atrVal
dispDn = close < open and body > dispMult * atrVal
// Falsifiable rule: the LAST OPPOSING candle immediately before displacement.
// Bullish OB = down candle followed by an up displacement candle; mirrored for bearish.
bullOB = dispUp and close[1] < open[1] and barstate.isconfirmed
bearOB = dispDn and close[1] > open[1] and barstate.isconfirmed
// The shape marks the prior (opposing) candle via a display offset
plotshape(bullOB, "Bullish OB (prior bar)", style = shape.triangleup, location = location.belowbar, color = color.teal, offset = -1)
plotshape(bearOB, "Bearish OB (prior bar)", style = shape.triangledown, location = location.abovebar, color = color.maroon, offset = -1)Pro tip: If you want to know whether order blocks mean anything on your market, do the unglamorous thing: fix the rule, mark every zone it produces — including the ones that fail — and measure behavior on return visits across hundreds of cases. A definition you cannot write as code is a definition you cannot test, and a zone that is only identified after price reacted to it is a story, not a tool. Educational context only, not financial advice; no pattern predicts price, and all trading carries risk of loss.
Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.