Indicator · Pine Script v5 · Own pane

STRO v2 Skew/Tail Risk & CF-VaR

by AssetWhisper

An indicator in a separate pane that measures the shape of recent log returns over a rolling window using skewness and excess kurtosis.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code100
Settings5inputs
LicenceMPL-2.0
Last update7 weeks ago10 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

100 lines of Pine Script v5 from indicators/STRO_Skew_Tail_Risk_CF_VaR.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

STRO_Skew_Tail_Risk_CF_VaR.pine
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AssetWhisper — https://assetwhisper.com/indicators/
// ============================================================================
//  STRO v2 — Skew/Tail Risk + Cornish-Fisher VaR
//  Idea: la forma de la distribución de los retornos recientes cambia antes que
//  la volatilidad. Asimetría (skew) negativa y colas pesadas (curtosis) elevan la
//  probabilidad de movimientos extremos a la baja. v2 traduce esos momentos en
//  algo accionable: el VaR de Cornish-Fisher (peor movimiento esperado 1 de cada
//  20 y 1 de cada 100 barras) frente al VaR gaussiano, la asimetría entre cola
//  izquierda y derecha y una distancia mínima de stop coherente con la cola actual.
// ============================================================================
indicator("STRO v2 — Skew/Tail Risk & CF-VaR", shorttitle="STRO v2", overlay=false)

n       = input.int(60, "Window (bars)", minval=20, maxval=250)
smoothL = input.int(5, "Smoothing", minval=1, maxval=20)
skewTh  = input.float(0.5, "Skew threshold (|S|)", minval=0.1, maxval=2.0, step=0.1)
kurtTh  = input.float(2.0, "Heavy tails: excess kurtosis >", minval=0.5, maxval=10.0, step=0.5)
showMoments = input.bool(true, "Show S and K", group="Visual")

// === MOMENTOS DE LOS LOG-RETORNOS ===
r    = math.log(close / close[1])
mean = ta.sma(r, n)
sd   = ta.stdev(r, n)
s3 = 0.0
s4 = 0.0
if sd > 0
    for i = 0 to n - 1
        zi = (nz(r[i]) - mean) / sd
        s3 += zi * zi * zi
        s4 += zi * zi * zi * zi
skewRaw = s3 / n
kurtRaw = s4 / n - 3                 // exceso de curtosis (normal = 0)
S = ta.ema(skewRaw, smoothL)
K = ta.ema(kurtRaw, smoothL)

// === CUANTILES DE CORNISH-FISHER ===
cfQ(z, sk, ku) =>
    z + (z * z - 1) * sk / 6 + (z * z * z - 3 * z) * ku / 24 - (2 * z * z * z - 5 * z) * sk * sk / 36

Sc = math.max(-3.0, math.min(3.0, S))       // rango de validez de la expansión
Kc = math.max(-2.0, math.min(10.0, K))
q95 = cfQ(-1.645, Sc, Kc)
q99 = cfQ(-2.326, Sc, Kc)
var95cf = -(mean + sd * q95) * 100          // pérdida % esperada 1 de cada 20 barras
var99cf = -(mean + sd * q99) * 100          // 1 de cada 100
var95n  = -(mean - 1.645 * sd) * 100
var99n  = -(mean - 2.326 * sd) * 100
tailPremium = var95n > 0 ? var95cf / var95n : 1.0
up95cf = (mean + sd * cfQ(1.645, Sc, Kc)) * 100
asym   = up95cf - var95cf                   // > 0: cola derecha mayor que la izquierda

// === RÉGIMEN ===
negSkew = S < -skewTh
posSkew = S > skewTh
heavy   = K > kurtTh
riskLevel = negSkew and heavy ? 3 : (negSkew or heavy) ? 2 : posSkew and not heavy ? 0 : 1
riskLabel = riskLevel == 3 ? "HIGH TAIL RISK" : riskLevel == 2 ? "ELEVATED" : riskLevel == 1 ? "NORMAL" : "BENIGN"
riskColor = riskLevel == 3 ? color.red : riskLevel == 2 ? color.orange : riskLevel == 1 ? color.gray : color.green

osc = ta.ema(math.max(-100.0, math.min(100.0, -S * 20 + K * 10)), smoothL)

