Library · Pine Script v5 · Library

OrderBlockDrawing_TradingFinder

by alvinng214· code credited to TFlab

This library plots order blocks directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code179
Settings0inputs
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 library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

179 lines of Pine Script v5 from ICT Balanced Price Range [TradingFinder] BPR FVG + IFVG/TFlabOrderBlockDrawing_TradingFinder4.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

TFlabOrderBlockDrawing_TradingFinder4.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

library('OrderBlockDrawing_TradingFinder', overlay = true)


export OBDrawing(string OBType, bool TriggerCondition ,float distalPrice, float proximalPrice, int  Index, bool OBValidGlobal, int OBValidDis, string MitigationLvL, string MitigationLvL_BB ,bool ShowAll,bool ShowAll_BB,bool Show,bool Show_BB,color ColorZone,color ColorZone_BB) =>

    var string oBType = OBType
    var bool show = Show
    var color colorZone = ColorZone
    var float DistalPrice = 0.0
    var float ProximalPrice = 0.0
    var bool Check = true
    var int Counter = 1
    var line Distal = na
    var line Proximal = na
    var line Line50per = na
    var linefill fillline = na
    var bool MitigationAlert = false

    var bool show_BB = Show_BB
    var color colorZone_BB = ColorZone_BB
    var bool TriggerCondition_BB = false 
    var float DistalPrice_BB = 0.0
    var float ProximalPrice_BB = 0.0
    var int Index_BB = 0
    var bool Check_BB = true
    var int Counter_BB = 1
    var line Distal_BB = na
    var line Proximal_BB = na
    var line Line50per_BB = na
    var linefill fillline_BB = na
    var bool MitigationAlert_BB = false
    var bool CBB = false // Condition Breaker Block

    if TriggerCondition
        DistalPrice := distalPrice
        ProximalPrice := proximalPrice

    float ML = switch MitigationLvL
        'Proximal' => ProximalPrice
        'Distal' => DistalPrice
        '50 % OB' => (ProximalPrice+DistalPrice) / 2

    float ML_BB = switch MitigationLvL_BB
        'Proximal' => ProximalPrice_BB
        'Distal' => DistalPrice_BB
        '50 % OB' => (ProximalPrice_BB+DistalPrice_BB) / 2    

    //Demand Oreder Block
    if oBType == 'Demand' 
        if  TriggerCondition  and Show
            Distal := line.new(Index, DistalPrice, bar_index  , DistalPrice , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Proximal := line.new(Index, ProximalPrice, bar_index , ProximalPrice , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Line50per := line.new(Index, (ProximalPrice+DistalPrice) / 2 , bar_index , (ProximalPrice+DistalPrice) / 2  , color = color.rgb(0, 0, 0) , 
             style = line.style_dotted , width = 1)
            fillline := linefill.new(Distal ,Proximal ,color = colorZone )

        if (Check == true) and OBValidGlobal == true 
            Counter := Counter + 1  
            line.set_x2(Distal, bar_index + 1 )
            line.set_x2(Proximal,  bar_index + 1)
            line.set_x2(Line50per,  bar_index + 1)

        if (low < ML)  or (bar_index -  Index) >= OBValidDis 
            Counter := Counter
            Check := false
            
        if TriggerCondition
            Counter := 1
            Check := true
    //Demand Block to Supply Breaker Block
        CBB := Check[1] == true and Check == false
        if (CBB[1] or CBB[2] or CBB[3] or CBB)  and Check_BB == false
            if close < DistalPrice
                Index_BB := bar_index
                Check_BB := true
                DistalPrice_BB := ProximalPrice
                ProximalPrice_BB := DistalPrice


        if  Check_BB[1] == false and Check_BB == true  and Show_BB
            Distal_BB := line.new(Index_BB, DistalPrice_BB, bar_index  , DistalPrice_BB , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Proximal_BB := line.new(Index_BB, ProximalPrice_BB, bar_index , ProximalPrice_BB , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Line50per_BB := line.new(Index_BB, (ProximalPrice_BB+DistalPrice_BB) / 2 , bar_index , (ProximalPrice_BB+DistalPrice_BB) / 2  , color = color.rgb(0, 0, 0) , 
             style = line.style_dotted , width = 1)
            fillline_BB := linefill.new(Distal_BB ,Proximal_BB ,color = colorZone_BB )
            TriggerCondition_BB := Check_BB[1] == false and Check_BB == true
        else 
            TriggerCondition_BB := false            

        if (Check_BB[1] == true) and (Check_BB == true) and OBValidGlobal == true  
            line.set_x2(Distal_BB, bar_index + 1 )
            line.set_x2(Proximal_BB,  bar_index + 1)
            line.set_x2(Line50per_BB,  bar_index + 1)

        if (high > ML_BB)  or (bar_index -  Index_BB) >= OBValidDis or (Check[1] == true and Check == false)
            Check_BB := false
            

    //Supply Oreder Block
    if oBType == 'Supply' 
        if TriggerCondition and show
            Distal := line.new(Index, DistalPrice, bar_index , DistalPrice , color = color.rgb(0, 0, 0, 45) , style = line.style_dashed , width = 1)
            Proximal := line.new(Index, ProximalPrice, bar_index  , ProximalPrice , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Line50per :=line.new(Index, (ProximalPrice+DistalPrice) / 2 , bar_index  , (ProximalPrice+DistalPrice) / 2  , color = color.rgb(0, 0, 0) , 
             style = line.style_dotted , width = 1)
            fillline := linefill.new(Distal ,Proximal ,color = colorZone )

        if (Check == true) and OBValidGlobal == true 
            Counter := Counter + 1
            line.set_x2(Distal, bar_index + 1 )
            line.set_x2(Proximal,  bar_index + 1)
            line.set_x2(Line50per,  bar_index + 1)

        if (high > ML) or (bar_index -  Index) >= OBValidDis 
            Counter := Counter
            Check := false

        if TriggerCondition
            Counter := 1
            Check := true
    //Supply Block to Demand Breaker Block
        CBB := Check[1] == true and Check == false
        if (CBB[1] or CBB[2] or CBB[3]  or CBB)  and Check_BB == false
            if close > DistalPrice
                Index_BB := bar_index
                Check_BB := true
                DistalPrice_BB := ProximalPrice
                ProximalPrice_BB := DistalPrice


        if  Check_BB[1] == false and Check_BB == true  and Show_BB
            Distal_BB := line.new(Index_BB, DistalPrice_BB, bar_index  , DistalPrice_BB , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Proximal_BB := line.new(Index_BB, ProximalPrice_BB, bar_index , ProximalPrice_BB , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Line50per_BB := line.new(Index_BB, (ProximalPrice_BB+DistalPrice_BB) / 2 , bar_index , (ProximalPrice_BB+DistalPrice_BB) / 2  , color = color.rgb(0, 0, 0) , 
             style = line.style_dotted , width = 1)
            fillline_BB := linefill.new(Distal_BB ,Proximal_BB ,color = colorZone_BB )
            TriggerCondition_BB := Check_BB[1] == false and Check_BB == true
        else 
            TriggerCondition_BB := false

        if (Check_BB[1] == true) and (Check_BB == true) and OBValidGlobal == true  
            line.set_x2(Distal_BB, bar_index + 1 )
            line.set_x2(Proximal_BB,  bar_index + 1)
            line.set_x2(Line50per_BB,  bar_index + 1)

        if (low < ML_BB)  or (bar_index -  Index_BB) >= OBValidDis or (Check[1] == true and Check == false)
            Check_BB := false

    //Delete Last OB
    if not ShowAll and TriggerCondition and TriggerCondition != false
        line.delete(Distal[1])
        line.delete(Proximal[1])
        line.delete(Line50per[1])
        linefill.delete(fillline[1])

    //Delete Last BB
    if not ShowAll_BB and TriggerCondition_BB and TriggerCondition_BB != false
        line.delete(Distal_BB[1])
        line.delete(Proximal_BB[1])
        line.delete(Line50per_BB[1])
        linefill.delete(fillline_BB[1])    

    //Mitigation Order Block Alert
    if Check[1] == true and Check == false
        MitigationAlert := true
    else
        MitigationAlert := false

    //Mitigation Breaker Block Alert
    if Check_BB[1] == true and Check_BB == false and MitigationAlert == false 
        MitigationAlert_BB := true
    else
        MitigationAlert_BB := false

    [MitigationAlert, MitigationAlert_BB, ProximalPrice_BB, DistalPrice_BB, Index_BB]

Overview

OrderBlockDrawing_TradingFinder draws lines connecting distal and proximal points of demand order blocks with a middle 50 percent level line and colored zone fills between them. Breaker blocks appear when demand blocks are mitigated. Function parameters control block type, visibility, colors, and mitigation levels. Lines update as the chart advances. It draws exclusively on the price chart for any instrument and timeframe.

Details

Published by

alvinng214 on GitHub

Code credit

TFlab, as written in the script's header

Type

Library, Pine Script v5

Draws

Library (no plots)

Category

Support & resistance, SMC / ICT / price action

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.

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

SMC Engine Private

by skipp-dev
1 stars

This Pine Script v6 library serves as an internal engine for Smart Money Concepts (SMC), providing types, tracking, and rendering logic for order blocks, fair value gaps, and market structure. It calculates order block parameters including quality scores, heig

Library v6 SMC / ICT / price actionSupport & resistance
Updated 2 days ago · None stated GitHub repository of SMC Engine Private

SFA FlowLiquidity v1

by genesisgrubio39
1 stars

The SFA FlowLiquidity library computes structural flow and liquidity events from price data. It detects sweep ups and downs with associated scores, identifies liquidity levels, and applies session and regime filters. Persistent arrays track liquidity prices, b

Library v6 SMC / ICT / price actionSupport & resistance
Updated 10 months ago · None stated GitHub repository of SFA FlowLiquidity v1

AuthLib

by alboogycOdR
6 stars

AuthLib is a Pine Script utility library providing access control and state management structures for technical indicators. It checks callers against a hardcoded array of authorized TradingView usernames before executing operations. The library exports user-de

Library v5 SMC / ICT / price actionSessions & time
Updated 7 months ago · None stated GitHub repository of AuthLib

PineDraw

by 345-strategies
5 stars

PineDraw is a Pine Script v6 library that provides object primitives for drawing and updating price levels on the chart. It enables indicators and strategies to maintain lines, boxes, and labels in place by updating existing objects instead of deleting and rec

Library v6 Support & resistance
Updated 2 days ago · MPL-2.0 GitHub repository of PineDraw

ZigZag

by rubystar0512
5 stars

This library calculates ZigZag pivots and draws connecting lines on the price chart. It changes direction when price moves beyond a percentage deviation after a set pivot depth, then stores each pivot with optional labels for reversal price, cumulative volume,

Library v5 Support & resistance
Updated 2 years ago · None stated GitHub repository of ZigZag

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

More libraries

Trade Your Charts With a Regulated Broker

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

Compare brokers