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提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。