Indicator · Pine Script v4 · On the chart

Order Block Finder

by theonetrade

This indicator identifies institutional Order Blocks on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code107
Settings6inputs
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

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

order_block_finder_rvHVaisA.pine
//@version=4
study("Order Block Finder", overlay = true)       
tip1 = "Indicator to help identify instituational Order Blocks (OB). OBs often signal the beginning of a strong move. There is a high probability that OB price levels will be revisited in the future and are interesting levels to place limit orders. Bullish Order block is the last down candle before a sequence of up candles. Bearish Order Block is the last up candle before a sequence of down candles."
tip2 = "!Experimental!\nFind Order Blocks from different timeframes. Channels prices are accurate, but arrow position is not. Most useful when selecting a timeframe higher than the chart."
tip3 = "Required number of subsequent candles in the same direction to identify Order Block"
tip4 = "Measured from from potential OB close to close of first candle in sequence"
dummy = input(true,"Hover over ( ! ) for documentation", tooltip = tip1)
colors    = input("LIGHT","Color Scheme", options=["DARK", "LIGHT"])
//res = input("","Order Block Timeframe",input.resolution,tooltip=tip2)
periods   = input(7,     "Relevant Periods to identify OB",tooltip=tip3)    // Required number of subsequent candles in the same direction to identify Order Block
threshold = input(0.0,   "Min. Percent move for valid OB", step = 0.1, tooltip=tip4)      // Required minimum % move (from potential OB close to last subsequent candle to identify Order Block)
bull_channels =  input(2, "Number of Bullish Channels to show")             // Num of channels
bear_channels = input(2, "Number of Bearish Channels to show")              // Num of channels


//Data Curation
res = ""
[copen,chigh,clow,cclose] = security(syminfo.tickerid,res,[open,high,low,close],barmerge.gaps_on, barmerge.lookahead_off)


ob_period = periods + 1                                                     // Identify location of relevant Order Block candle
absmove   = ((abs(cclose[ob_period] - cclose[1]))/cclose[ob_period]) * 100     // Calculate absolute percent move from potential OB to last candle of subsequent candles
relmove   = absmove >= threshold                                            // Identify "Relevant move" by comparing the absolute move to the threshold

// Color Scheme
bullcolor = colors == "DARK"? color.white : color.green
bearcolor = colors == "DARK"? color.blue : color.red

// Bullish Order Block Identification
bullishOB = cclose[ob_period] < copen[ob_period]                              // Determine potential Bullish OB candle (red candle)

int upcandles  = 0
for i = 1 to periods
    upcandles := upcandles + (cclose[i] > copen[i]? 1 : 0)                    // Determine color of subsequent candles (must all be green to identify a valid Bearish OB)

OB_bull      = bullishOB and (upcandles == (periods)) and relmove           // Identification logic (red OB candle & subsequent green candles)
OB_bull_chigh = OB_bull? chigh[ob_period] : na                                // Determine OB upper limit (Open or High depending on input)
OB_bull_clow  = OB_bull? clow[ob_period]  : na                                // Determine OB clower limit (Low)
OB_bull_avg  = (OB_bull_chigh + OB_bull_clow)/2                               // Determine OB middle line


// Bearish Order Block Identification
bearishOB = cclose[ob_period] > copen[ob_period]                              // Determine potential Bearish OB candle (green candle)

int downcandles  = 0
for i = 1 to periods
    downcandles := downcandles + (cclose[i] < copen[i]? 1 : 0)                // Determine color of subsequent candles (must all be red to identify a valid Bearish OB)

OB_bear      = bearishOB and (downcandles == (periods)) and relmove         // Identification logic (green OB candle & subsequent green candles)
OB_bear_chigh = OB_bear? chigh[ob_period] : na                                // Determine OB upper limit (High)
OB_bear_clow  = OB_bear? clow[ob_period] : na                                 // Determine OB clower limit (Open or Low depending on input)
OB_bear_avg  = (OB_bear_clow + OB_bear_chigh)/2                               // Determine OB middle line


