OPEN-SOURCE SCRIPT
Aggiornato

Tail-Risk & Fragility Oscillator

303
Tail-Risk & Fragility Oscillator

A risk-shape meter — not a buy/sell oscillator. It measures the asymmetry (skewness) and tail-fatness (excess kurtosis) of recent returns to answer one question your momentum and trend tools cannot: is fragile, fat-tailed risk building right now, and on which side? It reads this in plain language, optionally from higher-resolution "realized" data, and forward-calibrates whether those fragile states have actually preceded moves on the symbol you're viewing.

Why these parts are combined (not a mashup for show). Skewness says which tail is heavier (where a violent move is more likely to come from). Excess kurtosis says how heavy the tails are (how likely an outsized move is at all). Neither alone is "fragility" — fragility is one tail heavy AND tails fattening together — so both are combined into one reading. Realized estimation (optional) measures these moments from intrabar returns rather than one value per bar, far less noisy. And a Cornish-Fisher value-at-risk turns skew + kurtosis into a single "expected bad-case move" you can size against. Together they form one coherent tail-risk tool.

How it works. Returns feed central moments over a window: skew = m3/σ³, excess kurtosis = m4/m2² − 3. With "Realized" on, the moments come from a lower-timeframe return stream (confirmed only). The signed wave is standardized skewness; a percentile of kurtosis flags fat tails; a Cornish-Fisher quantile combines both, scaled to the chart timeframe over the calibration horizon, into a value-at-risk. A "fragile-down" state (negative-skew extreme + fat tails) is then scored for a subsequent down move and "fragile-up" for an up move, using triple-barrier outcomes, split into in-sample and recent out-of-sample, with a confidence interval and a multiple-testing check.

How to use. Read the Verdict row — "Downside-fragile" / "Upside-fragile" means a heavy tail is building on that side; "Tails normal" means no fragility. The Conviction row says whether that state has actually preceded the expected move on this symbol. Use it to size down, widen stops, or expect violence on the fragile side — layered on your own directional tool, never as a standalone entry. The "Bad-case move" row is the modelled adverse move over the next N bars at your chosen confidence.

What's original. Realized higher-moment estimation, a horizon-scaled Cornish-Fisher VaR readout, the forward triple-barrier calibration with an out-of-sample split, and a conviction read that openly admits when there's no proven edge — on a risk axis (fragility) that most indicators ignore entirely.

Inputs. Price source (change it for any market), reading mode (Simple/Pro), moment and realized-estimation controls, risk thresholds and VaR confidence, full calibration settings, and an auto-adapting dashboard legible on dark or light charts. Defaults are tuned for NSE:NIFTY1! intraday.

Honesty & limitations. Moments from short windows are noisy and the VaR is a model estimate, not a guarantee. Edge figures are computed on this chart's own history with overlapping windows and no costs — context, not a backtest; past behaviour doesn't predict the future.

Disclaimer: for research and education only. Not financial advice. Trading carries risk of loss; manage your own size.
Note di rilascio
Tail-Risk & Fragility — v2
Two changes in this update:

Performance: the forward-calibration engine now computes its triple-barrier outcome once per bar and reuses it across the base and both fragile-side branches, instead of recomputing the identical result three times — faster loading and lower runtime, with outputs byte-for-byte unchanged.

New (optional, off by default): variance-trend confirmation. A fragile state fires as a signal only when realized variance is also rising — the more robust early-warning that a large move is actually coming, rather than relying on the tail shape alone. It flows through the built-in calibration, so the Edge row tells you whether it helps. Existing behaviour is unchanged until you turn it on.
Note di rilascio
v1.1 — Cost model + finishing pass (no engine change)

- Added a cost model: a new "Round-trip cost (R)" input and a Net R dashboard row. The fragile-down
and fragile-up states are forward-calibrated on a symmetric 1:1 barrier, so conviction now requires
a fragile state to BOTH beat its base rate (Wilson) AND survive costs — a gross edge that costs eat
through is not tradeable, and the panel now says so.
- Added a Data Window (EXP_) export bus so the skew, kurtosis, tail percentile, VaR and the
cost-aware fragile-state edge (EXP_DownNetR / EXP_UpNetR) can feed other scripts via input.source().
- Added the MPL-2.0 licence header.
- No change to the skew/kurtosis engine, the value-at-risk read, the fragile-state logic or the
forward calibration — everyday behaviour is identical. Still a risk-shape read, not a buy/sell.

Descriptive research tooling, in-sample statistics, not investment advice.
Note di rilascio
v1.2 — Two additive normalization options over v1.1: a robust MAD z-score and an optional 3-window extreme consensus on the skew series. The skew/kurtosis moment engine, the realized (intrabar) estimation, the Cornish-Fisher VaR, the fragile-down/up states and the entire forward-calibration harness (triple-barrier, out-of-sample split, Wilson stars, Bonferroni, Net-R cost model) are unchanged — set Normalization = "Classic (mean/stdev)" to reproduce the exact v1.1 read.

1. Robust MAD normalization (default on). Realized skew is itself an outlier-driven statistic — a single fat-tail bar can dominate it — so a mean/stdev z on top double-counts those extremes. The skew series can now be standardized with a median/MAD z-score (median absolute deviation ×1.4826), which keeps the σ scale stable so the skew-extreme zones and the fragile-state triggers keep a consistent meaning across regimes. Selectable via "Normalization"; set "Classic (mean/stdev)" for the original.

2. 3-window extreme consensus (opt-in, default off). The skew z can be taken as the MEDIAN of the z at half, one and double the normalization window — a reading is extreme only when short, medium and long windows agree, removing the arbitrariness of a single lookback. "Extreme normalization" = "Single window" (the default) reproduces v1.1 exactly.

What is unchanged. The central-moment skew (m3/σ³) and excess kurtosis (m4/m2²−3), the optional realized lower-timeframe estimation, the fat-tail percentile flag, the Cornish-Fisher value-at-risk, the optional rising-variance confirmation, the fragile-down/up states, and the full forward-calibration layer (triple-barrier outcomes, non-overlapping sampling, out-of-sample window, Wilson interval, Bonferroni multi-test, round-trip cost → Net R) are byte-for-byte v1.1. Every export (EXP_Skew, EXP_Kurtosis, EXP_SkewWave, EXP_TailPct, EXP_VaRpct, EXP_ReturnSD, EXP_Fragile, EXP_FatTails, EXP_DownNetR, EXP_UpNetR) is retained. The new layers only re-standardize an existing series.

Still a risk-shape meter, NOT a buy/sell signal — moments from short windows are noisy and the VaR is a model estimate. Non-repaint: reads confirmed closes; the realized read uses confirmed lower-timeframe data; the calibration logs and resolves only on confirmed bars. Concept credits unchanged (skewness / excess kurtosis; realized higher-moment estimation; Cornish-Fisher quantile; López de Prado triple-barrier; Wilson; Bonferroni), plus the median/MAD robust z-score for the new normalization.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.