Indicator · Pine Script v5 · On the chart

Order Block Detector [LuxAlgo]

by theonetrade· code credited to LuxAlgo

This indicator identifies and plots bullish and bearish order blocks directly on the price chart using volume pivot detection.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code233
Settings12inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

233 lines of Pine Script v5 from assets/indicator/bit-exact/order_block_detector_luxalgo_KvGhxGxY.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

order_block_detector_luxalgo_KvGhxGxY.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=5
indicator("Order Block Detector [LuxAlgo]"
  , overlay = true
  , max_boxes_count = 500
  , max_labels_count = 500
  , max_lines_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(5, 'Volume Pivot Length'
  , minval = 1)

bull_ext_last = input.int(3, 'Bullish OB '
  , minval = 1
  , inline = 'bull')

bg_bull_css = input.color(color.new(#169400, 80), ''
  , inline = 'bull')

bull_css = input.color(#169400, ''
  , inline = 'bull')

bull_avg_css = input.color(color.new(#9598a1, 37), ''
  , inline = 'bull')

bear_ext_last = input.int(3, 'Bearish OB'
  , minval = 1
  , inline = 'bear')

bg_bear_css = input.color(color.new(#ff1100, 80), ''
  , inline = 'bear')

bear_css = input.color(#ff1100, ''
  , inline = 'bear')

bear_avg_css = input.color(color.new(#9598a1, 37), ''
  , inline = 'bear')

line_style = input.string('⎯⎯⎯', 'Average Line Style'
  , options = ['⎯⎯⎯', '----', '····'])

line_width = input.int(1, 'Average Line Width'
  , minval = 1)

mitigation = input.string('Wick', 'Mitigation Methods'
  , options = ['Wick', 'Close'])

//-----------------------------------------------------------------------------}
//Functions 
//-----------------------------------------------------------------------------{
//Line Style function
get_line_style(style) =>
    out = switch style
        '⎯⎯⎯'  => line.style_solid
        '----' => line.style_dashed
        '····' => line.style_dotted

//Function to get order block coordinates
get_coordinates(condition, top, btm, ob_val)=>
    var ob_top  = array.new_float(0)
    var ob_btm  = array.new_float(0)
    var ob_avg  = array.new_float(0)
    var ob_left = array.new_int(0)

    float ob = na

    //Append coordinates to arrays
    if condition
        avg = math.avg(top, btm)
        
        array.unshift(ob_top, top)
        array.unshift(ob_btm, btm)
        array.unshift(ob_avg, avg)
        array.unshift(ob_left, time[length])
        
        ob := ob_val
    
    [ob_top, ob_btm, ob_avg, ob_left, ob]

//Function to remove mitigated order blocks from coordinate arrays
remove_mitigated(ob_top, ob_btm, ob_left, ob_avg, target, bull)=>
    mitigated = false
    target_array = bull ? ob_btm : ob_top

    for element in target_array
        idx = array.indexof(target_array, element)

        if (bull ? target < element : target > element)
            mitigated := true

            array.remove(ob_top, idx)
            array.remove(ob_btm, idx)
            array.remove(ob_avg, idx)
            array.remove(ob_left, idx)
    
    mitigated

//Function to set order blocks
set_order_blocks(ob_top, ob_btm, ob_left, ob_avg, ext_last, bg_css, border_css, lvl_css)=>
    var ob_box = array.new_box(0)
    var ob_lvl = array.new_line(0)

    //Fill arrays with boxes/lines
    if barstate.isfirst
        for i = 0 to ext_last-1
            array.unshift(ob_box, box.new(na,na,na,na
              , xloc = xloc.bar_time
              , extend= extend.right
              , bgcolor = bg_css
              , border_color = color.new(border_css, 70)))

            array.unshift(ob_lvl, line.new(na,na,na,na
              , xloc = xloc.bar_time
              , extend = extend.right
              , color = lvl_css
              , style = get_line_style(line_style)
              , width = line_width))

    //Set order blocks
    if barstate.islast
        if array.size(ob_top) > 0
            for i = 0 to math.min(ext_last-1, array.size(ob_top)-1)
                get_box = array.get(ob_box, i)
                get_lvl = array.get(ob_lvl, i)

                box.set_lefttop(get_box, array.get(ob_left, i), array.get(ob_top, i))
                box.set_rightbottom(get_box, array.get(ob_left, i), array.get(ob_btm, i))

                line.set_xy1(get_lvl, array.get(ob_left, i), array.get(ob_avg, i))
                line.set_xy2(get_lvl, array.get(ob_left, i)+1, array.get(ob_avg, i))


//-----------------------------------------------------------------------------}
//Global elements 
//-----------------------------------------------------------------------------{
var os = 0
var target_bull = 0.
var target_bear = 0.

n = bar_index
upper = ta.highest(length)
lower = ta.lowest(length)

if mitigation == 'Close'
    target_bull := ta.lowest(close, length)
    target_bear := ta.highest(close, length)
else
    target_bull := lower
    target_bear := upper

os := high[length] > upper ? 0 : low[length] < lower ? 1 : os[1]

phv = ta.pivothigh(volume, length, length)

//-----------------------------------------------------------------------------}
//Get bullish/bearish order blocks coordinates 
//-----------------------------------------------------------------------------{
[bull_top
  , bull_btm
  , bull_avg
  , bull_left
  , bull_ob] = get_coordinates(phv and os == 1, hl2[length], low[length], low[length])

[bear_top
  , bear_btm
  , bear_avg
  , bear_left
  , bear_ob] = get_coordinates(phv and os == 0, high[length], hl2[length], high[length])

//-----------------------------------------------------------------------------}
//Remove mitigated order blocks
//-----------------------------------------------------------------------------{
mitigated_bull = remove_mitigated(bull_top
  , bull_btm
  , bull_left
  , bull_avg
  , target_bull
  , true)

mitigated_bear = remove_mitigated(bear_top
  , bear_btm
  , bear_left
  , bear_avg
  , target_bear
  , false)

//-----------------------------------------------------------------------------}
//Display order blocks
//-----------------------------------------------------------------------------{
//Set bullish order blocks
set_order_blocks(bull_top
  , bull_btm
  , bull_left
  , bull_avg
  , bull_ext_last
  , bg_bull_css
  , bull_css
  , bull_avg_css)

//Set bearish order blocks
set_order_blocks(bear_top
  , bear_btm
  , bear_left
  , bear_avg
  , bear_ext_last
  , bg_bear_css
  , bear_css
  , bear_avg_css)
        
//Show detected order blocks
plot(bull_ob, 'Bull OB', bull_css, 2, plot.style_linebr
  , offset = -length
  , display = display.none)

plot(bear_ob, 'Bear OB', bear_css, 2, plot.style_linebr
  , offset = -length
  , display = display.none)

//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
alertcondition(bull_ob, 'Bullish OB Formed', 'Bullish order block detected')

alertcondition(bear_ob, 'Bearish OB Formed', 'bearish order block detected')

alertcondition(mitigated_bull, 'Bullish OB Mitigated', 'Bullish order block mitigated')

alertcondition(mitigated_bear, 'Bearish OB Mitigated', 'bearish order block mitigated')

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

Overview

Order Block Detector [LuxAlgo] draws rectangular zones extending to the right alongside midpoint average lines for active order blocks, and automatically removes blocks once price mitigates them. Main settings let users adjust the volume pivot lookback length, the maximum number of recent bullish and bearish order blocks displayed, whether mitigation is triggered by candle wicks or closes, and zone colors and line styles. Because it relies on pivot detection with a lookback offset, order block identification lags by the pivot length.

Details

Published by

theonetrade on GitHub

Code credit

LuxAlgo, as written in the script's header

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Volume Pivot Lengthint5length
Bullish OB int3bull_ext_last
bg_bull_csscolorcolor.new(#169400, 80)bg_bull_css
bull_csscolor#169400bull_css
bull_avg_csscolorcolor.new(#9598a1, 37)bull_avg_css
Bearish OBint3bear_ext_last
bg_bear_csscolorcolor.new(#ff1100, 80)bg_bear_css
bear_csscolor#ff1100bear_css
bear_avg_csscolorcolor.new(#9598a1, 37)bear_avg_css
Average Line Stylestring⎯⎯⎯line_style
Average Line Widthint1line_width
Mitigation MethodsstringWickmitigation
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

Moon Dev GEX Sweep & CVD

by moondevonyt
98 stars

The indicator detects liquidity sweeps across key price levels and calculates a cumulative volume delta proxy. It uses pivot high and low lookbacks to identify swing points, marking sweeps when price breaks beyond a level and quickly closes back inside. Featur

Indicator v5 Support & resistanceSMC / ICT / price action
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Sweep & CVD

Order Flow Strategy (OFS)

by roan-maverick
69 stars

The Order Flow Strategy is a chart overlay indicator based on auction market theory and order flow concepts. It evaluates higher-timeframe value structure across custom timeframes alongside value area profiles (VAH, POC, VAL) and Fibonacci discount or premium

Indicator v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 10 days ago · Custom licence GitHub repository of Order Flow Strategy (OFS)

Calculates higher-timeframe volume profiles to identify Value Area High (VAH), Value Area Low (VAL), and Point of Control (POC) levels directly on the price chart. It flags potential reversal setups and Change in State of Delivery (CISD) patterns relative to v

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of CandelaCharts - Value Area Reversals

Copilot

by milocaetano
48 stars

Copilot is an order flow range-reversal indicator designed to overlay trading setups directly on the price chart. It evaluates four criteria: market context (sideways vs trending regime based on ATR height), structure (double top or double bottom retests), abs

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 4 weeks ago · MIT GitHub repository of Copilot

Supply and Demand Visible Range identifies supply, demand, and equilibrium zones across the visible chart range. It accumulates high, low, and volume data starting from the leftmost visible bar, optionally requesting lower timeframe intrabar data for finer res

Indicator v5 Support & resistanceVolume Repaints
Updated 3 months ago · AGPL-3.0 GitHub repository of Supply and Demand Visible Range [LuxAlgo]
13 stars

This script identifies and visualizes bullish and bearish order blocks on the price chart. It detects low-volatility consolidation ranges followed by breakout moves accompanied by high trading volume. Users can select between Simple, Relative, or Weighted volu

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 6 months ago · MIT GitHub repository of Advanced Order Blocks with Volume

More SMC / ICT scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers