Indicator · Pine Script v6 · On the chart

Institutional Order Flow Strength Classifier [LuxAlgo]

by MeridianAlgo· code credited to LuxAlgo

The Institutional Order Flow Strength Classifier identifies bullish and bearish order blocks triggered by market structure breaks confirmed through pivot highs and lows.

View on GitHub

GitHub stars9on the repository
Pine versionv6current
Lines of code211
Settings8inputs
LicenceMIT
Last update4 months ago29 Jun 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

211 lines of Pine Script v6 from examples/Institutional_Order_Flow_Strength_Classifier_LuxAlgo.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Institutional_Order_Flow_Strength_Classifier_LuxAlgo.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=6
indicator("Institutional Order Flow Strength Classifier [LuxAlgo]", "LuxAlgo - Institutional Order Flow Strength Classifier", overlay = true, max_boxes_count = 100, max_labels_count = 100)

//---------------------------------------------------------------------------------------------------------------------}
// Constants & Inputs
//---------------------------------------------------------------------------------------------------------------------{
color BULL_COLOR = #089981
color BEAR_COLOR = #f23645
color TEXT_COLOR = chart.fg_color

string OB_GROUP   = "Order Block Settings"
int pivotLenInput = input.int(5, "Pivot Lookback", minval = 2, group = OB_GROUP)
int maxOBsInput   = input.int(5, "Max Unmitigated OBs", minval = 1, maxval = 50, group = OB_GROUP)

string VIS_GROUP   = "Visualization"
color bullColorInput = input.color(color.new(BULL_COLOR, 80), "Bullish OB Color", group = VIS_GROUP)
color bearColorInput = input.color(color.new(BEAR_COLOR, 80), "Bearish OB Color", group = VIS_GROUP)
bool hideOverlappedInput = input.bool(true, "Hide Overlapped Zones", group = VIS_GROUP)
bool showLabelsInput = input.bool(true, "Show Strength Labels", group = VIS_GROUP)
bool showStrongestInput = input.bool(true, "Show Strongest OB Plot", group = VIS_GROUP)
int bufferSizeInput = input.int(5, "Strongest OB Buffer Size", minval = 1, maxval = 100, group = VIS_GROUP)

//---------------------------------------------------------------------------------------------------------------------}
// Types & Methods
//---------------------------------------------------------------------------------------------------------------------{
type OrderBlock
    float top
    float bottom
    int   startTime
    float strength
    bool  isBullish
    box   boxId
    label labelId
    bool  mitigated

//---------------------------------------------------------------------------------------------------------------------}
// Functions
//---------------------------------------------------------------------------------------------------------------------{
// Calculate OB Strength using displacement and volume factors
calculateStrength(float obRange, float breakoutDist, float relVol) =>
    float dispFactor = math.min(breakoutDist / (obRange * 5), 1.0)
    float volFactor = math.min(relVol / 2.0, 1.0)
    float score = (dispFactor * 0.6 + volFactor * 0.4) * 100
    math.round(score, 1)

//---------------------------------------------------------------------------------------------------------------------}
// Main Logic
//---------------------------------------------------------------------------------------------------------------------{
var obArray = array.new<OrderBlock>()
float volSMA = ta.sma(volume, 20)

// Pivot Detection
float hi = ta.pivothigh(pivotLenInput, pivotLenInput)
float lo = ta.pivotlow(pivotLenInput, pivotLenInput)

var float lastHi = na
var float lastLo = na
var int lastHiIdx = na
var int lastLoIdx = na

if not na(hi)
    lastHi := hi
    lastHiIdx := bar_index - pivotLenInput
if not na(lo)
    lastLo := lo
    lastLoIdx := bar_index - pivotLenInput

// Market Structure Break (BOS) detection
bool bullBOS = ta.crossover(close, lastHi)
bool bearBOS = ta.crossunder(close, lastLo)

