Free: indicator teardowns, a repaint checker and open-source scripts. No buy/sell signals, ever.

Taught to TradeSystems over signals.

Explainers / Market Structure Break & Order Block

Market Structure Break & Order Block, explained from the source

"Market Structure Break & Order Block" by EmreKb is one of the most-boosted free scripts on TradingView, with more than 64,000 boosts. It draws a ZigZag, writes "MSB" when a swing breaks the one before it, and shades boxes on candles it calls order blocks and breaker blocks. The swings and the MSB labels are confirmed some bars after the turn and then drawn back at it, and when a box breaks, the code removes the oldest box in its list, which is often not the one that broke.

How it works

  1. ZigZag swings. The direction flips to up when a bar makes a new 9-bar high (ZigZag Length 9), and to down on a new 9-bar low. At each flip, the extreme of the leg just finished becomes a swing point, and the ZigZag line is drawn back to it.
  2. Market structure break (MSB). A bearish MSB is printed when the newest swing low is below the previous swing low by more than 0.33 times the last leg (Fib Factor 0.33). A bullish MSB is the mirror image with swing highs. The line and the "MSB" label are placed at the swing, in the past.
  3. Order block (OB). At a bullish MSB, the last down candle in the swing before the break is boxed as "Bu-OB" (the last up candle for a bearish one).
  4. Breaker / mitigation block (BB / MB). The last opposite candle one swing further back gets a second box. It is labelled breaker if the new swing went beyond the old one, mitigation if not.
  5. Boxes stay and extend 10 bars past the current bar until the close goes through them.

Why it looks better in hindsight

Every swing is known only after price has moved 9 bars' worth the other way, and the MSB needs that swing to exist. In our simulation the MSB arrived a median of 5 to 6 bars after the swing extreme it is drawn at. On a finished chart, the labels and boxes sit neatly at turning points; at the time, you would have seen them later, with price already away from the level. More in what repainting is.

Two things in the code worth knowing

The wrong box can disappear. With "Delete Old/Broken Boxes" on (the default), a box that the close breaks through calls a delete routine that removes the first box in that list, the oldest, not the box that was broken. In our simulation, in 50 to 60% of breaks an older, still-unbroken box was removed instead, and the broken one stayed until it reached the front of the list. A zone can vanish from your chart without price ever touching it.

The bearish order-block alert fires above the zone. The zone loops for the other three box types say "if broken... else if inside... alert". The bearish OB loop drops the "else", so "Price in the BE-OB zone" also fires when the close is above the box, after it has broken. In our simulation about 1 in 5 of those alerts came with the close above the zone.

The settings

SettingDefaultWhat it does
ZigZag Length9bars for a new high/low that flips the swing direction; also the confirmation delay
Fib Factor0.33how far past the old swing (as a share of the last leg) counts as a break
Delete Old/Broken Boxesondeletes a box when one in its list breaks (the oldest, see above)
Show Zigzagondraws the swing lines

The alerts

There is one alert condition you can pick in the alert dialog: MSB, when the structure flips. The four zone messages ("Price in the BU-OB zone" and so on) come from alert() calls inside the script: they need an "Any alert() function call" alert and fire on every bar the close sits in a zone, not once per touch. None of them says anything about what price does next.

Where it fails

Also explained: ZigZag · Pivot Points High Low · Support Resistance Channels · Repainting

Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Market Structure Break & Order Block is by EmreKb on TradingView, published under the Mozilla Public License 2.0; this page explains its published open-source code and is not affiliated with the author. Simulation figures come from synthetic random-walk prices and say nothing about how the indicator trades.

Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue

Next steps

  • Get a script fixed. Compiles but behaves differently live, or changes after a reload? In a Pine Script Audit, an AI model reads every line and writes a report on what to fix for $49, or also fixes those problems for $149. It cannot prove a script is safe.
  • Check your own script. Paste its source into the free repaint checker. It runs in your browser and flags known patterns.
Subscribe to the Teardown Letter: $19/moBack to Taught to Trade

No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.