PINE LIBRARY

Order Block Drawing [TradingFinder]

Updated
🔵Introduction

Perhaps one of the most challenging tasks for Pine script developers (especially beginners) is properly drawing order blocks. While utilizing the latest technical analysis methods for "Price Action," beginners heavily rely on accurately plotting "Supply" and "Demand" zones, following concepts like "Smart Money Concept" and "ICT".

However, drawing "Order Blocks" may pose a challenge for developers. Therefore, to minimize bugs, increase accuracy, and speed up the process of coding order blocks, we have released the "Order Block Drawing" library.

Below, you can read more details about how to use this library.

Important:

This library has direct and indirect outputs. The indirect output includes the ranges of order blocks plotted on the chart. However, the direct output is a "Boolean" value that becomes "true" only when the price touches an order block, colloquially termed as "Mitigate." You can use this output for setting up alerts.


🔵How to Use

First, you can add the library to your code as shown in the example below.



🟣Parameters




OBType: All order blocks are summarized into two types: "Supply" and "Demand." You should input your order block type in this parameter. Enter "Demand" for drawing demand zones and "Supply" for drawing supply zones.

TriggerCondition: Input the condition under which you want the order block to be drawn in this parameter.

DistalPrice: Generally, if each zone is formed by two lines, the farthest line from the price is termed "Distal." This input receives the price of the "Distal" line.

ProximalPrice: Generally, if each zone is formed by two lines, the nearest line to the price is termed "Proximal" line.

Index: This input receives the value of the "bar_index" at the beginning of the order block. You should store the "bar_index" value at the occurrence of the condition for the order block to be drawn and input it here.

OBValidDis: Order blocks continue to be drawn until a new order block is drawn or the order block is "Mitigate." You can specify how many candles after their initiation order blocks should continue. If you want no limitation, enter the number 4998.

Show: You may need to manage whether to display or hide order blocks. When this input is "On", order blocks are displayed, and when it's "Off", order blocks are not displayed.

ColorZone: You can input your preferred color for drawing order blocks.

🔵Function Outputs

This function has only one output. This output is of type "Boolean" and becomes "true" only when the price touches an order block. Each order block can be touched only once and then loses its validity. You can use this output for alerts.


Release Notes
v2

New Update: New Feature and Fixed Bug

🔵Fixed Bug

There was a bug in the mitigation process that sometimes caused an alarm not to be issued despite the proximal level being mitigated. This bug has been fixed.

🔵New Feature

Order Block Drawing Control:
From now on, you can manage the drawing Order Block. For example, if you need the drawing of the Order Block to stop before the predicted natural states, you can enter that condition in the function so that the drawing of the Order Block will stop when it happens.

Mitigation Level Management:
From now on, you can choose yourself whether the trigger will happen at the "Proximal", "Distal" or "50 % OB" level. This feature helps you to have more customization in your strategy logic.

Show All Order Block:

In the previous version, you had no control over whether or not to display the last Order Block. Using this feature, you can choose to display only the last Order Block or display all Order Block.

OBDrawing(OBType, TriggerCondition, distalPrice, proximalPrice, Index, OBValidGlobal, OBValidDis, MitigationLvL, ShowAll, Show, ColorZone)
  Parameters:
    OBType (string)
    TriggerCondition (bool)
    distalPrice (float)
    proximalPrice (float)
    Index (int)
    OBValidGlobal (bool)
    OBValidDis (int)
    MitigationLvL (string)
    ShowAll (bool)
    Show (bool)
    ColorZone (color)

🔵New Parameters

OBValidGlobal (bool): This parameter is a boolean in which you can enter the condition that you want to execute to stop drawing the block order. If you do not have a special condition, you should set it to True.

MitigationLvL (string): This parameter is a string. Its inputs are one of "Proximal", "Distal" or "50 % OB" modes, which you can enter according to your needs. The "50 % OB" line is the middle line between distal and proximal.

ShowAll (bool): This is a boolean parameter, if it is "true" the entire order of blocks will be displayed, and if it is "false" only the last block order will be displayed.
Release Notes
v3

New Updated: New Feature

🔵New Feature

Breaker Block Drawing:

When an order block is broken by the price and the price closes outside the Zone, it can be assumed that its type has changed, that is, the demand order block becomes a supply breaker block or a supply order block becomes a demand breaker block.

From now on, there is this feature in this library that if you need to draw the block breaker, you can set "Show_BB" equal to "true".


snapshot


snapshot



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


🔵New Parameters


MitigationLvL_BB (string): This parameter is a string. Its inputs are one of "Proximal", "Distal" or "50 % OB" modes, which you can enter according to your needs. The "50 % OB" line is the middle line between distal and proximal.(Breaker Block)

ShowAll_BB (bool): This is a boolean parameter, if it is "true" the entire Breaker Block will be displayed, and if it is "false" only the last Breaker Block will be displayed.

Show_BB (bool): You may need to manage whether to display or hide Breaker Block. When this input is "On", Breaker Block are displayed, and when it's "Off", Breaker Block are not displayed.

ColorZone_BB (color): You can input your preferred color for drawing Breaker Blocks.
Release Notes
🔵Fixed Bug

In the drawing of breaker blocks, up to 9 candles were checked after the break. This feature caused bugs and broken display of breaker blocks. By limiting the number of checked candles to 4, a major part of this bug was fixed.

🔵New OutPut

The basic data related to the breaker blocks was added to the outputs. These data include proximal, distal and index.
displayformattingictictconceptsictorderblockorderblockorderblockssmartmoneysmartmoneyconceptSMCsupply_and_demandtechindicator

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.


Get Access to TradingFinder indicators and Education for FREE: tradingFinder.com/

Forex, Crypto, Stocks, Futures & Index informational materials and Trading Tools in Turkish language: tradingFinder.com/tr/
Also on:

Disclaimer