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. Подробнее читайте в Условиях использования.