OPEN-SOURCE SCRIPT

Order blocks

Updated
Hi all!

This indicator will show you found order blocks that can be used as supply or demand. It's my take on trying to create good order blocks and I hope it makes sense.

First off I suggest to verify the current trend before using an order block. This can be done in a variety of ways, one way could be to use my other script "Market structure" (tradingview.com/script/ud6AQSm2-Market-structure/) which I use and suggest.

You can configure the indicator to behave differently depending on settings. These are the settings available:

• The order blocks created can be found in any higher timeframe defined in "Timeframe"
• The number of active order blocks are defined in "Count". If an order block is found the earliest order block will be replaced
• You can choose the type of order blocks that are found ("Bullish", "Bearish " or "Both") in "Type"
• The old order blocks can be kept if "Keep history" is checked
• Order blocks that are found are not removed when mitigated (entered) but when a new one appears. They can be removed when they are broken by price if "Remove broken zones" are checked

There is also a setting section called "Requirements" that defines what is required for an order block to be created. These are the settings:

• "Take out"
Check this if you want the base of the order block (the candle where the zone is drawn from (high and low)) to have to take out the previous candle (be higher or lower depending if the order block is bullish or bearish).
• "Consecutive rising/falling"
Each following candle in the reaction (the 3 reaction candles) needs to reach higher or lower (depending on bullish or bearish). Check this if you want that to be true.
• "Reaction"
Some sort of reaction is needed from the 3 candles creating the order block. This reaction is based on the value of the Average True Length (ATR) of length 14. You can here define a factor of the value from the ATR that these 3 candles needs to move in price. A higher need for a reaction (higher factor of the ATR) will create lesser zones. You can also choose to show this limit with the checkbox.
• "Fair Value Gap"
The reaction needs to create a gap (imbalance) in price. This gap is known as a "Fair Value Gap" and is created when the last candle's wick does not meet with the base candle's wick. Check this if you want this to be needed.

After these settings you can also choose the colors of the created zones. The ones that are active (called "Zones"), the ones that are replaced ("Replaced zones") and the ones that are broken ("Broken zones") (if this is enabled in "Remove broken zones").

I'm using my library "Touched" to be able to show you labels when the order blocks have a retest, false breakout and breakout. These labels can be hidden if you disable the labels under the style tab in the indicator settings.

The concept of order blocks is widely used among traders and can provide you with good supply or demand zones. I hope that this indicator makes sense.

My todo-list has a few things, but top of that list is adding alerts for zone interactions or creations. Please feel free to say what you want to be coded!

The order blocks in the publication chart are found in weekly timeframe but are shown on the daily timeframe. Other than that the image shows you zones from the default settings (which are based on the daily timeframe).

Best of luck trading!
Release Notes
- Use my new "OrderBlocks" library (tradingview.com/script/PH0EAO9s-OrderBlocks/)
- Fix spelling error
Release Notes
- Code is now moved to my library 'OrderBlocks' (tradingview.com/script/PH0EAO9s-OrderBlocks/) which makes this indicator code very sparse
Release Notes
- Now supports lower timeframes! You can set the timeframe lower then the chart and it use 'request.security_lower_tf'. This is possible since TradingView released Pine Script version 6 and request functions can now be used in local scopes. So the indicator will use 'request.security' or 'request.security_lower_tf' depending on if the configured timeframe is higher or lower than the chart's. If a lower timeframe than the chart is chosen you must select between "First" and "Last" to take a zoom in the chart's candle.
- Bumped Pine Script version to 6
Release Notes
- Bump 'OrderBlocks' to 8 which now uses hl2 values for checking for consecutive rising or falling candles. It also contains a bug fix for beariah order blocks checking to many candles for this.
Release Notes
- Bump library 'OrderBlocks' to 10 which uses globel variables and handles alert settings
- Add a setting group called 'Alerts' with settings for retests, false breakouts and breakouts. These are all enabled by default but let's you configure which alerts that should be notified
Release Notes
- You can now stop the creation of new order blocks. If you want alerts on order blocks integrations (retests, false breakouts or breakouts) then this is prefered. If the creation of new zones is not stopped (at the last bar) new zones might appear before the integration, thus not firering an alert as you might want to. I suggest having this checked when creating an alert, but not checked if you have indicator on the chart (it will not create new order blocks if so). So, have this at '-1' when the indicator is on the chart and at the last visible bar when creating an alert.

If creation of new order blocks are stopped the background will be red.
orderblocksupplanddemandSupport and Resistance

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer