Library · Pine Script v5 · Library

OrderBlockOverlappingDrawing

by alvinng214· code credited to TFlab

This Pine Script v5 library provides a drawing function that renders overlapping supply and demand order blocks directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code133
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

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

TFlabOrderBlockOverlappingDrawing_TradingFinder1.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('OrderBlockOverlappingDrawing', overlay = true)

export OBOverlappingDrawing(string OBType , bool TriggerConditionOrigin, float distalPrice_Pre, float proximalPrice_Pre ,float distalPrice_Curr, float proximalPrice_Curr, int  Index_Curr ,
 bool OBValidGlobal, int OBValidDis, string MitigationLvL,bool ShowAll,bool Show,color ColorZone) =>

    var string oBType = OBType
    var bool Trigger = false
    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 int Index_Curr_Mit = 0
    var int Index_Pre_Mit  = 0
    var int Bar = 0

    if oBType == 'Demand'
        if  TriggerConditionOrigin     and Bar != Index_Curr    
            Bar := Index_Curr
            if (proximalPrice_Curr >= proximalPrice_Pre) and (distalPrice_Curr <= proximalPrice_Pre) and (distalPrice_Curr >= distalPrice_Pre)
                ProximalPrice := proximalPrice_Pre
                DistalPrice := distalPrice_Curr
                Trigger := true

            else if  (proximalPrice_Curr <= proximalPrice_Pre) and (distalPrice_Pre <= proximalPrice_Curr) and (distalPrice_Curr <= distalPrice_Pre)
                ProximalPrice := proximalPrice_Curr
                DistalPrice := distalPrice_Pre
                Trigger := true
                
            else if (proximalPrice_Curr <= proximalPrice_Pre) and (distalPrice_Pre <= proximalPrice_Curr) 
                ProximalPrice := proximalPrice_Curr
                DistalPrice := distalPrice_Curr        
                Trigger := true
            else 
                Trigger := false
        
    if oBType == 'Supply'
        if  TriggerConditionOrigin     and Bar != Index_Curr
            Bar := Index_Curr
            if (distalPrice_Curr >= distalPrice_Pre) and (distalPrice_Pre >= proximalPrice_Curr) and (proximalPrice_Pre <= proximalPrice_Curr)
                ProximalPrice := proximalPrice_Curr
                DistalPrice := distalPrice_Pre
                Trigger := true
            else if (distalPrice_Pre >= distalPrice_Curr) and (proximalPrice_Pre <= distalPrice_Curr) and (proximalPrice_Pre >= proximalPrice_Curr)
                ProximalPrice := proximalPrice_Pre
                DistalPrice := distalPrice_Curr
                Trigger := true                
            else if (distalPrice_Pre >= distalPrice_Curr) and (proximalPrice_Curr >= proximalPrice_Pre) 
                ProximalPrice := proximalPrice_Curr
                DistalPrice :=     distalPrice_Curr
                Trigger := true
            // else 
            //     Trigger := false 

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

    //Demand Oreder Block
    if oBType == 'Demand' 
        if  Trigger  and Show
            Distal := line.new(Index_Curr, DistalPrice, bar_index  , DistalPrice , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Proximal := line.new(Index_Curr, ProximalPrice, bar_index , ProximalPrice , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Line50per := line.new(Index_Curr, (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_Curr) >= OBValidDis 
            Counter := Counter
            Check := false
            
        if Trigger
            Counter := 1
            Check := true
            Trigger := false

    //Supply Oreder Block
    if oBType == 'Supply' 
        if Trigger and show
            Distal := line.new(Index_Curr, DistalPrice, bar_index , DistalPrice , color = color.rgb(0, 0, 0, 45) , style = line.style_dashed , width = 1)
            Proximal := line.new(Index_Curr, ProximalPrice, bar_index  , ProximalPrice , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
            Line50per :=line.new(Index_Curr, (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_Curr) >= OBValidDis 
            Counter := Counter
            Check := false

        if Trigger
            Counter := 1
            Check := true
            Trigger := false

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


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

    [MitigationAlert]

Overview

OrderBlockOverlappingDrawing calculates proximal, distal, and midpoint mitigation price boundaries when an origin trigger condition is met across consecutive bars. Function parameters determine the order block type, price levels, bar indices, mitigation levels, and visual zone styling. As a drawing utility, it produces no standalone trading signals and relies entirely on external scripts to detect order blocks and pass valid parameters.

Details

Published by

alvinng214 on GitHub

Code credit

TFlab, as written in the script's header

Draws

Library (no plots)

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

FunctionLinearRegression

by ricardosantos79
261 stars

This Pine Script v5 library provides functions to calculate and plot linear regression channels using sample point arrays. It evaluates paired X and Y arrays to calculate the regression slope, intercept, fitted values, maximum deviation, minimum deviation, and

Library v5 Trend
Updated 4 years ago · None stated GitHub repository of FunctionLinearRegression

PositionSizing

by iamrichardD
57 stars

This Pine Script v6 library calculates trade position sizes and provides risk management functions for external scripts. It computes position sizes from account equity, percentage risk, and stop-loss distance, and offers dynamic sizing adjustments based on vol

Library v6
Updated 1 year ago · Apache-2.0 GitHub repository of PositionSizing

Chart Patterns

by deepentropy
13 stars

Chart Patterns is a Pine Script v6 library designed to scan for and render technical chart patterns directly on the price chart. It defines custom user-defined types to configure scanning parameters, such as Zigzag pivot offsets, error ratios, flat ratios, and

Library v6 Repaints
Updated 6 months ago · MIT GitHub repository of Chart Patterns

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

WebhookMessageLibrary

by TradersPost
6 stars

WebhookMessageLibrary is a helper library designed to construct structured JSON payload messages for automated trading integrations like TradersPost. It defines custom exported types and constants for trade actions, market sentiments, quantities, limit prices,

Library v5
Updated 1 year ago · None stated GitHub repository of WebhookMessageLibrary

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 4 days ago · MPL-2.0 GitHub repository of PineDraw

More libraries

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