Indicator · Pine Script v5 · On the chart

SMC Setup Order Blocks 07 TFlab

by alvinng214· code credited to TFlab

This Pine Script indicator detects Smart Money Concepts order blocks on the price chart using pivot highs and lows.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code341
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago5 Aug 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

341 lines of Pine Script v5 from SMC_SETUP/SMC Setup Order Blocks 07 TFlab.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

SMC Setup Order Blocks 07 TFlab.txt
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TFlab

//@version=5
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © chartbox90

//@version=5
indicator("Smart Money Setup 07 [TradingFinder] Liquidity Hunts & Minor OB" , "SMC Setup Order Blocks 07 TFlab" , overlay = true  , max_bars_back = 5000 , max_boxes_count = 500 , max_labels_count = 500 , max_lines_count = 500)

//import Libraries
    //import Order Block Refiner
import TFlab/OrderBlockRefiner_TradingFinder/2 as Refiner
    //import Order Block Drawing  Library
import TFlab/OrderBlockDrawing_TradingFinder/4 as Drawing
    //import Order Block Overlapping
import TFlab/AlertSenderLibrary_TradingFinder/1 as Alert
 

//Input
PP = input.int(2 , "Pivot Period", minval = 2)
OBVaP = input.int(500, 'Order Block Validity Period (Bar)' , group = 'Global Setting' , maxval = 4998 , minval = 10,
 tooltip = 'You can set the validity period of each Order Block based on the number of candles that have passed since the origin of the Order Block.')
MLOB = input.string('Proximal' , 'Mitigation Level OB', ['Proximal', '50 % OB', 'Distal'] )

Refine= input.bool(true, 'Order Block Refine.', 
 'If you want this "Supply Main Order Block, ChoCh Origin" to be refined to display a optimal range,' +
 'you should select "On" and if you want to see the original' +
 'range of the block order, you should select "Off".' + 
 '\nAlso, if you are a risk taker, you can choose the "Aggressive" Refine method,' + 
 'and if you are risk averse, you can choose the "Defensive" Refine method.' 
 , group ='Order Blocks Refinement ', inline = 'Refine')

RefineMe = input.string('Defensive', '', ['Defensive', 'Aggressive'] , 
 group = 'Order Blocks Refinement ', inline = 'Refine')

//Calculation
ATR =ta.atr(50)
Open = open
High = high
Low = low
Close = close 
Bar_Index = bar_index


var ArrayType = array.new_string()
var ArrayValue = array.new_float()
var ArrayIndex =  array.new_int()
var Line = array.new_line()

HighPivot = ta.pivothigh(PP,PP)
LowPivot = ta.pivotlow(PP,PP)

HighValue = ta.valuewhen(HighPivot ,high[PP], 0)
LowValue = ta.valuewhen(LowPivot ,low[PP], 0)

HighIndex = ta.valuewhen(HighPivot ,bar_index[PP], 0)
LowIndex = ta.valuewhen(LowPivot ,bar_index[PP], 0)


Correct_HighPivot = 0.0
Correct_LowPivot =  0.0


PASS = 0

if HighPivot  and  LowPivot
    if ArrayType.size() == 0
        PASS := 1
    else if ArrayType.size() >= 1
        if ((ArrayType.get(ArrayType.size() - 1)) == "L" or
             (ArrayType.get(ArrayType.size() - 1)) == "LL")
            if LowPivot < ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue
            else 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
            Correct_HighPivot := HighValue  
        else if (ArrayType.get(ArrayType.size() - 1)) == "H" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HH"
            if HighPivot > ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue  
            else 
                array.push(ArrayType,ArrayType.size()>2?  ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
            Correct_LowPivot :=  LowValue    
        else if (ArrayType.get(ArrayType.size() - 1)) == "LH"
            if HighPivot < ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2?  ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue 
            else if HighPivot > ArrayValue.get(ArrayType.size() - 1)
                if close < ArrayValue.get(ArrayType.size() - 1)
                    array.remove(ArrayType,ArrayType.size() - 1)
                    array.remove(ArrayValue,ArrayValue.size() - 1)
                    array.remove(ArrayIndex,ArrayIndex.size() - 1)
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                    array.push(ArrayValue, HighValue)
                    array.push(ArrayIndex, HighIndex)
                    Correct_HighPivot := HighValue  
                else if close > ArrayValue.get(ArrayType.size() - 1)
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                    array.push(ArrayValue, LowValue)
                    array.push(ArrayIndex, LowIndex)
                    Correct_LowPivot :=  LowValue
        else if (ArrayType.get(ArrayType.size() - 1)) == "HL"
            if LowPivot > ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue                       
            else if LowPivot < ArrayValue.get(ArrayType.size() - 1)
                if close > ArrayValue.get(ArrayType.size() - 1)
                    array.remove(ArrayType,ArrayType.size() - 1)
                    array.remove(ArrayValue,ArrayValue.size() - 1)
                    array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                    array.push(ArrayValue, LowValue)
                    array.push(ArrayIndex, LowIndex)
                    Correct_LowPivot :=  LowValue
                else if close < ArrayValue.get(ArrayType.size() - 1)
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                    array.push(ArrayValue, HighValue)
                    array.push(ArrayIndex, HighIndex)
                    Correct_HighPivot := HighValue                         
else if  HighPivot 
    if ArrayType.size() == 0
        array.insert(ArrayType, 0, "H")
        array.insert(ArrayValue, 0, HighValue)
        array.insert(ArrayIndex, 0, HighIndex)
        Correct_HighPivot := HighValue
    else if ArrayType.size() >= 1
        if ((ArrayType.get(ArrayType.size() - 1)) == "L" or
             (ArrayType.get(ArrayType.size() - 1)) == "HL" or
             (ArrayType.get(ArrayType.size() - 1)) == "LL")
            if HighPivot > ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue
            else if  HighPivot < ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue                         
        else if (ArrayType.get(ArrayType.size() - 1)) == "H" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HH" or 
             (ArrayType.get(ArrayType.size() - 1)) == "LH"
            if (ArrayValue.get(ArrayValue.size() - 1)) < HighValue
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue               
else if LowPivot 
    if ArrayType.size() == 0
        array.insert(ArrayType, 0, "L")
        array.insert(ArrayValue, 0, LowValue)
        array.insert(ArrayIndex, 0, LowIndex)
        Correct_LowPivot :=  LowValue
    else if ArrayType.size() >= 1
        if (ArrayType.get(ArrayType.size() - 1)) == "H" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HH" or 
             (ArrayType.get(ArrayType.size() - 1)) == "LH"
            if LowPivot < ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2?  ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue
            else if LowPivot > ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue                        
        else if (ArrayType.get(ArrayType.size() - 1)) == "L" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HL" or 
             (ArrayType.get(ArrayType.size() - 1)) == "LL"
            if (ArrayValue.get(ArrayValue.size() - 1)) > LowValue
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue


var string TypePoint0 = ''
var string TypePoint1 = ''
var string TypePoint2 = ''
var string TypePoint3 = ''
var string TypePoint4 = ''
var string TypePoint5 = ''
var string TypePoint6 = ''
var string TypePoint7 = ''

var float PricePoint0 = 0.0
var float PricePoint1 = 0.0
var float PricePoint2 = 0.0
var float PricePoint3 = 0.0
var float PricePoint4 = 0.0
var float PricePoint5 = 0.0
var float PricePoint6 = 0.0
var float PricePoint7 = 0.0

var int IndexPoint0 = 0 
var int IndexPoint1 = 0 
var int IndexPoint2 = 0 
var int IndexPoint3 = 0 
var int IndexPoint4 = 0 
var int IndexPoint5 = 0 
var int IndexPoint6 = 0 
var int IndexPoint7 = 0 


if ArrayType.size() > 8
    TypePoint0 := ArrayType.get(ArrayType.size() - 1)
    TypePoint1 := ArrayType.get(ArrayType.size() - 2)
    TypePoint2 := ArrayType.get(ArrayType.size() - 3)
    TypePoint3 := ArrayType.get(ArrayType.size() - 4)
    TypePoint4 := ArrayType.get(ArrayType.size() - 5)
    TypePoint5 := ArrayType.get(ArrayType.size() - 6)
    TypePoint6 := ArrayType.get(ArrayType.size() - 7)
    TypePoint7 := ArrayType.get(ArrayType.size() - 8)

    PricePoint0 := ArrayValue.get(ArrayType.size() - 1)
    PricePoint1 := ArrayValue.get(ArrayType.size() - 2)
    PricePoint2 := ArrayValue.get(ArrayType.size() - 3)
    PricePoint3 := ArrayValue.get(ArrayType.size() - 4)
    PricePoint4 := ArrayValue.get(ArrayType.size() - 5)
    PricePoint5 := ArrayValue.get(ArrayType.size() - 6)
    PricePoint6 := ArrayValue.get(ArrayType.size() - 7)
    PricePoint7 := ArrayValue.get(ArrayType.size() - 8)

    IndexPoint0 := ArrayIndex.get(ArrayType.size() - 1) 
    IndexPoint1 := ArrayIndex.get(ArrayType.size() - 2)
    IndexPoint2 := ArrayIndex.get(ArrayType.size() - 3) 
    IndexPoint3 := ArrayIndex.get(ArrayType.size() - 4) 
    IndexPoint4 := ArrayIndex.get(ArrayType.size() - 5) 
    IndexPoint5 := ArrayIndex.get(ArrayType.size() - 6) 
    IndexPoint6 := ArrayIndex.get(ArrayType.size() - 7) 
    IndexPoint7 := ArrayIndex.get(ArrayType.size() - 8) 

bool BearSetup07 = false
bool BullSetup07 = false
//Box Data
    //Bearish SetUp
var int BeOBI = 0
    //Bullish SetUp
var int BuOBI = 0

//Bearish Logic
if TypePoint0 == 'LL' and 
 TypePoint1 == 'LH' and
 TypePoint2 == 'HL' and
 TypePoint3 == 'LH' and
 TypePoint4 == 'LL' and
 TypePoint5 == 'LH' and
 TypePoint6 == 'LL' and
 PricePoint0 > PricePoint4 and 
 IndexPoint0 == bar_index - PP
    BearSetup07 := true
    BeOBI := IndexPoint5
else  
    BearSetup07 := false

//Bullish Logic
if TypePoint0 == 'HH' and 
 TypePoint1 == 'HL' and
 TypePoint2 == 'LH' and
 TypePoint3 == 'HL' and
 TypePoint4 == 'HH' and
 TypePoint5 == 'HL' and
 TypePoint6 == 'HH' and
 PricePoint0 < PricePoint4 and
 IndexPoint0 == bar_index - PP
    BullSetup07 := true
    BuOBI := IndexPoint5
else  
    BullSetup07 := false



plotshape(BearSetup07  , 
 "Bear Setup07" , 
 style = shape.arrowup ,
 location = location.belowbar ,
 color = color.rgb(179, 2, 2) , 
 offset = -PP , 
 text = "Bear Setup07", 
 textcolor = color.rgb(179, 2, 22) )

plotshape(BullSetup07  , 
 "Bull Setup07" , 
 style = shape.arrowdown ,
 location = location.abovebar ,
 color = color.rgb(47, 156, 38) , 
 offset = -PP , 
 text = "Bull Setup07", 
 textcolor = color.rgb(47, 156, 38) )


////////////////////////////////////////////////////
///////////////Order Block Refinement///////////////
////////////////////////////////////////////////////

[Bu_Xd1, Bu_Xd2, Bu_Yd12, Bu_Xp1, Bu_Xp2, Bu_Yp12] = 
 Refiner.OBRefiner('Demand', Refine ? 'On' : 'Off', RefineMe,BullSetup07 , BuOBI) 

[Be_Xd1, Be_Xd2, Be_Yd12, Be_Xp1, Be_Xp2, Be_Yp12] = 
 Refiner.OBRefiner('Supply', Refine ? 'On' : 'Off', RefineMe ,BearSetup07 , BeOBI) 

////////////////////////////////////////////////////
////////////////////////Drawing/////////////////////
////////////////////////////////////////////////////

[Alert_DAMM, Alert_SAMMbb, PASBB, DASBB, IASBB] = Drawing.OBDrawing('Demand', BullSetup07 ,Bu_Yd12 ,Bu_Yp12 ,Bu_Xd1 ,true , OBVaP   ,MLOB ,MLOB , true ,false ,true, false, #2d9b3167, na) 
[Alert_SMMM, Alert_DMMMbb, PMDBB, DMDBB, IMDBB] = Drawing.OBDrawing('Supply', BearSetup07 ,Be_Yd12 ,Be_Yp12 ,Be_Xd1 ,true , OBVaP   ,MLOB ,MLOB , true ,false ,true, false, #ff525254  , na)

Overview

SMC Setup Order Blocks 07 TFlab builds supply and demand zones based on configurable pivot periods and order block validity periods. The script offers refinement options to optimize block ranges with defensive or aggressive methods as well as mitigation levels for proximal, fifty percent, or distal targets. It highlights liquidity hunts and minor order blocks while drawing all elements directly on the chart for technical analysis.

Details

Published by

alvinng214 on GitHub

Code credit

TFlab, as written in the script's header

Type

Indicator, Pine Script v5

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.

Settings

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

SettingTypeDefaultVariable
Pivot Periodint2PP
Order Block Validity Period (Bar)int500OBVaP
Mitigation Level OBstringProximalMLOB
Order Block Refine.booltrueRefine
RefineMestringDefensiveRefineMe
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