if bullBOS or bearBOS
    int searchLen = bar_index - (bullBOS ? lastHiIdx : lastLoIdx)
    float obTop = na
    float obBtm = na
    int obIdx = na
    float obVol = na
    
    if bullBOS
        float minLow = na
        for i = 1 to searchLen
            if close[i] < open[i]
                if na(minLow) or low[i] < minLow
                    minLow := low[i]
                    obTop := high[i]
                    obBtm := low[i]
                    obIdx := i
                    obVol := volume[i]
        lastHi := na 
    else
        float maxHigh = na
        for i = 1 to searchLen
            if close[i] > open[i]
                if na(maxHigh) or high[i] > maxHigh
                    maxHigh := high[i]
                    obTop := high[i]
                    obBtm := low[i]
                    obIdx := i
                    obVol := volume[i]
        lastLo := na
        
    if not na(obIdx)
        float obHeight = obTop - obBtm
        float breakoutDist = bullBOS ? (close - obTop) : (obBtm - close)
        float avgVol = volSMA[obIdx]
        float strength = calculateStrength(obHeight, breakoutDist, obVol / avgVol)
        
        OrderBlock newOB = OrderBlock.new(obTop, obBtm, time[obIdx], strength, bullBOS, na, na, false)
        array.unshift(obArray, newOB)

//---------------------------------------------------------------------------------------------------------------------}
// Mitigation, Strongest Tracking & Array Management
//---------------------------------------------------------------------------------------------------------------------{
// 1. Mitigation Check (Every Bar)
if array.size(obArray) > 0
    for i = 0 to array.size(obArray) - 1
        OrderBlock ob = array.get(obArray, i)
        if not ob.mitigated
            bool isMitigated = ob.isBullish ? low < ob.bottom : high > ob.top
            if isMitigated
                ob.mitigated := true

// 2. Strongest OB tracking within buffer
float strongestTop = na
float strongestBottom = na
float strongestAvgPrice = na
bool  strongestIsBullish = false
float maxStrength = -1.0

if array.size(obArray) > 0
    int checkedCount = 0
    for i = 0 to array.size(obArray) - 1
        OrderBlock ob = array.get(obArray, i)
        if not ob.mitigated
            if ob.strength > maxStrength
                maxStrength := ob.strength
                strongestTop := ob.top
                strongestBottom := ob.bottom
                strongestAvgPrice := (ob.top + ob.bottom) / 2
                strongestIsBullish := ob.isBullish
            
            checkedCount += 1
            if checkedCount >= bufferSizeInput
                break

// Plot strongest OB zone with directional color and clear cut on change
color plotCol = na(strongestAvgPrice) ? na : (strongestIsBullish ? bullColorInput : bearColorInput)
bool  hasChanged = strongestAvgPrice != strongestAvgPrice[1]

plotTop = plot(showStrongestInput ? strongestTop : na, "Strongest OB Top", color = hasChanged ? na : color.new(plotCol, 70))
plotBtm = plot(showStrongestInput ? strongestBottom : na, "Strongest OB Bottom", color = hasChanged ? na : color.new(plotCol, 70))
fill(plotTop, plotBtm, hasChanged ? na : color.new(plotCol, 90), "Strongest OB Zone Fill")

plot(showStrongestInput ? strongestAvgPrice : na, "Strongest OB Median", color = hasChanged ? na : color.new(plotCol, 40), linewidth = 2)

