OPEN-SOURCE SCRIPT

Regime Blocks

5 925
Regime Blocks is a market-structure visualization tool that converts confirmed structural breaks into sequential bullish and bearish price-range blocks.
The indicator helps answer three practical questions directly on the chart:
1. Which structural regime is currently active?
2. How long has the current regime remained active?
3. What price range has developed within the regime?
The main purpose of Regime Blocks is to present price movement as a clear visual map of bullish and bearish structural regimes.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🧠 ORIGINALITY AND DESIGN LOGIC
The indicator is based on two analytical concepts:
confirmed swing highs and swing lows;
Average True Range, or ATR, used as a volatility-adjusted structural-break filter.
These components are not an arbitrary combination of unrelated indicators. They work together as parts of one unified market-structure model.
Confirmed swing points define the structural levels that price must exceed. The ATR filter defines the additional minimum distance price must move beyond a swing level before the break is accepted by the system.
Using ATR instead of a fixed number of points allows the confirmation threshold to adapt automatically to instruments with different price scales and volatility levels.
After a break is confirmed, the script applies a persistent market-state model:
an upward break can establish a bullish regime;
a downward break can establish a bearish regime;
a break in the opposite direction changes the current regime;
a break in the same direction can divide an extended regime into a new visual wave without changing its bullish or bearish classification.
The distinction between a regime change and a continuation structural wave is one of the indicator’s key features.
Without segmentation, an extended move can appear as one oversized block that becomes difficult to analyze. Regime Blocks divides such movements into more compact structural sections while preserving the overall regime direction.
This makes it possible to see simultaneously:
the broader structural condition of the market;
the internal development of the current move;
the sequence of structural waves.
The indicator maintains only one Bullish or Bearish label for each regime. When a new wave begins in the same direction, the label is transferred to the current block instead of being repeated on every section.
This approach reduces unnecessary text and keeps the chart visually clean.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚙️ HOW THE CALCULATIONS WORK
1. Swing-point confirmation
The indicator identifies local swing highs and swing lows using a symmetrical pivot window.
The Swing Length setting defines how many candles must appear on both sides of a potential extreme before the swing can be confirmed.
For example, a value of Swing Length = 8 means that eight candles to the left and eight candles to the right are required to confirm a swing point.
A higher value:
creates fewer structural levels;
highlights broader market movements;
reduces sensitivity to short-term fluctuations;
confirms structural changes later.
A lower value:
reacts more quickly to price movement;
identifies smaller structures;
creates more structural breaks;
may increase the number of regime changes.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2. Structural-break confirmation
After a swing point is confirmed, the indicator monitors whether price moves beyond the corresponding structural level.
A bullish structural break occurs when the selected confirmation source moves above the latest confirmed swing high, including the additional ATR-based filter.
A bearish structural break occurs when the selected confirmation source moves below the latest confirmed swing low, including the ATR-based filter.
The user can choose between two confirmation methods:
candle-close confirmation;
candle-extreme confirmation using the wick.
When candle-close confirmation is enabled, the structural event is confirmed only after the candle closes beyond the calculated level.
When candle-close confirmation is disabled, the event can be triggered by the candle’s high or low before the current candle closes.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3. ATR break filter
The Break Filter setting is expressed as a fraction or multiple of ATR.
For example, a value of 0.20 means that price must move beyond the swing level by an additional distance equal to at least 0.20 ATR.
Increasing the value:
filters weaker and marginal breaks;
reduces the number of regime changes;
makes the indicator more conservative.
Decreasing the value:
increases the speed of the indicator’s response;
makes the model more sensitive;
may increase the number of temporary or minor breaks.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4. Market-regime changes
The first confirmed structural break establishes the initial market state.
After that:
a bearish break during a bullish regime starts a Bearish regime;
a bullish break during a bearish regime starts a Bullish regime.
Each confirmed swing level can generate only one break event.
This prevents the same structural level from repeatedly generating events on subsequent candles.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
5. Dividing a regime into structural waves
A confirmed break in the current direction does not change the regime.
For example, a new upward break within an already active bullish regime does not establish a different market state. The regime remains bullish.
When Split Long Regimes Into Waves is enabled, such a break can start a new visual block within the same regime.
A new wave is created only when all three conditions are met:
a new structural break in the current direction is confirmed;
the current block has reached the required minimum duration;
the current block has reached the required minimum price range measured in ATR.
These filters prevent small or closely spaced breaks from creating an excessive number of blocks.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
6. Block construction
Each block begins on the candle where the corresponding structural event is confirmed.
While a block remains active:
its upper boundary follows the highest price reached within the block;
its lower boundary follows the lowest price reached within the block.
When the next structural wave begins or the regime changes, the completed block is fixed and a new block starts separately.
The blocks therefore display the actual price range formed within each structural section.
The blocks are not projected future support or resistance zones.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
👁️ HOW TO READ THE INDICATOR
🟢 Bullish regime
Bullish blocks are displayed in green.
The lower boundary is emphasized as the primary reference boundary of the bullish regime.
The upper boundary is displayed as the secondary range boundary.
The Bullish label appears below the lower boundary of the block.
🔴 Bearish regime
Bearish blocks are displayed in red.
The upper boundary is emphasized as the primary resistance boundary of the bearish regime.
The lower boundary is displayed as the secondary range boundary.
The Bearish label appears above the upper boundary of the block.
A longer block shows that the structural condition remained active for a greater number of candles.
Frequent alternation between Bullish and Bearish may indicate a less stable, sideways, or rotational market structure.
Extended sections in one direction indicate a more persistent structural move.
Block boundaries should be interpreted as the actual extremes of a completed or developing structural wave, not as guaranteed reversal points.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🛠️ INDICATOR SETTINGS
Swing Length
Controls the sensitivity of confirmed swing-high and swing-low detection.
Lower values:
react more quickly to price movement;
identify smaller structures;
generally create more regime changes.
Higher values:
identify broader structures;
reduce the influence of short-term market noise;
confirm structural changes later.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Confirm Break By Candle Close
When this setting is enabled, a structural break is confirmed only after the candle closes.
This is the more conservative option and prevents intrabar events that may disappear before the candle closes.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Break Filter, ATR
Defines the additional distance beyond a confirmed swing level required to validate a structural break.
Increase the value to filter weaker breaks.
Decrease the value when a faster response to structural changes is preferred.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Split Long Regimes Into Waves
Determines whether extended bullish and bearish regimes are divided into separate visual blocks after confirmed breaks in the current direction.
When this setting is disabled, one block continues until the regime changes direction.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Minimum Wave Length
Defines the minimum number of candles that must form within the current block before another break in the same direction can begin a new visual wave.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Minimum Wave Range, ATR
Defines the minimum height of the current block relative to ATR before the block can be segmented.
A value of 0 disables this requirement.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎨 Visual settings
Users can customize:
bullish and bearish block colors;
fill transparency;
boundary visibility;
boundary-line width;
secondary-boundary transparency;
label visibility and spacing;
the number of historical blocks displayed on the chart.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔔 ALERTS
The indicator provides four alert conditions.
Bullish Regime Started
Triggers when a confirmed bullish structural break changes the market state from bearish or undefined to bullish.
Bearish Regime Started
Triggers when a confirmed bearish structural break changes the market state from bullish or undefined to bearish.
Bullish Structural Wave
Triggers when a confirmed upward break starts a new visual block within an already active bullish regime.
The regime itself does not change.
Bearish Structural Wave
Triggers when a confirmed downward break starts a new visual block within an already active bearish regime.
The regime itself does not change.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⏱️ CONFIRMATION AND REAL-TIME BEHAVIOR
A pivot point requires candles to form to the right of the potential extreme before it can be confirmed.
A swing high or swing low is therefore confirmed with a delay equal to the selected Swing Length.
The indicator does not move a structural-break event retrospectively to the candle where the potential pivot originally appeared.
It first waits for the swing point to be confirmed and then monitors whether the structural-break condition is satisfied.
When candle-close confirmation is enabled, regime changes and new-wave events are evaluated only on closed candles.
When candle-close confirmation is disabled, an intrabar event may appear while the candle is forming and disappear before the candle closes if price moves back inside the structural level.
The active block changes in real time as price develops:
the upper boundary expands when a new high is formed;
the lower boundary expands when a new low is formed.
After the next block begins, completed historical blocks no longer change.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ LIMITATIONS
Regime Blocks is a market-structure visualization indicator, not a complete trading system.
It does not analyze:
volume;
momentum divergence;
order flow;
fundamental data;
trading sessions;
position sizing;
stop-loss placement;
expected trade return;
commissions or other trading costs.
The indicator does not predict whether a block boundary will hold and does not provide guaranteed entry or exit signals.
The output depends on:
the selected Swing Length;
the ATR filter value;
the chart timeframe;
the instrument’s volatility;
the candle type being used.
Synthetic chart types may produce different results because their open, high, low, and close values differ from standard market candles.
Regime Blocks is intended to be used as a market-context tool alongside the trader’s own entry rules, risk management, and independent analysis.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.