// Plotting
plotshape(OB_bull, title="Bullish OB", style = shape.triangleup,   color = bullcolor, textcolor = bullcolor, size = size.tiny, location = location.belowbar, offset = -ob_period, text = "Bull")     // Bullish OB Indicator
bull1 = plot(OB_bull_chigh, title="Bullish OB High", style = plot.style_linebr, color = bullcolor, offset = -ob_period, linewidth = 2)                                               // Bullish OB Upper Limit
bull2 = plot(OB_bull_clow,  title="Bullish OB Low",  style = plot.style_linebr, color = bullcolor, offset = -ob_period, linewidth = 2)                                               // Bullish OB Lower Limit
fill(bull1, bull2, color=bullcolor, transp = 50, title = "Bullish OB fill")                                                                                                          // Fill Bullish OB
plotshape(OB_bull_avg, title="Bullish OB Average", style = shape.cross,   color = bullcolor, size = size.small, location = location.absolute, offset = -ob_period)                 // Bullish OB Average


plotshape(OB_bear, title="Bearish OB", style = shape.triangledown, color = bearcolor, textcolor = bearcolor,  size = size.tiny, location = location.abovebar, offset = -ob_period, text = "Bear")     // Bearish OB Indicator
bear1 = plot(OB_bear_clow,  title="Bearish OB Low",  style = plot.style_linebr, color = bearcolor, offset = -ob_period, linewidth = 2)                                                // Bearish OB Lower Limit
bear2 = plot(OB_bear_chigh, title="Bearish OB High", style = plot.style_linebr, color = bearcolor, offset = -ob_period, linewidth = 2)                                                // Bearish OB Upper Limit
fill(bear1, bear2, color=bearcolor, transp = 50, title = "Bearish OB fill")                                                                                                           // Fill Bearish OB
plotshape(OB_bear_avg, title="Bearish OB Average", style = shape.cross,   color = bearcolor, size = size.small, location = location.absolute, offset = -ob_period)                  // Bullish OB Average

var LineBullAvg = array.new_line()
var LineBullHigh = array.new_line()
var LineBullLow = array.new_line()
var LineBearAvg = array.new_line()
var LineBearHigh = array.new_line()
var LineBearLow = array.new_line()

sync = time_close(res)

if OB_bull and bull_channels>0
    if array.size(LineBullAvg) == bull_channels
        line.delete(array.get(LineBullAvg,0))
        array.remove(LineBullAvg,0)
        line.delete(array.get(LineBullHigh,0))
        array.remove(LineBullHigh,0)
        line.delete(array.get(LineBullLow,0))
        array.remove(LineBullLow,0)
    
    array.push(LineBullAvg,line.new(x1 = sync, xloc=xloc.bar_time, y1 = OB_bull_avg, x2 = sync[1], y2 = OB_bull_avg, extend = extend.left, color = bullcolor, style = line.style_solid, width = 1))
    array.push(LineBullHigh,line.new(x1 = sync, xloc=xloc.bar_time,y1 = OB_bull_chigh, x2 = sync[1], y2 = OB_bull_chigh, extend = extend.left, color = bullcolor, style = line.style_dashed, width = 1))
    array.push(LineBullLow,line.new(x1 = sync, xloc=xloc.bar_time, y1 = OB_bull_clow, x2 = sync[1], y2 = OB_bull_clow, extend = extend.left, color = bullcolor, style = line.style_dashed, width = 1))