// === VISUAL ===
hline(0, "Zero", color=color.gray)
hline(20, "Risk warning", color=color.new(color.orange, 60), linestyle=hline.style_dashed)
hline(-20, "Benign", color=color.new(color.green, 60), linestyle=hline.style_dashed)
plot(osc, "Tail-risk oscillator", color=riskColor, linewidth=3)
plot(showMoments ? S * 30 : na, "Skew ×30", color=color.new(color.blue, 50), linewidth=1)
plot(showMoments ? K * 15 : na, "Excess kurtosis ×15", color=color.new(color.purple, 50), linewidth=1)
bgcolor(riskLevel == 3 ? color.new(color.red, 92) : riskLevel == 0 ? color.new(color.green, 93) : na, title="Tail regime")
plotshape(S > 0 and S[1] <= 0, "Skew turning positive", style=shape.diamond, location=location.bottom, color=color.lime, size=size.tiny, text="S+")
plotshape(S < 0 and S[1] >= 0, "Skew turning negative", style=shape.diamond, location=location.top, color=color.maroon, size=size.tiny, text="S-")
plot(riskLevel, "STRO risk level (export: 0 benign .. 3 high)", display=display.none)
plot(var99cf, "STRO VaR99 CF % (export)", display=display.none)

var table t = table.new(position.top_right, 2, 9, bgcolor=color.new(color.black, 60))
table.cell(t, 0, 0, "TAIL RISK", text_color=color.white, text_size=size.small)
table.cell(t, 1, 0, riskLabel, bgcolor=color.new(riskColor, 30), text_color=color.white, text_size=size.small)
table.cell(t, 0, 1, "Skew", text_color=color.white, text_size=size.small)
table.cell(t, 1, 1, str.tostring(S, "#.##"), text_color=negSkew ? color.red : posSkew ? color.lime : color.white, text_size=size.small)
table.cell(t, 0, 2, "Excess kurtosis", text_color=color.white, text_size=size.small)
table.cell(t, 1, 2, str.tostring(K, "#.##"), text_color=heavy ? color.red : color.white, text_size=size.small)
table.cell(t, 0, 3, "VaR 95% CF / normal", text_color=color.white, text_size=size.small)
table.cell(t, 1, 3, str.tostring(var95cf, "#.##") + "% / " + str.tostring(var95n, "#.##") + "%", text_color=color.orange, text_size=size.small)
table.cell(t, 0, 4, "VaR 99% CF / normal", text_color=color.white, text_size=size.small)
table.cell(t, 1, 4, str.tostring(var99cf, "#.##") + "% / " + str.tostring(var99n, "#.##") + "%", text_color=color.red, text_size=size.small)
table.cell(t, 0, 5, "Tail premium", text_color=color.white, text_size=size.small)
table.cell(t, 1, 5, str.tostring(tailPremium, "#.##") + "x", text_color=tailPremium > 1.3 ? color.red : tailPremium < 0.9 ? color.lime : color.white, text_size=size.small)
table.cell(t, 0, 6, "Up/down 95% asym.", text_color=color.white, text_size=size.small)
table.cell(t, 1, 6, str.tostring(asym, "#.##") + " pts", text_color=asym > 0 ? color.lime : color.red, text_size=size.small)
table.cell(t, 0, 7, "Min stop (≥ VaR99)", text_color=color.white, text_size=size.small)
table.cell(t, 1, 7, str.tostring(math.max(0.0, var99cf), "#.##") + "% per bar", text_color=color.aqua, text_size=size.small)
table.cell(t, 0, 8, "σ / bar", text_color=color.white, text_size=size.small)
table.cell(t, 1, 8, str.tostring(sd * 100, "#.##") + "%  (n=" + str.tostring(n) + ")", text_color=color.gray, text_size=size.small)

// === ALERTAS ===
alertcondition(riskLevel == 3 and riskLevel[1] != 3, "STRO High tail risk", "STRO v2: negative skew with heavy tails - defensive mode")
alertcondition(riskLevel == 0 and riskLevel[1] != 0, "STRO Benign tails", "STRO v2: positive skew, normal tails - favourable for longs")
alertcondition(tailPremium > 1.5 and tailPremium[1] <= 1.5, "STRO Tail premium", "STRO v2: CF VaR exceeds normal VaR by 50%+")
alertcondition(S < 0 and S[1] >= 0, "STRO Skew negative", "STRO v2: skewness turned negative")

Overview

STRO v2 Skew/Tail Risk & CF-VaR converts them into a Cornish-Fisher value-at-risk estimate compared with the Gaussian version, a comparison of left and right tails, and a minimum stop distance consistent with the current tail. Skew and kurtosis thresholds flag asymmetric or heavy-tailed conditions. Window, smoothing and thresholds are inputs.

Details

Published by

AssetWhisper on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Window (bars)int60n
Smoothingint5smoothL
Skew threshold (|S|)float0.5skewTh
Heavy tails: excess kurtosis >float2.0kurtTh
Show S and KbooltrueshowMoments
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator calculates the distribution of close-to-close percentage changes using rate of change on closing prices. It bins percentage changes into intervals of 0.25 percent increments from negative to positive values and plots a normalized cumulative hist

Indicator v4 Volatility & bands
Updated 11 days ago · GPL-3.0 GitHub repository of Close-to-Close % Change Distribution

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers