Indicators··8 min read

Order Block Zones with Objective Displacement Rules

0 references, link-verifiedEditor of record: Shane CantyStandards review editorial standard · audit log

Order blocks are price zones where institutional order flow is believed to accumulate, typically at recent consolidation areas or reversal points. This indicator identifies these zones using objective, rule-based criteria: consolidation width, boundary definition, and displacement measurement. Traders use order block analysis to identify support and resistance levels with institutional context, though the interpretation remains probabilistic and offers no predictive guarantee.

//@version=6
indicator("Order Block Zones with Objective Displacement", overlay=true, max_lines_count=500, max_boxes_count=500)

// Inputs
lookback = input.int(20, title="Lookback Period for Swing Identification", minval=5, maxval=50)
consolidation_bars = input.int(5, title="Minimum Consolidation Bars", minval=2, maxval=20)
displacement_atr_mult = input.float(1.5, title="Displacement Threshold (ATR Multiple)", minval=0.5, maxval=5.0)
color_demand = input.color(color.new(color.green, 80), title="Demand Block Color")
color_supply = input.color(color.new(color.red, 80), title="Supply Block Color")
show_labels = input.bool(true, title="Show Displacement Labels")

// ATR for threshold scaling
atr = ta.atr(14)

// Track the most recent order blocks
var box current_demand_block = na
var box current_supply_block = na
var float demand_top = na
var float demand_bottom = na
var float supply_top = na
var float supply_bottom = na
var bool demand_broken = false
var bool supply_broken = false
var int demand_break_bar = na
var int supply_break_bar = na

// Identify recent swing high and low over the lookback period
recent_swing_high = ta.highest(high, lookback)
recent_swing_low = ta.lowest(low, lookback)
swing_high_bar = ta.highestbars(high, lookback)
swing_low_bar = ta.lowestbars(low, lookback)

// Check if we are in a consolidation phase (price not making new highs/lows for N bars)
bars_since_swing_high = -swing_high_bar
bars_since_swing_low = -swing_low_bar
is_consolidating = (bars_since_swing_high >= consolidation_bars and bars_since_swing_low >= consolidation_bars)

// ===== DEMAND BLOCK (support-type order block) =====
// Forms when price consolidates and shows bullish close
if is_consolidating and close > open
    if na(demand_top) or close > demand_top
        demand_top = recent_swing_high
        demand_bottom = recent_swing_low
        demand_broken = false
        demand_break_bar = na
        if not na(current_demand_block)
            box.set_closed(current_demand_block, true)
        current_demand_block := box.new(bar_index, demand_bottom, bar_index, demand_top, closed=false, 
                                        border_color=na, bgcolor=color_demand, text="Demand Block")

// Check for demand block displacement (close below demand bottom with ATR threshold)
if not na(current_demand_block) and not demand_broken
    if close < demand_bottom and (demand_bottom - close) > displacement_atr_mult * atr
        demand_broken := true
        demand_break_bar := bar_index

// ===== SUPPLY BLOCK (resistance-type order block) =====
// Forms when price consolidates and shows bearish close
if is_consolidating and close < open
    if na(supply_top) or close < supply_top
        supply_top = recent_swing_high
        supply_bottom = recent_swing_low
        supply_broken = false
        supply_break_bar = na
        if not na(current_supply_block)
            box.set_closed(current_supply_block, true)
        current_supply_block := box.new(bar_index, supply_bottom, bar_index, supply_top, closed=false,
                                        border_color=na, bgcolor=color_supply, text="Supply Block")

// Check for supply block displacement (close above supply top with ATR threshold)
if not na(current_supply_block) and not supply_broken
    if close > supply_top and (close - supply_top) > displacement_atr_mult * atr
        supply_broken := true
        supply_break_bar := bar_index

// Extend boxes to current bar
if not na(current_demand_block)
    box.set_right(current_demand_block, bar_index)
if not na(current_supply_block)
    box.set_right(current_supply_block, bar_index)

// Plot labels for displacement confirmation
if show_labels
    if demand_broken and not na(demand_break_bar)
        label.new(demand_break_bar, high, "D-Disp", color=color.green, style=label.style_label_down, textcolor=color.white)
    if supply_broken and not na(supply_break_bar)
        label.new(supply_break_bar, low, "S-Disp", color=color.red, style=label.style_label_up, textcolor=color.white)

How the code works

The indicator first identifies swing highs and lows over the user-defined lookback period using the ta.highest() and ta.lowest() functions, storing how many bars ago each occurred. It then monitors price consolidation: when the bar count since the most recent swing high and swing low both exceed the minimum consolidation bar threshold, the code treats the zone between those swing points as an active order block.

