OPEN-SOURCE SCRIPT
تم تحديثه

Market Structure + CHoCH/MSS/BOS | Xcelerate Trade

896
Market Structure + CHoCH / MSS / BOS | Xcelerate Trade
A precise market-structure mapper from the Xcelerate Trade team. It auto-detects swing highs / lows, classifies every break of structure as CHoCH (Change of Character), MSS (Market Structure Shift) or BOS (Break of Structure), and labels each pivot as HH / HL / LH / LL. Designed for SMC and price-action traders who want a clean, repaint-aware structural read of the chart.

What you get on the chart
Swing labels: HH (Higher High), HL (Higher Low), LH (Lower High), LL (Lower Low) — auto-placed on every detected pivot.
Break lines: every confirmed break is drawn as a horizontal segment from the swing bar to the breaking bar.
Break tags: each break line gets a label — CHoCH, MSS or BOS — so you can read structure at a glance.
Info table (top-right): current settings (Auto / Manual, TF, L/R, detection method, MSS definition, break validation) and an optional debug panel with trend state, flags, pre-CHoCH levels, last-break details.
Pattern alerts: ready-to-use alertcondition for HH-HL-HH and LL-LH-LL sequences.
Pivot detection — two modes
Williams Fractals (default): classic ta.pivothigh / ta.pivotlow with separate left and right lengths. Configurable in Manual Settings (defaults L = 6, R = 4) or selected automatically per timeframe via Auto Timeframe Settings:

Timeframe L / R
1m
4 / 4
5m
4 / 3
15m
5 / 4
30m+, daily, weekly, monthly
6 / 4
Simple Fractals: SMC-style, symmetric — current bar is a pivot if it's the highest / lowest within simpleFractalPeriod bars on each side. Faster but more frequent than Williams.

You can also force Wait for bar close (default ON) to confirm pivots only on closed bars.

Break validation — 4 modes
Choose how a level is considered "broken":

Close — close beyond the swing level (cleanest, default).
High/Low (wick) — wick beyond the level (most aggressive).
Close beyond buffer (ticks) — close beyond level ± N × mintick.
Close beyond buffer (%) — close beyond level ± X%.
Buffer fields appear conditionally so you can tune the strictness of structure breaks per instrument (forex, indices, crypto, etc.).

Structure classification — CHoCH / MSS / BOS
Trend state is tracked internally (Bullish, Bearish, Neutral). Every confirmed break is then classified:

CHoCH — first break that reverses the trend (bullish CHoCH on a close above the last swing high while bearish; bearish CHoCH on a close below the last swing low while bullish), or the very first break when the trend is still neutral. CHoCH flips the trend and starts a fresh leg.

MSS — first qualifying break in the direction of the new trend after CHoCH, per the MSS definition setting:

First break after CHoCH — any first break in trend direction = MSS, then BOS.
First break >= pre-CHoCH level — MSS only when the broken swing is at or beyond the swing level that existed before the CHoCH. Stricter — protects against premature MSS calls.
HL + >= pre-CHoCH (legacy) — same as above, plus a confirming HL (bull) / LH (bear) is required after CHoCH before MSS can fire.
BOS — every subsequent break in the trend direction after MSS — until the opposite CHoCH occurs and the cycle restarts.

This rule set keeps only one MSS per trend leg, with everything before it being CHoCH and everything after being BOS — exactly how SMC traders read it.

Pre-CHoCH levels (transparent reasoning)
When CHoCH fires, the script captures the swing-high / swing-low that existed before the trend flip (pre_choch_swing_high / pre_choch_swing_low). These are used by the stricter MSS modes and shown in the debug rows of the info table, so you can verify exactly why a break was classified as MSS or BOS.

Last broken swing tracking
For every confirmed break the indicator stores:

