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脚本库
本着真正的TradingView精神,作者将此Pine代码发布为开源库,以便我们社区的其他Pine程序员可以重复使用它。向作者致敬!您可以私密或在其他开源出版物中使用此库,但在出版物中重复使用此代码受网站规则约束。
💎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/
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
Pine脚本库
本着真正的TradingView精神,作者将此Pine代码发布为开源库,以便我们社区的其他Pine程序员可以重复使用它。向作者致敬!您可以私密或在其他开源出版物中使用此库,但在出版物中重复使用此代码受网站规则约束。
💎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/
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。