A demand block forms when price is consolidating and the current bar closes above its open (bullish consolidation signal). The block's boundaries are set to the swing high (top) and swing low (bottom) of the lookback period. The indicator stores this zone as a box object and monitors it for "displacement": a close below the demand block's bottom boundary by more than a user-defined multiple of ATR (Average True Range). When displacement is confirmed, a label marks the event bar.

Supply blocks work inversely: they form during bearish consolidation (close below open) in a consolidation zone, with boundaries at the swing high and low. Displacement occurs when price closes above the supply top by more than the ATR multiple.

The var keyword maintains state across bars for the current blocks and their break status, preventing redundant zone creation and ensuring each displacement event is tracked only once. The indicator automatically closes the previous block when a new consolidation zone is identified, ensuring only recent order blocks occupy the chart.

Reading it on a chart

Demand blocks appear as green zones and supply blocks as red zones. A trader observing this indicator would look for:

  1. Zone formation: Shaded boxes appear on the chart at consolidation areas, marking where price has halted directional movement and formed a tight range.
  2. Displacement confirmation: When price breaks a block boundary by more than the ATR threshold, a label appears ("D-Disp" for demand, "S-Disp" for supply). This signals that the order block zone has been tested with sufficient force, not merely touched.
  3. Multiple tests: Price may approach a block boundary several times without displacing it; displacement only confirms when the threshold magnitude is exceeded.
  4. Reversal potential: After displacement, price may return toward the order block zone, as the underlying consolidation may represent trapped liquidity. A trader might watch for re-entry zones or use the displaced block as a reversal reference level.

The lookback period controls how far back the indicator searches for swing points; shorter lookbacks (5-10 bars) identify tight recent consolidations, while longer lookbacks (20-30 bars) capture broader institutional order accumulation zones. The consolidation bar setting filters out minor pauses and focuses on meaningful sideways periods.

Limitations

The indicator does not distinguish between institutional order clusters and retail price action; consolidation zones are purely technical, derived from price bars alone, not from volume, order flow, or market microstructure data. The ATR displacement threshold is relative and will scale with volatility, meaning the same price movement may trigger displacement during calm periods but fail during high-volatility regimes when ATR expands.

Order blocks assume price will respect zone boundaries, yet many consolidations break without reversal, and price may gap past a block entirely, yielding no testable opportunity. The indicator looks backward only and cannot predict whether a future test of a block will reverse or break through; zone identification does not improve predictive accuracy. The indicator is designed for swing-length consolidations (5+ bars) and will not identify intrabar order blocks or very short-term range-bound action used in scalping.

Repainting does not occur because bar states (consolidation, displacement) finalize once identified, but zones themselves redraw as new consolidations form, altering the historical display. Finally, the objective rules remove visual subjectivity but do not validate that identified zones will function as support, resistance, or reversal points; a zone meeting all criteria may still fail to halt or reverse price.


Key definitions

Order block: A price zone corresponding to recent consolidation or reversal, hypothesized to align with institutional order concentration and used as a reference for support, resistance, or entry levels.

Consolidation: A period in which price high and low remain within a defined range for a specified number of bars, signaling reduced directional pressure.

Displacement: A break of an order block boundary by a threshold amount (typically measured in volatility units such as ATR), confirming material testing of the zone.

Swing high: The highest high or close within a lookback period; represents local resistance in recent price history.

Swing low: The lowest low or close within a lookback period; represents local support in recent price history.

ATR (Average True Range): A volatility measure computed as the 14-bar average of the true range; used to scale thresholds to current market volatility conditions.

Demand block: An order block zone formed during bullish consolidation, expected to act as support if price returns to it.

Supply block: An order block zone formed during bearish consolidation, expected to act as resistance if price approaches it again.


References

  1. Wilder, J.W., "New Concepts in Technical Trading Systems", Trend Research Ltd. (1978). Foundational work introducing Average True Range and volatility-adjusted analysis methods for technical trading.

  2. TradingView, "Pine Script Reference Manual v6", TradingView.com (2024). Https://www.tradingview.com/pine-script-reference/, Language specification and function reference for indicator construction.

  3. Wikipedia, "Support and resistance", Wikipedia.org. Https://en.wikipedia.org/wiki/Support_and_resistance, Overview of price level mechanics in technical analysis.

  4. Investopedia, "Order Block", Investopedia.com. Https://www.investopedia.com/terms/o/orderblock.asp, Explanation of practitioner terminology and consolidation-based zone identification.

  5. CME Group, "Crude Oil Futures Contract Specifications", CME.com (2024). Https://www.cmegroup.com/trading/energy/crude-oil/, Example primary source; order block mechanics apply across any liquid instrument class.


Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.

Last reviewed by the PropLedger research pipeline: 2026-09-20. Educational research on historical data, not financial advice.

Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.