PINE LIBRARY
Market Structure Report Library [TradingFinder]

🔵Introduction
Market Structure is one of the most fundamental concepts in Price Action and Smart Money theory. In simple terms, it represents how price moves between highs and lows and reveals which phase of the market cycle we are currently in uptrend, downtrend, or transition.
Each structure in the market is formed by a combination of Breaks of Structure (BoS) and Changes of Character (CHoCH):

Since price movement is inherently fractal, market structure can be analyzed on two distinct levels:
🔵Library Purpose
The “Market Structure Report Library” is designed to automatically detect the current market structure type in real time.
Without drawing or displaying any visuals, it analyzes raw price data and returns a series of logical and textual outputs (Return Values) that describe the current structural state of the market.
It provides the following information:
Trend Type:
Structure Type:
Consecutive BoS Counter: Measures trend strength on both Major and Minor levels.
Candle Type: Returns the current candle’s condition(Bullish, Bearish, Doji)
This library is specifically designed for use in Smart Money–based screeners, indicators, and algorithmic strategies.
It can analyze multiple symbols and timeframes simultaneously and return the exact structure type (BoS or CHoCH) and trend direction for each.
🔵Function Outputs
The function MS() processes the price data and returns seven key outputs,
each representing a distinct structural state of the market. These values can be used in indicators, strategies, or multi-symbol screeners.
🟣ExternalTrend
Type: string
Description: Represents the direction of the Major (External) market structure.
Possible values:
This is determined based on the behavior of Major Pivots (swing highs/lows).
🟣InternalTrend
Type: string
Description: Represents the direction of the Minor (Internal) market structure.
Possible values:
🟣M_State
Type: string
Description: Specifies the type of the latest Major Structure event.
Possible values:
🟣m_State
Type: string
Description: Specifies the type of the latest Minor Structure event.
Possible values:
🟣MBoS_Counter
Type: integer
Description: Counts the number of consecutive structural breaks (BoS) in the Major structure.
Useful for evaluating trend strength:
🟣mBoS_Counter
Type: integer
Description: Counts the number of consecutive structural breaks in the Minor structure.
Helps analyze the micro structure of the market on lower timeframes.
Higher value: strong internal trend.
Reset: indicates a minor pullback or reversal.
🟣Candle_Type
Type: string
Description: Represents the type of the current candle.
Possible values:
Pine Script®
Market Structure is one of the most fundamental concepts in Price Action and Smart Money theory. In simple terms, it represents how price moves between highs and lows and reveals which phase of the market cycle we are currently in uptrend, downtrend, or transition.
Each structure in the market is formed by a combination of Breaks of Structure (BoS) and Changes of Character (CHoCH):
- BoS occurs when the market breaks a previous high or low, confirming the continuation of the current trend.
- CHoCH occurs when price breaks in the opposite direction for the first time, signaling a potential trend reversal.
Since price movement is inherently fractal, market structure can be analyzed on two distinct levels:
- Major / External Structure: represents the dominant macro trend.
- Minor / Internal Structure: represents corrective or smaller-scale movements within the larger trend.
🔵Library Purpose
The “Market Structure Report Library” is designed to automatically detect the current market structure type in real time.
Without drawing or displaying any visuals, it analyzes raw price data and returns a series of logical and textual outputs (Return Values) that describe the current structural state of the market.
It provides the following information:
Trend Type:
- External Trend (Major): Up Trend, Down Trend, No Trend
- Internal Trend (Minor): Up Trend, Down Trend, No Trend
Structure Type:
- BoS: Confirms trend continuation
- CHoCH: Indicates a potential trend reversal
Consecutive BoS Counter: Measures trend strength on both Major and Minor levels.
Candle Type: Returns the current candle’s condition(Bullish, Bearish, Doji)
This library is specifically designed for use in Smart Money–based screeners, indicators, and algorithmic strategies.
It can analyze multiple symbols and timeframes simultaneously and return the exact structure type (BoS or CHoCH) and trend direction for each.
🔵Function Outputs
The function MS() processes the price data and returns seven key outputs,
each representing a distinct structural state of the market. These values can be used in indicators, strategies, or multi-symbol screeners.
🟣ExternalTrend
Type: string
Description: Represents the direction of the Major (External) market structure.
Possible values:
- Up Trend
- Down Trend
- No Trend
This is determined based on the behavior of Major Pivots (swing highs/lows).
🟣InternalTrend
Type: string
Description: Represents the direction of the Minor (Internal) market structure.
Possible values:
- Up Trend
- Down Trend
- No Trend
🟣M_State
Type: string
Description: Specifies the type of the latest Major Structure event.
Possible values:
- BoS
- CHoCH
🟣m_State
Type: string
Description: Specifies the type of the latest Minor Structure event.
Possible values:
- BoS
- CHoCH
🟣MBoS_Counter
Type: integer
Description: Counts the number of consecutive structural breaks (BoS) in the Major structure.
Useful for evaluating trend strength:
- Increasing count: indicates trend continuation.
- Reset to zero: typically occurs after a CHoCH.
🟣mBoS_Counter
Type: integer
Description: Counts the number of consecutive structural breaks in the Minor structure.
Helps analyze the micro structure of the market on lower timeframes.
Higher value: strong internal trend.
Reset: indicates a minor pullback or reversal.
🟣Candle_Type
Type: string
Description: Represents the type of the current candle.
Possible values:
- Bullish
- Bearish
- Doji
import TFlab/Market_Structure_Report_Library_TradingFinder/1 as MSS
PP = input.int (5 , 'Market Structure Pivot Period' , group = 'Symbol 1' )
[ExternalTrend, InternalTrend, M_State, m_State, MBoS_Counter, mBoS_Counter, Candle_Type] = MSS.MS(PP)
Pine kitaplığı
Gerçek TradingView ruhuyla, yazar bu Pine kodunu açık kaynaklı bir kütüphane olarak yayınladı, böylece topluluğumuzdaki diğer Pine programcıları onu yeniden kullanabilir. Yazara saygı! Bu kütüphaneyi özel olarak veya diğer açık kaynaklı yayınlarda kullanabilirsiniz, ancak bu kodun bir yayında yeniden kullanımı Site Kuralları tarafından yönetilmektedir.
💎Get instant (Demo/Vip) access here: tradingFinder.com/
✅Get access to our support team: t.me/TFLABS
🧠Free Forex, Crypto & Stock Trading tutorial, same as ICT, Smart Money & Price Action:
tradingfinder.com/education/forex/
✅Get access to our support team: t.me/TFLABS
🧠Free Forex, Crypto & Stock Trading tutorial, same as ICT, Smart Money & Price Action:
tradingfinder.com/education/forex/
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Pine kitaplığı
Gerçek TradingView ruhuyla, yazar bu Pine kodunu açık kaynaklı bir kütüphane olarak yayınladı, böylece topluluğumuzdaki diğer Pine programcıları onu yeniden kullanabilir. Yazara saygı! Bu kütüphaneyi özel olarak veya diğer açık kaynaklı yayınlarda kullanabilirsiniz, ancak bu kodun bir yayında yeniden kullanımı Site Kuralları tarafından yönetilmektedir.
💎Get instant (Demo/Vip) access here: tradingFinder.com/
✅Get access to our support team: t.me/TFLABS
🧠Free Forex, Crypto & Stock Trading tutorial, same as ICT, Smart Money & Price Action:
tradingfinder.com/education/forex/
✅Get access to our support team: t.me/TFLABS
🧠Free Forex, Crypto & Stock Trading tutorial, same as ICT, Smart Money & Price Action:
tradingfinder.com/education/forex/
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.