lastBreakSwingBarIndex — the bar where the broken swing originally formed (its ID).
lastBreakSwingPrice — the level that was broken.
lastBreakClassification — CHoCH / MSS / BOS.
lastBreakDirection — above swing high / below swing low.
lastBreakDetectBarIndex — the bar where the break passed your validation filter.
These are visible in the debug rows when Show debug rows (table) is on — useful for forensic / journal-style review.

Drawing budget (FIFO)
The indicator caps the number of CHoCH / MSS / BOS line + label pairs at Max CHoCH/MSS/BOS lines + labels (default 400, max ~80% of TradingView's 500 limit). Older drawings are removed first (FIFO), so you never hit the line cap on long histories.

Alerts
Two ready-to-use alert conditions:

HH-HL-HH Alert — fires when an HH-HL-HH pattern completes.
LL-LH-LL Alert — fires when an LL-LH-LL pattern completes.
Use TradingView's alert dialog → choose the alert condition by name. Messages include {{ticker}} and {{interval}} placeholders.

Suggested settings (from the Xcelerate Trade team)
Default for most traders: Auto settings ON, Williams Fractals, Wait for bar close ON, Break validation = Close, MSS definition = First break after CHoCH.
Strict structural read (low noise): Break validation = Close beyond buffer (%) with 0.05–0.10%, MSS definition = First break >= pre-CHoCH level.
Aggressive / fast feedback: Simple Fractals with period 2, Break validation = High/Low (wick), Wait for bar close = OFF.
Forensic review: turn ON Show debug rows (table) to see trend state, CHoCH / MSS flags, pre-CHoCH levels and the last-break summary.
Notes & disclaimers
Williams Fractals confirm with a delay equal to the right-length (R bars). This is intentional — pivots are not repainted after confirmation.
Simple Fractals confirm with a delay equal to simpleFractalPeriod bars.
This is an analytical tool — no automated buy / sell labels. Pair with your own execution rules.
Pine Script v6.
Built and maintained by the Xcelerate Trade team. A complete CHoCH / MSS / BOS market-structure read with HH / HL / LH / LL labels, four break-validation modes, three MSS definition modes, an info / debug table and ready alert conditions.
ملاحظات الأخبار
Market Structure + CHoCH / MSS / BOS | Xcelerate Trade
A precise market-structure mapper from the Xcelerate Trade team. It auto-detects swing highs / lows, classifies every break of structure as CHoCH (Change of Character), MSS (Market Structure Shift) or BOS (Break of Structure), and labels each pivot as HH / HL / LH / LL. Designed for SMC and price-action traders who want a clean, repaint-aware structural read of the chart.

What you get on the chart
Swing labels: HH (Higher High), HL (Higher Low), LH (Lower High), LL (Lower Low) — auto-placed on every detected pivot.
Break lines: every confirmed break is drawn as a horizontal segment from the swing bar to the breaking bar.
Break tags: each break line gets a label — CHoCH, MSS or BOS — so you can read structure at a glance.
Info table (top-right): current settings (Auto / Manual, TF, L/R, detection method, MSS definition, break validation) and an optional debug panel with trend state, flags, pre-CHoCH levels, last-break details.
Pattern alerts: ready-to-use alertcondition for HH-HL-HH and LL-LH-LL sequences.
Pivot detection — two modes
Williams Fractals (default): classic ta.pivothigh / ta.pivotlow with separate left and right lengths. Configurable in Manual Settings (defaults L = 6, R = 4) or selected automatically per timeframe via Auto Timeframe Settings:

Timeframe L / R
1m
4 / 4
5m
4 / 3
15m
5 / 4
30m+, daily, weekly, monthly
6 / 4
Simple Fractals: SMC-style, symmetric — current bar is a pivot if it's the highest / lowest within simpleFractalPeriod bars on each side. Faster but more frequent than Williams.

You can also force Wait for bar close (default ON) to confirm pivots only on closed bars.

Break validation — 4 modes
Choose how a level is considered "broken":

Close — close beyond the swing level (cleanest, default).
High/Low (wick) — wick beyond the level (most aggressive).
Close beyond buffer (ticks) — close beyond level ± N × mintick.
Close beyond buffer (%) — close beyond level ± X%.
Buffer fields appear conditionally so you can tune the strictness of structure breaks per instrument (forex, indices, crypto, etc.).

Structure classification — CHoCH / MSS / BOS
Trend state is tracked internally (Bullish, Bearish, Neutral). Every confirmed break is then classified:

CHoCH — first break that reverses the trend (bullish CHoCH on a close above the last swing high while bearish; bearish CHoCH on a close below the last swing low while bullish), or the very first break when the trend is still neutral. CHoCH flips the trend and starts a fresh leg.

MSS — first qualifying break in the direction of the new trend after CHoCH, per the MSS definition setting:

First break after CHoCH — any first break in trend direction = MSS, then BOS.
First break >= pre-CHoCH level — MSS only when the broken swing is at or beyond the swing level that existed before the CHoCH. Stricter — protects against premature MSS calls.
HL + >= pre-CHoCH (legacy) — same as above, plus a confirming HL (bull) / LH (bear) is required after CHoCH before MSS can fire.
BOS — every subsequent break in the trend direction after MSS — until the opposite CHoCH occurs and the cycle restarts.

This rule set keeps only one MSS per trend leg, with everything before it being CHoCH and everything after being BOS — exactly how SMC traders read it.

Pre-CHoCH levels (transparent reasoning)
When CHoCH fires, the script captures the swing-high / swing-low that existed before the trend flip (pre_choch_swing_high / pre_choch_swing_low). These are used by the stricter MSS modes and shown in the debug rows of the info table, so you can verify exactly why a break was classified as MSS or BOS.

Last broken swing tracking
For every confirmed break the indicator stores:

lastBreakSwingBarIndex — the bar where the broken swing originally formed (its ID).
lastBreakSwingPrice — the level that was broken.
lastBreakClassification — CHoCH / MSS / BOS.
lastBreakDirection — above swing high / below swing low.
lastBreakDetectBarIndex — the bar where the break passed your validation filter.
These are visible in the debug rows when Show debug rows (table) is on — useful for forensic / journal-style review.

Drawing budget (FIFO)
The indicator caps the number of CHoCH / MSS / BOS line + label pairs at Max CHoCH/MSS/BOS lines + labels (default 400, max ~80% of TradingView's 500 limit). Older drawings are removed first (FIFO), so you never hit the line cap on long histories.

Alerts
Two ready-to-use alert conditions:

HH-HL-HH Alert — fires when an HH-HL-HH pattern completes.
LL-LH-LL Alert — fires when an LL-LH-LL pattern completes.
Use TradingView's alert dialog → choose the alert condition by name. Messages include {{ticker}} and {{interval}} placeholders.

Suggested settings (from the Xcelerate Trade team)
Default for most traders: Auto settings ON, Williams Fractals, Wait for bar close ON, Break validation = Close, MSS definition = First break after CHoCH.
Strict structural read (low noise): Break validation = Close beyond buffer (%) with 0.05–0.10%, MSS definition = First break >= pre-CHoCH level.
Aggressive / fast feedback: Simple Fractals with period 2, Break validation = High/Low (wick), Wait for bar close = OFF.
Forensic review: turn ON Show debug rows (table) to see trend state, CHoCH / MSS flags, pre-CHoCH levels and the last-break summary.
Notes & disclaimers
Williams Fractals confirm with a delay equal to the right-length (R bars). This is intentional — pivots are not repainted after confirmation.
Simple Fractals confirm with a delay equal to simpleFractalPeriod bars.
This is an analytical tool — no automated buy / sell labels. Pair with your own execution rules.
Pine Script v6.
Built and maintained by the Xcelerate Trade team. A complete CHoCH / MSS / BOS market-structure read with HH / HL / LH / LL labels, four break-validation modes, three MSS definition modes, an info / debug table and ready alert conditions.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.