OPEN-SOURCE SCRIPT
Market Structure Mechanics - MSS

This script is an automated structural mapping tool designed to read price action through the strict lens of the ICT (Inner Circle Trader) algorithmic framework. It doesn't just mark every high and low; it intelligently categorizes how price interacts with structural levels to tell you whether the trend is continuing, reversing, or manipulating.
Here is a breakdown of how the script interprets market mechanics:
1. Trend Tracking & Pivot Identification
The script actively tracks the most recent swing high (sh) and swing low (sl) to determine the current trend (bullish or bearish). It uses a customizable pivot length (default 5 bars) to identify these structural turning points.
2. Break of Structure (BOS)
A BOS signals that the current trend is continuing.
If the trend is Bullish and a candle closes decisively above the active Swing High, the script draws a solid blue line and labels it BOS.
If the trend is Bearish and a candle closes decisively below the active Swing Low, it draws a solid red line labeled BOS.
3. Market Structure Shift (MSS) with Displacement
An MSS is a high-probability signal that the overall trend has reversed. However, the script is designed to filter out fake reversals by enforcing the Displacement Rule.
If the trend is Bullish, but price suddenly closes below the active Swing Low, the algorithm checks the recent down-move to see if a Bearish Fair Value Gap (FVG) was formed.
If an FVG is present, it means the move had massive institutional momentum (Displacement). It will draw a thick red line labeled MSS, and the trend will officially shift to bearish.
If it breaks the low but no FVG is found, the script flags it as a low-probability, invalid break (drawn as a dotted gray line).
4. Liquidity Sweeps (Stop Hunts)
This is where the script shines at reading manipulation.
If price pushes past a structural high or low to trigger retail stop losses, but the candle ultimately fails to close beyond the level (leaving a wick), the script immediately recognizes this as a stop hunt.
It will draw a dashed orange line and label it Sweep.
The script also features a built-in "Smart Label Merger", meaning if a level gets Swept and then Broken on the exact same candle, the labels will neatly combine (e.g., "Sweep, BOS") instead of creating a messy, overlapping clump of text on your chart.
Here is a breakdown of how the script interprets market mechanics:
1. Trend Tracking & Pivot Identification
The script actively tracks the most recent swing high (sh) and swing low (sl) to determine the current trend (bullish or bearish). It uses a customizable pivot length (default 5 bars) to identify these structural turning points.
2. Break of Structure (BOS)
A BOS signals that the current trend is continuing.
If the trend is Bullish and a candle closes decisively above the active Swing High, the script draws a solid blue line and labels it BOS.
If the trend is Bearish and a candle closes decisively below the active Swing Low, it draws a solid red line labeled BOS.
3. Market Structure Shift (MSS) with Displacement
An MSS is a high-probability signal that the overall trend has reversed. However, the script is designed to filter out fake reversals by enforcing the Displacement Rule.
If the trend is Bullish, but price suddenly closes below the active Swing Low, the algorithm checks the recent down-move to see if a Bearish Fair Value Gap (FVG) was formed.
If an FVG is present, it means the move had massive institutional momentum (Displacement). It will draw a thick red line labeled MSS, and the trend will officially shift to bearish.
If it breaks the low but no FVG is found, the script flags it as a low-probability, invalid break (drawn as a dotted gray line).
4. Liquidity Sweeps (Stop Hunts)
This is where the script shines at reading manipulation.
If price pushes past a structural high or low to trigger retail stop losses, but the candle ultimately fails to close beyond the level (leaving a wick), the script immediately recognizes this as a stop hunt.
It will draw a dashed orange line and label it Sweep.
The script also features a built-in "Smart Label Merger", meaning if a level gets Swept and then Broken on the exact same candle, the labels will neatly combine (e.g., "Sweep, BOS") instead of creating a messy, overlapping clump of text on your chart.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.