//---------------------------------------------------------------------------------------------------------------------}
// 3. Visual Management (Last Bar)
if barstate.islast
    int activeCount = 0
    var occupiedTops = array.new_float(0)
    var occupiedBtms = array.new_float(0)
    array.clear(occupiedTops)
    array.clear(occupiedBtms)
    
    if array.size(obArray) > 0
        for i = 0 to array.size(obArray) - 1
            OrderBlock ob = array.get(obArray, i)
            
            bool isOverlapped = false
            if not ob.mitigated and hideOverlappedInput and array.size(occupiedTops) > 0
                for j = 0 to array.size(occupiedTops) - 1
                    float otherTop = array.get(occupiedTops, j)
                    float otherBtm = array.get(occupiedBtms, j)
                    if (ob.top <= otherTop and ob.top >= otherBtm) or (ob.bottom <= otherTop and ob.bottom >= otherBtm) or (ob.top >= otherTop and ob.bottom <= otherBtm)
                        isOverlapped := true
                        break

            if not ob.mitigated and not isOverlapped and activeCount < maxOBsInput
                activeCount += 1
                array.push(occupiedTops, ob.top)
                array.push(occupiedBtms, ob.bottom)
                
                color obCol = ob.isBullish ? bullColorInput : bearColorInput
                color labelCol = ob.isBullish ? BULL_COLOR : BEAR_COLOR

                if na(ob.boxId)
                    ob.boxId := box.new(ob.startTime, ob.top, time, ob.bottom, bgcolor = obCol, border_color = obCol, border_style = line.style_dashed, xloc = xloc.bar_time)
                
                if showLabelsInput
                    if na(ob.labelId)
                        ob.labelId := label.new(time, (ob.top + ob.bottom) / 2, text = str.format("{0}%", ob.strength), style = label.style_label_left, textcolor = labelCol, color = #00000000, size = size.small, textalign = text.align_center, xloc = xloc.bar_time)
            else
                if not na(ob.boxId)
                    box.delete(ob.boxId)
                    ob.boxId := na
                if not na(ob.labelId)
                    label.delete(ob.labelId)
                    ob.labelId := na

// 4. Memory management (Every bar)
if array.size(obArray) > 100
    for i = array.size(obArray) - 1 to 0
        OrderBlock ob = array.get(obArray, i)
        if ob.mitigated and array.size(obArray) > 50
            array.remove(obArray, i)
        else if array.size(obArray) > 100
            array.pop(obArray)

//---------------------------------------------------------------------------------------------------------------------}

Overview

Institutional Order Flow Strength Classifier [LuxAlgo] calculates a strength score for each order block based on price displacement and relative volume. The script renders unmitigated order block zones directly on the price chart using boxes and strength percentage labels, with options to track the strongest active zone. Users can customize pivot lookback lengths, max order block capacity, and visual settings.

Details

Published by

MeridianAlgo on GitHub

Code credit

LuxAlgo, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

SMC / ICT / price action, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

code-converterconverterjavascriptpinescripttranspilercode-reviewmeridianalgocode-conversionpinescript-algorithms

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Pivot Lookbackint5pivotLenInput
Max Unmitigated OBsint5maxOBsInput
Bullish OB Colorcolorcolor.new(BULL_COLOR, 80)bullColorInput
Bearish OB Colorcolorcolor.new(BEAR_COLOR, 80)bearColorInput
Hide Overlapped ZonesbooltruehideOverlappedInput
Show Strength LabelsbooltrueshowLabelsInput
Show Strongest OB PlotbooltrueshowStrongestInput
Strongest OB Buffer Sizeint5bufferSizeInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows

DE-tracker

by Allen1212
303 stars

This indicator plots labels on the TradingView price chart to mark ARK Invest's buy and sell trades for the DE stock. Buy transactions appear in green with X1 or X2 multipliers showing the number of ARK ETFs involved on the same day; sells appear in red. The m

Indicator v4 Support & resistanceSMC / ICT / price action
Updated 2 years ago · None stated GitHub repository of DE-tracker

This Pine Script indicator plots a ZigZag on the price chart. It identifies reversal points when price moves more than a set percentage from the last pivot. The script calculates forecasts using zigzag data and labels detected geometric patterns including harm

Indicator v4 TrendSupport & resistance

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

Open Source Fractal

by cantolab
183 stars

This indicator implements the Fractal Model concept to plot market structure shifts, liquidity sweeps, and Change in State of Delivery (CISD) levels. It overlays custom higher-timeframe candle previews, open prices, and time markers directly on the price chart

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MIT GitHub repository of Open Source Fractal

Swing Failure Signals

by Ganador1
154 stars

This indicator calculates pivot highs and pivot lows to detect liquidity sweeps and Swing Failure Patterns. It identifies when price breaks past recent key swing highs or lows within a configurable historical window, then looks for a quick reversal or change i

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · Apache-2.0 GitHub repository of Swing Failure Signals

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers