OPEN-SOURCE SCRIPT
Updated Order Block Matrix [Alpha Extract]

The Order Block Matrix indicator identifies and visualizes key supply and demand zones on your chart, helping traders recognize potential reversal points and high-probability trading setups.
This tool helps traders:
🔶 CALCULATION
The indicator processes chart data to identify and analyze order blocks:
Order Block Detection
Inputs:
Detection Logic:
🔶Volume Analysis
Volume Profiling:
Strength Assessment:
Pine Script®
🔶 DETAILS
Visual Features
Volume Profile Histograms:
Block Visualization:
Screener Table:
Interpretation
🔶 EXAMPLES
The indicator helps identify key trading opportunities:
Bullish Order Blocks
Bearish Order Blocks

Combined Strategies
🔶 SETTINGS
Customization Options
Order Block Detection:
Visual Style:
Color Settings:
Screener Table:
The Order Block Matrix indicator provides traders with powerful insights into market structure, helping to identify key levels where smart money is active and where high-probability trading opportunities may exist.
This tool helps traders:
- Visualize key order blocks with volume profile histograms showing liquidity distribution.
- Identify high-volume price levels where institutional activity occurs.
- rank historical order blocks and analyze their strength based on volume.
- Receive alerts for potential trading opportunities based on price-block interactions.
🔶 CALCULATION
The indicator processes chart data to identify and analyze order blocks:
Order Block Detection
Inputs:
- Price action patterns (consolidation areas followed by breakouts).
- Volume data from current and lower timeframes.
- User-defined lookback periods and thresholds.
Detection Logic:
- Identifies consolidation areas using a dynamic range comparison.
- Confirms breakout patterns with percentage threshold validation.
- Maps volume distribution across price levels within each order block.
🔶Volume Analysis
Volume Profiling:
- Divides each order block into configurable grid segments.
- Maps volume distribution across price segments within blocks.
- Highlights zones with highest volume concentration.
Strength Assessment:
- Calculates total block volume and relative strength metrics.
- Compares block volume to historical averages.
- Determines probability of reversal based on volume patterns.
isConsolidation(len) =>
high_range = ta.highest(high, len) - ta.lowest(high, len)
low_range = ta.highest(low, len) - ta.lowest(low, len)
avg_range = (high_range + low_range) / 2
current_range = high[1] - low[1]
current_range <= avg_range * (1 + obThreshold)
high_range = ta.highest(high, len) - ta.lowest(high, len)
low_range = ta.highest(low, len) - ta.lowest(low, len)
avg_range = (high_range + low_range) / 2
current_range = high[1] - low[1]
current_range <= avg_range * (1 + obThreshold)
🔶 DETAILS
Visual Features
Volume Profile Histograms:
- Color-coded bars showing volume concentration within order blocks.
- Gradient coloring based on relative volume (high volume = brighter colors).
- Bull blocks (green/teal) and bear blocks (red) with varying opacity.
Block Visualization:
- Dynamic box sizing based on volume concentration.
- Optional block borders and background fills.
- Volume labels showing total block volume.
Screener Table:
- Real-time analysis of order block metrics.
- Shows block direction, proximity, retest count, and volume metrics.
- Color-coded for quick reference.
Interpretation
- High Volume Areas: Zones with institutional interest and potential reversal points.
- Block Direction: Bullish blocks typically support price, bearish blocks typically resist price.
- Retests: Multiple tests of an order block may strengthen or weaken its influence.
- Block Age: Newer blocks often have stronger influence than older ones.
- Volume Concentration: Brightest segments within blocks represent the highest volume areas.
🔶 EXAMPLES
The indicator helps identify key trading opportunities:
Bullish Order Blocks
- Support Zones: Identify strong support levels where price is likely to bounce.
- Breakout Confirmation: Validate breakouts with volume analysis to avoid false moves.
- Retest Strategies: Enter trades when price retests a bullish order block with high volume.
Bearish Order Blocks
- Resistance Zones: Identify strong resistance levels where price is likely to reverse.
- Distribution Areas: Detect zones where smart money is distributing to retail.
- Short Opportunities: Find optimal short entry points at high-volume bearish blocks.
Combined Strategies
- Order Block Stacking: Multiple aligned blocks create stronger support/resistance zones.
- Block Mitigation: When price breaks through a block, it often indicates a strong trend continuation.
- Volume Profile Applications: Higher volume segments provide more precise entry and exit points.
🔶 SETTINGS
Customization Options
Order Block Detection:
- Consolidation Lookback: Adjust the period for consolidation detection.
- Breakout Threshold: Set minimum percentage for breakout confirmation.
- Historical Lookback Limit: Control how far back to scan for historical order blocks.
- Maximum Order Blocks: Limit the number of visible blocks on the chart.
Visual Style:
- Grid Segments: Adjust the number of volume profile segments.
- Extend Blocks to Right: Enable/disable extending blocks to current price.
- Show Block Borders: Toggle border visibility.
- Border Width: Adjust thickness of block borders.
- Show Volume Text: Enable/disable volume labels.
- Volume Text Position: Control placement of volume labels.
Color Settings:
- Bullish High/Low Volume Colors: Customize appearance of bullish blocks.
- Bearish High/Low Volume Colors: Customize appearance of bearish blocks.
- Border Color: Set color for block outlines.
- Background Fill: Adjust color and transparency of block backgrounds.
- Volume Text Color: Customize label appearance.
Screener Table:
- Show Screener Table: Toggle table visibility.
- Table Position: Select positioning on the chart.
- Table Size: Adjust display size.
The Order Block Matrix indicator provides traders with powerful insights into market structure, helping to identify key levels where smart money is active and where high-probability trading opportunities may exist.
Release Notes
Major Fixes:1. Window Mode Implementation
Added windowsis = true and mswindow = 1000 to process only the last 1000 bars
This directly addresses the max_bars_back limitation that was causing issues on lower timeframes
Only processes bars within the window range: inWindowRange = windowsis ? bar_index > (last_bar_index - mswindow) : true
2. Removed Complex Lower Timeframe Processing
Eliminated the request.security_lower_tf() calls that were fetching 15-minute data
Removed the complex multi-timeframe volume calculations that were likely causing performance issues
Simplified from [h_req, l_req, v_req] = request.security_lower_tf(...) to direct volume usage
3. Eliminated Historical Data Scanning
Removed the enableFullHistory and scanned_history logic
Deleted the complex historical lookback loop that was scanning hundreds of bars
This should significantly improve performance when backtesting over months/years
Simplified Architecture:
Volume Calculation
Old: Complex multi-timeframe volume distribution across grid segments
New: Simple volume formatting and direct volume[obLookback - 1] usage
Order Block Generation
Streamlined the block creation process
Removed age-based management and complex overlap detection
Simplified mitigation logic
Performance Optimizations
Window processing prevents excessive historical calculations
Removed timeframe complexity that was causing backtesting issues
Direct volume/price data usage instead of lower timeframe requests
Release Notes
Adjusted a few hardcoded inputs. Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Access more of our systems and insights at alphaextract.xyz
All analysis provided by Alpha Extract is for educational and informational purposes only.
All analysis provided by Alpha Extract is for educational and informational purposes only.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Access more of our systems and insights at alphaextract.xyz
All analysis provided by Alpha Extract is for educational and informational purposes only.
All analysis provided by Alpha Extract is for educational and informational purposes only.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.