OPEN-SOURCE SCRIPT

Magic Order Blocks [MW]

By mwrightinc
Updated
Add a slim design, minimalist view of the most relevant higher and lower order blocks to your chart. Use our novel method of filtering that uses both the the number of consecutive bullish or bearish candles that follow the order block, and the number of ATRs that the asset’s price changed following the order block. View just the order blocks above and below the current price, or view the backgrounds for each and every one. And, if you're up to it, dig into a comprehensive view of the data for each order block candle.

Settings:

General Settings
  • Minimum # of Consecutive Bars Following Order Block
  • Show Bullish Order Blocks Below / Hide Last Bullish Block
  • Show Bearish Order Blocks Above / Hide Last Bearish Block
  • Use ATR Filter - Select # of ATRs Below
  • Closest Order Block is Followed by This Many ATRs


Preferences
  • Right Offset of Indicator Label
  • Show Mid-Line from Recent Order Block Indicator Label
  • Use ATRs Instead of Consecutive Candles in Label Indicator
  • Show Timestamp of Recent Order Block
  • Show Large Order Block Detail Labels
  • Show Small Order Block Labels


Background Settings
  • Show Background for Recent Order Block Indicator Label
  • # of Backgrounds to Show Before Now
  • Show All Bullish Order Block Backgrounds
  • Show All Bearish Order Block Backgrounds


Calculations

This indicator creates a matrix of each order block that is followed by the user-specified number of consecutive bullish or bearish candles. The data can be further filtered by the number of ATRs that the price moves after the order block - also user-defined. The most recent bearish order block above the current price takes arrays from the initial filtered matrix of arrays, filters once more by the “mid-price” of the order block (the average between the order block candle high and low) and selects the last element from this order block matrix. The same follows for the latest bearish order block above the current price.

How to Use

An order block refers to a price range or zone on a chart where large institutional orders have been placed, causing a significant shift in market direction. These zones are crucial because they often indicate areas of strong buying or selling interest, which can lead to future support or resistance levels. Traders use order blocks to identify potential points of market reversal or continuation.

The Magic Order Blocks [MW] default view shows the most recent overhead bearish order block above the current price, and the most recent bullish order block below. These can presumably act as support or resistance levels, because they reflect the last price where a significant price move occurred. “Significant” meaning that the order block candle was followed by many consecutive bullish or bearish candles. Based on the user-defined settings, it can also mean that price moved multiples of the asset's average true range (ATR). More consecutive candles means that the duration of the move lasted a long time. A higher ATR move indicates that the price moved impulsively in one direction.

The default view also shows a label to the right of the current price that provides the price level, the time stamp of the order block (optional), and a sequence of bars that show the significance of the level. By default, these bars represent the number of ATRs that price rose or fell following the order block, but they can be toggled to show the number of consecutive bullish or bearish candles that followed the order block.

Although the default view provides the zones that are most relevant to the current price, past order block candles can also be identified visually with labels as well with translucent backgrounds color-coded for bullish or bearish bias. Overlapping backgrounds can identify an area that has been repeatedly been an area of support or resistance.

A detailed view of each order block can also be viewed the includes the following data points:

  • Bar Index
  • Timestamp
  • Consecutive Accumulated Volume
  • Consecutive Bars
  • Price Change over Consecutive Bars
  • Price/Volume Ratio Over Consecutive Bars
  • Mid Price of Order Block
  • High Price of Order Block
  • Low Price of Order Block
  • ATRs over Consecutive Bars


- Other Usage Notes and Limitations:

The calculations used only provide an estimated relationship or a close approximation, and are not exact.

It's important for traders to be aware of the limitations of any indicator and to use them as part of a broader, well-rounded trading strategy that includes risk management, fundamental analysis, and other tools that can help with reducing false signals, determining trend direction, and providing additional confirmation for a trade decision. Diversifying strategies and not relying solely on one type of indicator or analysis can help mitigate some of these risks.

Things to keep in mind. Longer timeframes don’t necessarily have a as many consecutive candle drops or gains as with shorter timeframes, so be sure to adjust your settings when moving to 1 hour, 1 day, or 1 week timeframes from 1 minute, 5 minute, or 15 minute timeframes.
Release Notes
v1.1
- Fixed problem on OANDA:BTCUSD where an error was caused when there were no order blocks above the current price
Release Notes
v1.2
Fixed
  • Indicator labels not shifting to the right with new Candles
  • Matrix rows no longer keep adding for every candle
Release Notes
v1.2.1
  • Changed max_bars_back to 5000 from 1000 due to an error in drawing labels for older blocks
Release Notes
v1.2.2
  • Fixed error with "too large a lookback" / "too many bars in history"
ATRAverage True Range (ATR)Chart patternsorderblockssupportSupport and Resistance
mwrightinc

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