PROTECTED SOURCE SCRIPT

MARKET Structure + MTF Dashboard

303
This script automatically detects market structure shifts and visualizes:


Bullish BOS (Break of Structure)


Bearish BOS


Bullish CHoCH (Change of Character)


Bearish CHoCH


On top of that, it shows a multi-timeframe dashboard in the top-right corner of the chart, so you can instantly see the latest structure event on:


1m


6m


36m


216m


1D


regardless of which timeframe you are currently viewing.

Core Logic
The script is built around swing highs / swing lows using ta.pivothigh and ta.pivotlow.


Pivot Definition


A swing high / low is defined by:


lb = left bars


rb = right bars


A pivot high is a bar whose high is higher than the previous lb bars and the next rb bars.
A pivot low is a bar whose low is lower than the previous lb bars and the next rb bars.


Break Conditions


After a pivot is confirmed, the script waits at least N bars (minBarsAfterPivot) before accepting any break of that pivot level as a valid structure event.
You can choose how to define the break:


Close-based (닫기) – use candle close


Wick-based (없음 or 꼬리) – use high/low (full wick)




BOS vs CHoCH Classification


For each timeframe, the script tracks structure breaks and classifies them:


A move breaking above the last swing high → upward break


A move breaking below the last swing low → downward break


Then:


If the current break direction is the same as the previous break
→ it is classified as BOS (trend continuation)


If the current break direction is the opposite of the previous break
→ it is classified as CHoCH (trend reversal / change of character)


Return codes (internally):


1 = Bullish BOS


2 = Bullish CHoCH


-1 = Bearish BOS


-2 = Bearish CHoCH


0 = no event



Chart Annotations
On the active chart timeframe, the script can optionally show:


Structure lines:


Horizontal lines at the price level where BOS / CHoCH occurred


Lines extend to the left until the first candle that previously touched that price zone




Labels:


“Bull BOS”, “Bear BOS”, “Bull CHoCH”, “Bear CHoCH”


Fully color-customizable (line color, label background, text color, transparency)




You can also enable/disable pivot labels (HH, HL, LL, LH) for swing highs and lows, with separate toggles for:


HH / LL


HL / LH



Multi-Timeframe Dashboard
The dashboard in the top-right corner shows, for each timeframe:


1m / 6m / 36m / 216m / 1D


The last structure event (Bull BOS, Bull CHoCH, Bear BOS, Bear CHoCH, or None)


Colored background by event type:


Strong green / red for CHoCH


Softer green / red for BOS


Gray for None




The important part:
Each timeframe’s state is calculated inside that timeframe itself and then pulled via request.security().
That means:

No matter which chart timeframe you are currently on,
the dashboard always shows the same last event for each TF.


Inputs


Pivot lb / Pivot rb
Control how “wide” a swing must be to be accepted as a pivot.


Breakout 기준 (Confirm type)


Close-based or wick-based break logic.




피봇 이후 최소 대기 캔들 수 (Min bars after pivot)
Minimum number of bars that must pass after a pivot forms before a break can count as BOS / CHoCH.
This filters out very early / noisy breaks.


Toggles:


Show pivot balloons (HH/HL/LL/LH)


Show BOS


Show CHoCH




Visual:


Line colors for each event type


Line transparency


Label background transparency


Label text color





Alerts
The script defines alert conditions for:


Bullish BOS


Bearish BOS


Bullish CHoCH


Bearish CHoCH


You can use them to trigger notifications when a new structure event occurs on the active timeframe.

Notes & Usage


This is a market structure helper, not a complete trading system.


BOS / CHoCH should be used together with:


Liquidity zones


Volume / delta


Orderflow or higher-timeframe context




Parameters like lb, rb, and minBarsAfterPivot are intentionally exposed so you can tune:


Sensitivity vs. reliability


Scalping vs. swing-structure




This script is for educational purposes only and does not constitute financial advice.
Always backtest and combine with your own trading plan and risk management.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.