if OB_bear and bear_channels>0
    if array.size(LineBearAvg) == bear_channels
        line.delete(array.get(LineBearAvg,0))
        array.remove(LineBearAvg,0)
        line.delete(array.get(LineBearHigh,0))
        array.remove(LineBearHigh,0)
        line.delete(array.get(LineBearLow,0))
        array.remove(LineBearLow,0)
    
    array.push(LineBearAvg,line.new(x1 = sync, xloc=xloc.bar_time, y1 = OB_bear_avg, x2 = sync[1], y2 = OB_bear_avg, extend = extend.left, color = bearcolor, style = line.style_solid, width = 1))
    array.push(LineBearHigh,line.new(x1 = sync, xloc=xloc.bar_time, y1 = OB_bear_chigh, x2 = sync[1], y2 = OB_bear_chigh, extend = extend.left, color = bearcolor, style = line.style_dashed, width = 1))
    array.push(LineBearLow,line.new(x1 = sync, xloc=xloc.bar_time, y1 = OB_bear_clow, x2 = sync[1], y2 = OB_bear_clow, extend = extend.left, color = bearcolor, style = line.style_dashed, width = 1))


// Alerts for Order Blocks Detection
alertcondition(OB_bull, title='New Bullish OB detected', message='New Bullish OB detected - This is NOT a BUY signal!')
alertcondition(OB_bear, title='New Bearish OB detected', message='New Bearish OB detected - This is NOT a SELL signal!')

Overview

A bullish Order Block forms at the close of the last down candle before a required sequence of up candles that meet the move threshold. A bearish Order Block forms at the close of the last up candle before a required sequence of down candles. The script draws horizontal lines at the Order Block open, high, low and average levels plus multiple bullish and bearish channel lines based on user inputs. Primary settings control the number of periods required for confirmation, the minimum percentage move threshold, color scheme, and channel counts. It operates on any selected timeframe using security to pull historical data with gaps and lookahead disabled.

Details

Published by

theonetrade on GitHub

Type

Indicator, Pine Script v4

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
Hover over ( ! ) for documentationbooltruedummy
Color SchemestringLIGHTcolors
Relevant Periods to identify OBint7periods
Min. Percent move for valid OBfloat0.0threshold
Number of Bullish Channels to showint2bull_channels
Number of Bearish Channels to showint2bear_channels
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

This Pine Script indicator identifies liquidity sweeps and confirms signals using a close-back candle pattern directly on the price chart. It tracks recent swing highs and lows over a customizable lookback period. A bullish signal forms when a prior bar sweeps

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 3 months ago · MPL-2.0 GitHub repository of Liquidity Sweep + Close-Back Confirmation
47 stars

This overlay indicator draws a set of higher-timeframe candles on the price chart. The user sets the timeframe or lets it select automatically, plus candle count, size, offset, margin, and whether the candles are standard or Heikin Ashi. A table can show the a

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 2 months ago · None stated GitHub repository of HTF Sweep Model with CISD Table

TheStrat Suite

by 345-strategies
30 stars

TheStrat Suite is a multi-timeframe price action indicator implementing Rob Smith's TheStrat methodology. It calculates bar classifications for inside bars, hammers, shooters, failed 2s and outside bars across configurable timeframes. The indicator detects sig

Indicator v6 SMC / ICT / price actionCandlestick patterns Repaints
Updated 2 weeks ago · MPL-2.0 GitHub repository of TheStrat Suite

ICT HTF Candles (fadi)

by dbruce1990
13 stars

ICT HTF Candles displays higher timeframe candle structures directly on the price chart using customized boxes and lines. It tracks up to six user-defined higher timeframes, plotting historical body, wick, and imbalance zones alongside optional price level tra

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · None stated GitHub repository of ICT HTF Candles (fadi)

Fractal Reclaim Strength

by selimgrsoy0-commits
12 stars

The indicator tracks four-bar fractal sweep and reclaim setups on chart timeframes of 15 minutes and above. It calculates Reclaim Strength based on where C2 closes relative to C1's range and plots level lines for the swept C1 extreme and C2 extreme. An on-scre

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · None stated GitHub repository of Fractal Reclaim Strength

This overlay indicator detects tweezer tops and bottoms and kangaroo-tail pin bars, then draws supply and demand zones from those patterns. It scores each zone, decays freshness, merges overlapping zones, and can invalidate a zone after a close-through or afte

Indicator v6 Candlestick patternsSupport & resistance
Updated 4 weeks ago · MIT GitHub repository of Tweezer & Kangaroo Zones [WavesUnchained]

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