OPEN-SOURCE SCRIPT
Market Structure Trend [Datapro]

Market Structure Trend Matrix [Datapro]
Overview
The **Market Structure Trend Matrix** is a technical analysis overlay designed to identify trend direction and potential reversal points based on Market Structure concepts (specifically **Break of Structure** and **Change of Character - ChoCh**).
This script updates the original logic by implementing robust Pine Script v6 architecture, solving historical calculation inconsistencies (CW10002), and adding an institutional-grade dashboard for real-time data monitoring. It is designed for traders who need clear visual cues for entry, stop-loss management, and target projection.
How It Works
The core logic relies on **Pivot Highs** and **Pivot Lows** to define market structure.
1. **Trend Detection:**
* A **Bullish Trend** is initiated when price closes above a confirmed Pivot High (ChoCh ↑).
* A **Bearish Trend** is initiated when price closes below a confirmed Pivot Low (ChoCh ↓).
2. **ATR Trailing Stop:**
* Once a trend is established, the script plots a dynamic trailing stop using the **Average True Range (ATR)**. This stop trails the price to help protect open profits during the trend lifecycle.
3. **Target System:**
* The script automatically projects sequential targets based on a user-defined ATR multiplier step. This helps traders scale out of positions systematically.
Key Features
* **Structure-Based Signals:** Identifies "ChoCh" (Change of Character) points which often signify the start of a new trend or a deep pullback.
* **Dynamic ATR Stop:** A volatility-based trailing stop that adapts to market conditions, providing breathing room during volatile swings.
* **Auto-Scaling Targets:** Visualizes potential take-profit levels calculated from the structural entry point.
* **Institutional Dashboard:** A compact table displaying the current Structure Bias, Entry Price, Next Target, Trailing Stop value, and Cycle PnL.
* **HFT Data Export:** Hidden plots are included for strategy integration, allowing external systems or webhooks to fetch entry, target, and stop values without visual clutter.
* **Performance Optimized:** Code is audited to prevent memory leaks (FIFO object management) and ensure consistent calculation on every bar.
How to Use
1. **Trend Confirmation:** Look for the **ChoCh** label and the colored structure line. This indicates a potential shift in market sentiment.
2. **Entry:** Traders often enter on the close of the bar that triggers the ChoCh signal or on a retest of the broken structure level.
3. **Stop Loss:** Use the **ATR Trailing Stop** line (dashed) as a guide for placing initial stops and trailing them as the trend progresses.
4. **Exit:** Take profit at the projected "Target" lines or exit entirely if price crosses the Trailing Stop, signaling a trend invalidation.
Settings
* **Market Structure Length:** Defines the sensitivity of the pivot detection (left/right lookback). Higher values filter out minor swings; lower values detect short-term structure.
* **ATR Multiplier:** Controls the distance of the trailing stop from the price. Higher values result in wider stops (fewer false exits).
* **Target Step:** Defines the vertical distance between consecutive target levels.
---
Credits & License
* **Original Concept:** BigBeluga
* **Refactor & Optimization:** datapro
* **License:** CC BY-NC-SA 4.0
---
**DISCLAIMER**
Licensed under MPL 2.0. Attribution required.
**NO FINANCIAL ADVICE.** The information provided by this script is for educational and informational purposes only. It is not intended as financial advice. Trading involves significant risk of loss and is not suitable for every investor. Past performance is not indicative of future results. Use at your own risk. Provided "AS IS".
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。