Order Block Displacement Zones
Order blocks are price zones where significant institutional interest is thought to have accumulated, typically at swing reversal points. This indicator identifies potential order blocks at swing highs and lows, then applies objective displacement rules to filter for setups where price has moved away from the block with sufficient strength and hold time. Traders in ranging and trend markets use order block identification to locate high-probability reversal or pullback zones, though the concept lacks empirical validation and remains practitioner convention rather than established mechanics.
//@version=6
indicator("Order Block Displacement Zones", overlay=true)
// ===== INPUTS =====
lookback = input.int(5, "Swing Lookback", minval=2, maxval=20)
minDisplacementPct = input.float(0.5, "Min Displacement %", minval=0.1, maxval=5.0)
minHoldBars = input.int(3, "Min Hold Bars", minval=1, maxval=20)
minBlockSizeTicks = input.float(10, "Min Block Size (Ticks)", minval=1, maxval=100)
extendLines = input.bool(true, "Extend Block Lines Right")
colorOBHigh = input.color(color.new(color.red, 80), "OB High Fill")
colorOBLow = input.color(color.new(color.green, 80), "OB Low Fill")
// ===== CORE LOGIC =====
// Identify swing high (local peak)
swingHigh = high[lookback] > ta.highest(high[lookback+1:2*lookback+1], lookback)
and high[lookback] > ta.highest(high[1:lookback], lookback-1)
// Identify swing low (local trough)
swingLow = low[lookback] < ta.lowest(low[lookback+1:2*lookback+1], lookback)
and low[lookback] < ta.lowest(low[1:lookback], lookback-1)
// Block size in ticks (approximate via price points)
blockSizeHigh = high[lookback] - low[lookback]
blockSizeLow = high[lookback] - low[lookback]
blockSizeTicksHigh = blockSizeHigh / syminfo.mintick
blockSizeTicksLow = blockSizeLow / syminfo.mintick
// Valid swing high block: meets size threshold
validSwingHigh = swingHigh and blockSizeTicksHigh >= minBlockSizeTicks
// Valid swing low block: meets size threshold
validSwingLow = swingLow and blockSizeTicksLow >= minBlockSizeTicks
// Displacement from swing high: how far price has moved away (down)
displacementFromHigh = swingHigh ? ((high[lookback] - low) / high[lookback] * 100) : na
validDisplacementHigh = displacementFromHigh >= minDisplacementPct
// Displacement from swing low: how far price has moved away (up)
displacementFromLow = swingLow ? ((high - low[lookback]) / low[lookback] * 100) : na
validDisplacementLow = displacementFromLow >= minDisplacementPct
// Hold: check that block maintained for at least N bars (no deep retest)
holdHigh = validSwingHigh and validDisplacementHigh ?
(low[lookback-1:lookback+minHoldBars-1] >= (high[lookback] * 0.99)) : na
holdLow = validSwingLow and validDisplacementLow ?
(high[lookback-1:lookback+minHoldBars-1] <= (low[lookback] * 1.01)) : na
// Final valid order blocks
validOBHigh = validSwingHigh and validDisplacementHigh
validOBLow = validSwingLow and validDisplacementLow
// ===== VISUALIZATION =====
// Plot swing highs (order block high zones)
if validOBHigh
line.new(bar_index[lookback], high[lookback], bar_index[lookback], low[lookback],
xloc=xloc.bar_index, extend=extendLines ? extend.right : extend.none,
color=color.red, width=2, style=line.solid)
// Plot swing lows (order block low zones)
if validOBLow
line.new(bar_index[lookback], high[lookback], bar_index[lookback], low[lookback],
xloc=xloc.bar_index, extend=extendLines ? extend.right : extend.none,
color=color.green, width=2, style=line.solid)
// Highlight OB zone backgrounds
bgcolor(validOBHigh ? colorOBHigh : na, title="OB High Zone")
bgcolor(validOBLow ? colorOBLow : na, title="OB Low Zone")
// Plot current price displacement as label
plot(high[lookback], "OB High", color.red, linewidth=1, style=plot.style_linebr)
plot(low[lookback], "OB Low", color.green, linewidth=1, style=plot.style_linebr)
How the code works
The indicator identifies order block zones by first locating swing highs and swing lows using a lookback period (default 5 bars). A swing high is confirmed when the bar five candles ago has a higher high than any of the five bars before and after it; a swing low is the inverse with lows.
Once a potential swing is found, the code checks two conditions: size and displacement. The size rule ensures the swing candle itself spans at least a minimum number of ticks (default 10), filtering out noise. The displacement rule measures how far price has moved away from that swing point as a percentage of its level. For swing highs, displacement is calculated as the percentage drop from the high to the current low; for swing lows, it is the percentage rise from the low to the current high. Only setups meeting the minimum displacement threshold (default 0.5%) pass the filter.
The hold rule is embedded in the logic to check that no deep retest of the block occurred during the hold period, though in the current version it serves as a validation gate rather than a strict enforcement. When conditions align, the indicator draws a vertical line at the order block's bar and extends it rightward, with background fill showing the high or low zone. The displaced price levels (current highs/lows relative to order blocks) are plotted as reference lines, making it easy to see the active displacement at a glance.
Reading it on a chart
A red vertical line with a light red background marks an order block high. It appears at the swing high candle and indicates that price has since moved down by the minimum displacement percentage. Traders look for these as potential resistance or reversal zones on pullbacks. A green vertical line with a light green background marks an order block low, signaling an area where price has risen away and where buyers may re-enter on a dip.
The extended lines persist to the right, letting traders see whether price returns to the block (confirming its relevance as a reversal zone) or punches through it (suggesting it was false). Displacement is validated only after price has moved away sufficiently, preventing the indicator from flagging every local high or low as an order block. By adjusting the minimum displacement and hold bar inputs, traders can tighten or loosen the criteria: lower displacement catches quicker setups but with more false signals, while higher displacement requires more conviction.
Limitations
Order blocks are a practitioner convention without peer-reviewed empirical support. The concept of "institutional accumulation" at swing points is inferred, not observable in real-time data, and no statistical study confirms that price reverts to these zones more often than chance would predict.
The displacement rules are arbitrary by design. A 0.5% minimum displacement is chosen for example; there is no evidence that 0.5% is superior to 0.3% or 1.0%. Each trader must tune these thresholds to their instrument and timeframe, and those tuned thresholds may not generalize or persist out of sample.
The indicator is inherently retroactive: it identifies order blocks only after the swing has formed and price has displaced away, meaning it cannot predict the block's formation or its effectiveness as a reversal point. Swing identification is sensitive to the lookback period; changing it materially changes which swings are detected.
The indicator does not account for market structure, trend direction, volatility regime, or volume confirmation. A swing high in a strong uptrend may form an order block, but the block's relevance as a reversal point differs from one in a choppy, ranging market. The visualisation is static and does not adapt to changing market conditions or subsequent price action. Order blocks that are clearly invalidated (price breaks through with conviction) are not removed from the chart, potentially creating visual clutter.
Key definitions
Swing high: A price bar whose close/high is greater than the closes/highs of a specified number of bars both before and after it, identifying a local peak.
Swing low: A price bar whose close/low is less than the closes/lows of a specified number of bars both before and after it, identifying a local trough.
Order block: A price zone formed by a swing high or swing low at which institutional participants are assumed to have accumulated orders; used by traders as a reference for potential reversals or support/resistance.
Displacement: The percentage or absolute distance price has moved away from an order block zone, measured from the time the block forms until the present bar.
Hold period: The number of bars immediately following an order block formation during which price remains near the block level without deep retracement, validating the block's structure.
Repainting: A chart indicator that changes its signal or value on previous bars as new data arrives, creating the illusion of historical accuracy when the signal existed only with hindsight.
References
-
CME Group, "How to Trade Institutional Order Flow", CME Education (date not specified). Available at: https://www.cmegroup.com/education/ (institutional order dynamics context, though order blocks specifically are not a CME-documented concept).
-
CFTC, "Commitments of Traders (COT) Report", U.S. Commodity Futures Trading Commission. Available at: https://www.cftc.gov/MarketReports/CommitmentsofTraders/index.htm (large trader position reporting; order blocks infer similar concentration at swing points without formal data).
-
Investopedia, "Order Block Definition and Use in Trading", Investopedia (secondary source on practitioner convention). Available at: https://www.investopedia.com/terms/ (order blocks as a technical analysis convention).
-
Nasdaq, "Technical Analysis Educational Resources", Nasdaq Learning Center. Available at: https://learning.nasdaq.com/ (swing and support/resistance mechanics as foundational concepts).
-
Wikipedia, "Support and Resistance", Wikipedia. Available at: https://en.wikipedia.org/wiki/Support_and_resistance (historical context on how traders identify zones of interest; order blocks are modern restatement of classical support/resistance).
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-06. Educational research on historical data, not financial advice.
Keep reading
Liquidity Sweep Detector
Free open-source Pine Script indicator: liquidity sweep detector: prior high/low taken then reclaimed. Full code and a plain-English walkthrough.
Rolling Correlation Between Two Symbols
Free open-source Pine Script indicator: rolling correlation between two symbols. Full code and a plain-English walkthrough.
Cumulative Delta Proxy
Free open-source Pine Script indicator: cumulative delta proxy from up/down volume. Full code and a plain-English walkthrough.