OPEN-SOURCE SCRIPT
Trend Integrity Oscillator [MQLSoftware]

Trend Integrity Oscillator answers one question in a measurable way: is the current pullback a pause inside an intact trend, or the start of a reversal? Instead of pairing two generic oscillators and eyeballing their relationship, it separates the two things that actually diverge in a pullback — trend efficiency and structural integrity — and then measures the outcome of that divergence on the chart's own history.
This is a visual analytical tool for chart study. It does not execute trades and does not provide financial advice.
Key Features
Core Concept — what is original here
1. Multiscale signed efficiency. sER(n) = (close − close[n]) / path(n): a Kaufman-style efficiency ratio kept with its sign. +1 means the last n bars traveled their entire path upward, −1 downward, ~0 churn. Three horizons are blended 0.5/0.3/0.2 with the seniors heaviest, and everything is computed straight on chart bars — the script contains zero request.security calls, so the higher-timeframe re-resolution bug class is structurally impossible.
2. Structure Integrity 0–100. Not a second oscillator but a composite of three confirmed-pivot facts: (a) anchor hold — how firmly price holds the structural anchor pivot, ATR-scaled; (b) pivot-chain consistency — the share of recent pivot steps that agree with the structural direction; (c) retracement depth — the live pullback ranked as a percentile against the depths of pullbacks on this chart that eventually resumed. Self-calibrating; no fixed depth settings.
3. The pullback state machine. ARMED = trend efficiency flips against the trend while the structure holds. RESUMED = efficiency recovers, or price prints a confirmed close beyond the pre-pullback extreme. BROKEN = a confirmed close beyond the anchor pivot as it stood when the pullback started — a reversal, not a pullback. A structural direction flip during an armed episode counts as a failed pullback; nothing is silently dropped.
4. Measured base rates. The panel reports observed frequencies with sample sizes — measured per chart, per direction, not asserted. Below 10 completed episodes the panel says "collecting" instead of quoting noise.
Anatomy of the Display
On the price chart (the overlay layer):
In the oscillator pane:
Notes on Repainting
Typical Analysis Workflow
Configuration
Markets and Timeframes
Any symbol and timeframe. The engine is percentile- and ATR-based, so it self-calibrates per instrument. On low-history charts the panel reports "collecting" until the sample is real.
Alerts
Pullback armed · Trend resumed · Structure broken · Alignment started · Deep pullback (live depth crossed P75 of resumed history, once per episode) · plus one dynamic alert() with direction and integrity context.
This is a visual analytical tool for chart study. It does not execute trades and does not provide financial advice.
Key Features
- Outcome signals on the price chart: when a pullback resumes, the ▲/▼ marker prints this chart's measured resume rate for that direction; when the structure is closed through, ✕ BREAK prints at the violated anchor
- Pullback Survival Zone on the price chart: while a pullback is armed, the pullback territory is shaded and the survival line marks the P75 depth of all pullbacks on this chart that eventually resumed — between that line and the anchor is territory most survivors never visited
- Anchor line — the structural pivot whose confirmed close-through turns a pullback into a reversal (frozen at arm time for the live episode)
- Trend Efficiency line 0–100 — multiscale signed efficiency computed on three horizons (chart window plus two senior windows equal in wall-clock time to auto-selected higher timeframes), weighted toward the seniors
- Structure Integrity area 0–100 — a composite of three confirmed-pivot facts: anchor hold, pivot-chain consistency, and retracement depth ranked against this chart's own resumed pullbacks
- Pullback state machine — aligned → pullback armed → resumed / broken, confirmed bars only
- Measured base rates in the panel: how often armed pullbacks actually resumed on this chart, per direction, with sample sizes; live pullback depth percentile
- Phase lane, pane event marks, optional armed bar-paint and pane tint, five alerts + one dynamic alert
Core Concept — what is original here
1. Multiscale signed efficiency. sER(n) = (close − close[n]) / path(n): a Kaufman-style efficiency ratio kept with its sign. +1 means the last n bars traveled their entire path upward, −1 downward, ~0 churn. Three horizons are blended 0.5/0.3/0.2 with the seniors heaviest, and everything is computed straight on chart bars — the script contains zero request.security calls, so the higher-timeframe re-resolution bug class is structurally impossible.
2. Structure Integrity 0–100. Not a second oscillator but a composite of three confirmed-pivot facts: (a) anchor hold — how firmly price holds the structural anchor pivot, ATR-scaled; (b) pivot-chain consistency — the share of recent pivot steps that agree with the structural direction; (c) retracement depth — the live pullback ranked as a percentile against the depths of pullbacks on this chart that eventually resumed. Self-calibrating; no fixed depth settings.
3. The pullback state machine. ARMED = trend efficiency flips against the trend while the structure holds. RESUMED = efficiency recovers, or price prints a confirmed close beyond the pre-pullback extreme. BROKEN = a confirmed close beyond the anchor pivot as it stood when the pullback started — a reversal, not a pullback. A structural direction flip during an armed episode counts as a failed pullback; nothing is silently dropped.
4. Measured base rates. The panel reports observed frequencies with sample sizes — measured per chart, per direction, not asserted. Below 10 completed episodes the panel says "collecting" instead of quoting noise.
Anatomy of the Display
On the price chart (the overlay layer):
- Survival Zone while a pullback is armed: neutral slate = ordinary pullback territory, amber band = deeper than 75% of this chart's resumed pullbacks, dotted amber = the survival line, solid line = the frozen anchor
- ▲/▼ resume markers with the measured per-direction resume rate printed on them (tooltip: bars in pullback, max depth, base rate with n)
- ✕ BREAK marker at the anchor price on the confirmed close-through
- Optional amber bar tint while armed (off by default)
In the oscillator pane:
- Trend Efficiency line — teal above the bull threshold, ember below the bear threshold; brighter when |efficiency| is high; soft glow
- Structure Integrity — quiet slate area (3-bar display smoothing; the engine reads the raw series); turns amber while a pullback is armed
- Midline 50 and dotted 60/40 guides — the guides sit exactly on the direction-flip hysteresis thresholds
- Phase lane (top strip): trend color = aligned, amber = pullback armed, grey = no established state
- Pane event marks: • pullback armed, ▲/▼ trend resumed, ✕ structure broken; optional pane tint while armed
- Panel: Trend, Structure (tooltip shows the three components), State, base rates per direction, live pullback depth percentile
Notes on Repainting
- All state transitions, signal markers, base-rate counters and alerts fire on confirmed bars only and never move once printed
- The oscillator lines, the live zone's right edge, the anchor line and the panel's live rows update intrabar — visual context, not signals
- The survival line and the episode anchor are frozen at arm time — they do not follow price during the episode
- Pivots confirm with the standard pivot lag (Pivot Length bars each side) and never move once confirmed
- No request.security anywhere in the script
Typical Analysis Workflow
- Read the State row: ALIGNED means efficiency and structure agree; NO ALIGNMENT means stand aside or dig deeper
- When PULLBACK ARMED appears, check the live depth percentile — a pullback deeper than most that ever resumed deserves more suspicion
- Use the base rates as context: a market where pullbacks resume 50% of the time is a coin flip and the panel will say so honestly
- Treat ✕ structure broken as the line between "pullback" and "reversal" — the anchor pivot was closed through
Configuration
- Response: Fast / Balanced / Strict — measured smoothing presets, not guesses
- Auto Senior Horizons on by default; two manual timeframe inputs when disabled
- Pivot Length, Min Integrity to Arm
- Chart Overlay group: signals on price, survival zone, completed episodes to keep, anchor line mode (During pullbacks / Always / Off), bar paint, pane tint
- All identity colors are inputs (dark-theme defaults; pick deeper tones on light charts)
Markets and Timeframes
Any symbol and timeframe. The engine is percentile- and ATR-based, so it self-calibrates per instrument. On low-history charts the panel reports "collecting" until the sample is real.
Alerts
Pullback armed · Trend resumed · Structure broken · Alignment started · Deep pullback (live depth crossed P75 of resumed history, once per episode) · plus one dynamic alert() with direction and integrity context.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
🟣 Free tools, guides & product resources:
mqlsoftware.com/account/
🟣 New tools, releases & updates:
t.me/mqlsoftware_official
MQLSoftware — trading analysis tools & indicators.
mqlsoftware.com/account/
🟣 New tools, releases & updates:
t.me/mqlsoftware_official
MQLSoftware — trading analysis tools & indicators.
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
🟣 Free tools, guides & product resources:
mqlsoftware.com/account/
🟣 New tools, releases & updates:
t.me/mqlsoftware_official
MQLSoftware — trading analysis tools & indicators.
mqlsoftware.com/account/
🟣 New tools, releases & updates:
t.me/mqlsoftware_official
MQLSoftware — trading analysis tools & indicators.
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。