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

Tail-Risk & Fragility Oscillator

200
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.
ملاحظات الأخبار
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.
ملاحظات الأخبار
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.

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

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