PINE LIBRARY

Order Block Refiner [TradingFinder]

By TFlab
Updated
🔵Introduction

The "Refinement" feature allows you to adjust the width of the order block according to your strategy. There are two modes, "Aggressive" and "Defensive," in the "Order Block Refine". The difference between "Aggressive" and "Defensive" lies in the width of the order block.

For risk-averse traders, the "Defensive" mode is suitable as it provides a lower loss limit and a greater reward-to-risk ratio. For risk-taking traders, the "Aggressive" mode is more appropriate. These traders prefer to enter trades at higher prices, and this mode, which has a wider order block width, is more suitable for this group of individuals.


Important:
One of the advantages of using this library is increased code accuracy. Not only does it have the capability to create order blocks, but you can also simply define the condition for order block creation (true/false) and "bar_index," and you'll find the primary range without applying any filters.


🟣Order Block Refinement Algorithm

The order block ranges are filtered in two stages. In the first stage, the "Open," "High," "Low," and "Close" of the current order block candle, its two or three previous candles, and one subsequent candle (if available) are examined. In this stage, minimum and maximum distances are calculated, and logical range filters are applied.

In the second stage, two modes, "Aggressive" and "Defensive," are calculated.

For the "Defensive" mode, the width of these ranges is compared with the "ATR" (Average True Range) of period 55, and if they are smaller than "ATR" or 1 to more than 4 times "ATR," the width of the range is reduced from 0 to 80 percent.

For the "Aggressive" mode, you get the same output as the first filter, which usually has a wider width than the "Defensive" mode.


Order Block Refiner: Off

snapshot

Order Block Refiner: On / "Aggressive Mode"

snapshot

Order Block Refiner: On / "Defensive Mode"

snapshot



🔵How to Use




To add "Order Block Refiner Library", you must first add the following code to your script.




OBType: This parameter receives 2 inputs. If the order block you want to "Refine" is of type demand, you should enter "Demand," and if it's of type supply, you should enter "Supply."

OBRefine: Set to "On" if you want the "Refine" operation to be performed. Otherwise, set to "Off."

RefineMethod: This input receives 2 modes, "Aggressive" and "Defensive." You can switch between these modes according to your needs.

TriggerCondition: Enter the condition with which the order block is formed in this parameter.

Index: Enter the "bar_index" of the candle where the order block is formed in this parameter.


🟣Function Outputs

This function has 6 outputs: "bar_index" at the beginning of the "Distal" line, "bar_index+1" at the end of the "Distal" line, "Price" at the "Distal" line, "bar_index" at the beginning of the "Proximal" line, "bar_index+1" at the end of the "Proximal" line, and "Price" at the "Proximal" line, which can be used to draw order blocks.

Sample:


Release Notes
v2
🔵Fixed Error

Due to the limitation on the number of available candles, which is no more than 5000, errors occasionally occurred. This issue has been resolved with a minor modification.
displaystatisticstechindicator
TFlab

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.

Disclaimer