OPEN-SOURCE SCRIPT

Change of Character (CHoCH) Alert System [algo_aakash]

2 660
Change of Character (CHoCH) Alert System is a market structure signal tool focused on a single event: a confirmed shift in directional bias. Rather than labeling every Break of Structure and CHoCH the way many public structure scripts do, this indicator deliberately ignores continuation breaks and limits both the chart and the alert feed to the moments where the prevailing character of the market actually flips.

Problem Statement
Most public CHoCH implementations classify a character change purely on the direction of a swing break, with no measure of how convincing that break actually was. This creates two practical issues for anyone building alerts around structure. Every minor swing wobble can trigger a notification, producing alert fatigue, and there is no way to separate a decisive character change from one that barely closed beyond the swing level. This script addresses both issues with a close-confirmed CHoCH-only detection engine and a built-in confidence grading step applied to every signal.

Methodology
The script maintains a single structure register holding the most recent confirmed swing high and swing low, located with standard pivot detection over a user-defined pivot length. When the adaptive swing filter is enabled, a newly confirmed pivot only replaces the stored swing if its distance from the last opposite-type pivot exceeds a configurable ATR-relative threshold, which keeps insignificant micro-swings out of the structure register before they can influence a signal.
A Change of Character is only evaluated on a confirmed candle close, so nothing in the detection logic repaints once a signal has printed. A bullish CHoCH requires a close above the last swing high while the tracked bias is bearish or undefined. A bearish CHoCH requires a close below the last swing low while the tracked bias is bullish or undefined. A break that occurs while the bias already agrees with the break direction is treated as ordinary continuation and is not flagged.
Two optional filters gate confirmation further. A displacement filter requires the breaking close to clear the swing level by a minimum ATR multiple, removing marginal breaks. A momentum filter requires the breakout candle's body to represent a minimum percentage of its total range, removing breaks driven mostly by wick with little real conviction behind the close.
Once a CHoCH is confirmed, the broken swing level is projected forward on the chart as an active structure line. If a later confirmed close moves back through that level, the structure is marked invalidated and the projection line is dimmed, separately from the detection of any new CHoCH.

Signal Workflow
Track the most recent confirmed swing high and swing low using pivot detection.
Apply the adaptive swing filter to reject pivots too close to the last opposite-type pivot.
On each confirmed candle close, test for a close beyond the stored swing level against the current bias.
Apply the displacement filter to confirm the close cleared the level by a minimum ATR multiple.
Apply the momentum filter to confirm the breakout candle's body-to-range ratio meets the minimum threshold.
Score the confirmed breakout candle on displacement in ATR units and body-to-range ratio to produce a Weak, Moderate, or Strong confidence grade.
Flip the tracked bias, plot the CHoCH label with its grade, and project the broken level forward as an active structure line.
Continue monitoring the active structure line and mark it invalidated if a later confirmed close moves back through it.

Why This Indicator Is Different
Many structure tools plot every Break of Structure alongside every CHoCH, leaving the trader to filter out which events represent an actual change in character.
This script omits BOS events entirely and reports only confirmed CHoCH signals, which are the events that correspond to a bias flip.
Each confirmed CHoCH is scored using two independent factors measured on the breakout candle itself, its ATR-normalized displacement past the level and its body-to-range ratio, rather than being treated as a single undifferentiated event.
The confidence grade is written into the alert message text at the moment the event fires, which requires composing the message dynamically rather than relying on a fixed template.
The swing level broken by a CHoCH remains tracked after the signal fires, so a later close back through that level produces a distinct invalidation alert rather than silently vanishing into the next structure calculation.
Detection is restricted to confirmed candle closes throughout, so the bias, the grade, and the invalidation state cannot change intrabar once printed.

Inputs
Structure Engine
Swing Pivot Length
Adaptive Swing Filter
Filter Threshold (ATR multiple)
Break Confirmation
Displacement Filter
Displacement Multiplier
Momentum Filter
Minimum Body % of Range
ATR Length
Visual Settings
Show Swing Points
Show Structure Projection
Projection Extension
Show Trend Background Wash
Color Candles After CHoCH
Show Confidence Grade
Label Size
Bullish, Bearish, and Projection colors
Status Panel
Show Status Panel
Panel Position
Alerts
Alert: Bullish CHoCH
Alert: Bearish CHoCH
Alert: Bullish Structure Invalidated
Alert: Bearish Structure Invalidated

Alerts
Alerts are available for:
Bullish CHoCH confirmed on a closed candle, with the confidence grade included in the alert message
Bearish CHoCH confirmed on a closed candle, with the confidence grade included in the alert message
Bullish structure invalidated after a confirmed close back below an active bullish level
Bearish structure invalidated after a confirmed close back above an active bearish level

Practical Usage
Use a shorter pivot length on intraday charts to react to structure earlier, combined with the displacement and momentum filters to avoid marginal breaks.
Use a longer pivot length on higher timeframes to isolate structurally significant character changes only.
Treat a Strong-grade CHoCH as a higher-conviction event than a Weak-grade CHoCH when weighing entry timing or position sizing.
Watch for a structure invalidated alert shortly after a CHoCH, since it indicates price has returned through the level that produced the signal.
Use the status panel as a quick reference for the current bias and the most recent CHoCH grade without needing to scan the chart for labels.

Limitations
Swing highs and lows depend on confirmed pivots, which require the full pivot length of bars to close on both sides before becoming available, introducing a disclosed confirmation lag.
The displacement and momentum filters reduce signal frequency by design, which means fewer but more selective CHoCH events compared to unfiltered structure break detection.
Structure invalidation reflects a return through a previously broken level and does not attempt to forecast subsequent price direction.
This indicator identifies structural events only and does not constitute financial advice or a complete trading system on its own.

Notes
All structural state, including the tracked bias, the active levels, and the confidence grade, is evaluated only on a confirmed candle close, so nothing in this script repaints once printed.
The only lag in the system is the standard pivot confirmation lag inherent to pivot-based swing detection, which is disclosed above rather than hidden.
Designed for dark theme charts. On light themes, consider darkening the projection line color for improved contrast.

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.