PINE LIBRARY
MarketStructureLib

MarketStructure Library
This library extends the "MarketStructure" library by mickes (tradingview.com/script/tqFlUGel-MarketStructure/) under the Mozilla Public License 2.0, credited to mickes. It provides functions for detecting and visualizing market structure, including Break of Structure (BOS), Change of Character (CHoCH), Equal High/Low (EQH/EQL), and liquidity zones, with enhancements for improved accuracy and customization.
Functionality
Market Structure Detection: Identifies internal (orderflow) and swing market structures using pivot points, with support for BOS, CHoCH, and EQH/EQL.
Volatility Filter: Only confirms pivots when the ATR exceeds a user-defined threshold, reducing false signals in low-volatility markets.
Trend Strength Metric: Calculates a trend strength score based on pivot frequency and volatility, stored in the Structure type for use in scripts.
Customizable Visualizations: Allows users to configure line styles and colors for BOS and CHoCH, and label sizes for pivots, BOS, CHoCH, and liquidity.
Liquidity Zones: Visualizes liquidity levels with confirmation bars and lookback periods.
Methodology
Pivot Detection: Uses ta.pivothigh and ta.pivotlow with a volatility filter (ATR multiplier) to confirm significant pivots.
Trend Strength: Computes a score as pivotCount / LeftLength * (currentATR / ATR), reflecting trend reliability based on pivot frequency and market volatility.
BOS/CHoCH Logic: Detects BOS when price breaks a pivot in the trend direction, and CHoCH when price reverses against the trend, with labels for "MSF" or "MSF+" based on pivot patterns.
EQH/EQL Zones: Creates boxes around equal highs/lows within an ATR-based threshold, with optional extension.
Visualization: Draws lines and labels for BOS, CHoCH, and liquidity, with user-defined styles, colors, and sizes.
Usage
Integration: Import into Pine Script indicators (e.g., import Fenomentn/MarketStructure/1) to analyze market structure.
Configuration: Set pivot lengths, volatility threshold, label sizes, and visualization styles via script inputs.
Alerts: Enable alerts for BOS, CHoCH, and EQH/EQL events, triggered on bar close to avoid repainting.
Best Practices: Use on forex or crypto charts (1m to 12h timeframes) for optimal results. Adjust the volatility threshold for different market conditions.
Originality
This library builds on mickes’ framework by adding:
A volatility-based pivot filter to enhance signal accuracy.
A trend strength metric for assessing trend reliability.
Dynamic label sizing and customizable visualization styles for better usability. No additional open-source code was reused beyond mickes’ library, credited under MPL 2.0.
Developed by Fenomentn. Published under Mozilla Public License 2.0.
This library extends the "MarketStructure" library by mickes (tradingview.com/script/tqFlUGel-MarketStructure/) under the Mozilla Public License 2.0, credited to mickes. It provides functions for detecting and visualizing market structure, including Break of Structure (BOS), Change of Character (CHoCH), Equal High/Low (EQH/EQL), and liquidity zones, with enhancements for improved accuracy and customization.
Functionality
Market Structure Detection: Identifies internal (orderflow) and swing market structures using pivot points, with support for BOS, CHoCH, and EQH/EQL.
Volatility Filter: Only confirms pivots when the ATR exceeds a user-defined threshold, reducing false signals in low-volatility markets.
Trend Strength Metric: Calculates a trend strength score based on pivot frequency and volatility, stored in the Structure type for use in scripts.
Customizable Visualizations: Allows users to configure line styles and colors for BOS and CHoCH, and label sizes for pivots, BOS, CHoCH, and liquidity.
Liquidity Zones: Visualizes liquidity levels with confirmation bars and lookback periods.
Methodology
Pivot Detection: Uses ta.pivothigh and ta.pivotlow with a volatility filter (ATR multiplier) to confirm significant pivots.
Trend Strength: Computes a score as pivotCount / LeftLength * (currentATR / ATR), reflecting trend reliability based on pivot frequency and market volatility.
BOS/CHoCH Logic: Detects BOS when price breaks a pivot in the trend direction, and CHoCH when price reverses against the trend, with labels for "MSF" or "MSF+" based on pivot patterns.
EQH/EQL Zones: Creates boxes around equal highs/lows within an ATR-based threshold, with optional extension.
Visualization: Draws lines and labels for BOS, CHoCH, and liquidity, with user-defined styles, colors, and sizes.
Usage
Integration: Import into Pine Script indicators (e.g., import Fenomentn/MarketStructure/1) to analyze market structure.
Configuration: Set pivot lengths, volatility threshold, label sizes, and visualization styles via script inputs.
Alerts: Enable alerts for BOS, CHoCH, and EQH/EQL events, triggered on bar close to avoid repainting.
Best Practices: Use on forex or crypto charts (1m to 12h timeframes) for optimal results. Adjust the volatility threshold for different market conditions.
Originality
This library builds on mickes’ framework by adding:
A volatility-based pivot filter to enhance signal accuracy.
A trend strength metric for assessing trend reliability.
Dynamic label sizing and customizable visualization styles for better usability. No additional open-source code was reused beyond mickes’ library, credited under MPL 2.0.
Developed by Fenomentn. Published under Mozilla Public License 2.0.
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。