Volatility regime
Volatility regime shows how far implied volatility (how big a move option prices expect) sits from its normal level.
Columns under the chart measure it in standard deviations: above +0.5 is high, below -0.5 is low. A card names the regime and the stress level, and candles dim on stressed days. A day is stressed when implied volatility ranks in the top fifth of the window, 252 trading days by default. Use it to tell calm markets from nervous ones, once 60 trading days of daily options data exist.
Under the hood: the recipe reads the 30-day at-the-money IV from option_daily. The vol of vol is the exponentially weighted deviation of the IV's daily log changes, annualized. Two DayHistory rings from the options kit keep both (Options kit). It draws columns coloured by the regime between two muted guides, and a render.barcolor that dims a stressed bar's candle (Plotting). A render.hud card with a sparkline tile sits beside them. It is also the vol-regime template, the Volatility Regime card under Beyond the time axis in the editor's starter list, and it compiles as written.
The wrun indicator
// Volatility Regime: how far implied volatility (how big a move option prices expect) sits from its normal level. High
// implied volatility means pricey options and big expected swings. Columns under the chart show how far today's 30-day
// reading sits from its usual level, in standard deviations. Above +0.5 the regime is high, below -0.5 it is low. A
// card names the regime and the stress level: calm, transitional or stressed. A day is stressed when implied volatility
// ranks in the top fifth of the window, and its candle dims. The card also shows the vol of vol: how much implied
// volatility itself jumps around. Use it to tell calm markets from nervous ones before you trade.
//
// Technical notes: whether the chart's underlying's implied volatility is high, normal or low for that name, and how
// unsettled it is, from the daily options statistics (option_daily, the 30-day at-the-money IV per session). The regime
// score is a z-score: the session's IV against the mean and standard deviation of the window's earlier sessions, high
// over +0.5, low under -0.5, neutral between, drawn as columns in a pane under the chart with guides at both edges. The
// stress class bins the IV's percentile among the window's earlier sessions: calm under the 55th, transitional from the
// 55th to the 80th, stressed from the 80th up; the card names it, and a stressed bar's candle dims to the muted text
// colour when Tint candles is on (calm and transitional bars keep the chart's candles). The vol of vol is how much the
// IV itself moves: the exponentially weighted standard deviation of its daily log changes over the last Vol of vol
// sessions (recent changes weigh more), annualized over 252 days a year (365 on crypto, which trades every day), in
// percent, with its own percentile. A card at the bottom right reads the regime, the stress class and the numbers
// behind them. Each session's reading is the statistics job's close of that session, held on an intraday chart until
// the next one lands. The statistics are short today (they start when the data plane switches the daily job on): every
// reading needs Minimum history (60 sessions), and until then the card says how many there are. Daily or finer charts.
param.int("lookback", 252, { min: 20, max: 520, label: "Window, sessions", description: "The past trading days today is compared against. 252 is about a year, or 8 months on crypto." });
param.int("min_sessions", 60, { min: 10, max: 520, label: "Minimum history, sessions", description: "Trading days of data needed before a reading shows. Until then the card counts the days so far." });
param.int("vov_days", 30, { min: 5, max: 90, label: "Vol of vol, sessions", description: "The vol of vol is how much implied volatility itself jumps day to day. This sets how many recent days it weighs, the newest most." });
param.bool("tint_candles", true, { label: "Tint candles", description: "Dims the candles on stressed days, when the IV sits at its 80th percentile or higher" });
input("close", ohlcv.close); // the chart's own close: the grid
input("iv30", option_daily.atm_iv_30d, { missing: "nan", description: "The 30-day implied volatility (IV) of this symbol's options, in percent, one reading per trading day" }); // lands on the first bar of its day, NaN elsewhere
market.zone(); // the market's clock: 0 UTC on crypto, which trades every day of the year (the vol of vol's year)
output("score", histogram, lower, { color_by: "regime", colors: ["theme.down", "theme.muted", "theme.up"], label: "Regime score", format: "0.00", description: "How far today's 30-day IV sits from the window's average, in standard deviations. Empty until Minimum history is met." });
output("high_guide", line, lower, { role: "guide", color: "theme.muted", width: 1, label: "High", align: "right", description: "+0.5: over it the regime is high" });
output("low_guide", line, lower, { role: "guide", color: "theme.muted", width: 1, label: "Low", align: "right", description: "-0.5: under it the regime is low" });
output("regime", none, lower, { description: "0 low (score under -0.5), 1 normal, 2 high (over +0.5). It reads 1 while there is no score." });
output("stress", none, lower, { description: "0 calm (IV percentile under 55), 1 transitional (55 to 80), 2 stressed (80 and up). Empty while there is no percentile." });
output("tint_on", none, lower, { description: "1 on a stressed bar while Tint candles is on, so the candle dims" });
output("iv", none, lower, { description: "The newest 30-day IV, in percent" });
output("iv_pct", none, lower, { description: "Where today's IV ranks among the window's earlier days, 0 to 100" });
output("vov", none, lower, { description: "The vol of vol: how much the IV itself moves from day to day, as a yearly percent. It counts 365 days a year on crypto, 252 elsewhere." });
output("vov_pct", none, lower, { description: "Where today's vol of vol ranks among the window's earlier days, 0 to 100" });
output("sessions", none, lower, { description: "How many trading days of data the window holds" });
output("status", none, lower, { description: "0 not enough history yet, 1 the regime reads, 2 bars longer than a day" });
string("read", { max_bytes: 64 }); // the headline
string("stress_text", { max_bytes: 32 }); // "Stressed, 86th percentile"
string("title", { max_bytes: 64 });
render.barcolor("stress_tint", { where: "tint_on", color: "theme.muted" }); // a stressed bar's candle, dimmed; calm and transitional bars keep the chart's own
render.hud("regime_card", {
position: "bottom_right",
title: "{{title}}",
columns: 2,
tiles: [
tile.pill("Regime", "read", { headline: true }),
tile.pill("Stress", "stress_text"),
tile.spark("Vol of vol trend", "vov", { bars: 64 }),
tile.rows([
["IV, 30 days", "iv", "0.00"],
["Regime score", "score", "0.00"],
["IV percentile", "iv_pct", "0"],
["Vol of vol", "vov", "0.0"],
["Vol of vol percentile", "vov_pct", "0"],
["Trading days read", "sessions", "int"],
]),
],
});
const DAY = 86400.0;
const HIGH = 0.5; // the score's edges
const LOW = -0.5;
const TRANSITIONAL = 55.0; // the stress class's percentile edges
const STRESSED = 80.0;
const CAPACITY = 520;
const MONTHS: String[] = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
const ivs = new DayHistory(CAPACITY); // one 30-day IV per session
const vovs = new DayHistory(CAPACITY); // one vol of vol per session it could be measured
const dateClock = new Clock("UTC");
let lookback = 252; // settings, read in onStart()
let need = 60;
let vovDays = 30;
let tint = true;
let yearDays = 252.0; // the year the vol of vol annualizes over, read in onStart()
let prevT: f64 = NaN; // the bar spacing
let barSec: f64 = NaN;
let scoreNow: f64 = NaN; // the session readings, held
let ivPctNow: f64 = NaN;
let vovNow: f64 = NaN;
let vovPctNow: f64 = NaN;
function onStart(): void {
lookback = i32(p_lookback());
need = i32(p_min_sessions());
if (need > lookback) need = lookback;
vovDays = i32(p_vov_days());
tint = p_tint_candles() > 0.5;
yearDays = i32(p_market_zone()) == 0 ? 365.0 : 252.0; // crypto trades every day of the year
}
/** The vol of vol over the newest vovDays daily log changes of the IV, each weighing (1 - a)^k with k sessions back
* and a = 2 / (vovDays + 1), annualized, percent; NaN until vovDays + 1 sessions are held. */
function volOfVol(): f64 {
if (ivs.count() < vovDays + 1) return NaN;
const keep = 1.0 - 2.0 / f64(vovDays + 1);
let weight = 1.0;
let sumW = 0.0;
let sumSq = 0.0;
for (let k = 0; k < vovDays; k += 1) {
const r = Math.log(ivs.value(k) / ivs.value(k + 1));
sumSq += weight * r * r;
sumW += weight;
weight *= keep;
}
return Math.sqrt((sumSq / sumW) * yearDays) * 100.0;
}
function measure(day: f64): void {
const v = volOfVol();
if (!isNaN(v)) vovs.push(day, v);
vovNow = v;
const ready = ivs.span(lookback) >= need;
scoreNow = ready ? ivs.zscore(lookback) : NaN;
ivPctNow = ready ? ivs.percentile(lookback) : NaN;
vovPctNow = ready && !isNaN(v) && vovs.span(lookback) >= 2 ? vovs.percentile(lookback) : NaN;
}
function regimeOf(): f64 {
if (isNaN(scoreNow)) return 1.0;
return scoreNow > HIGH ? 2.0 : scoreNow < LOW ? 0.0 : 1.0;
}
function stressOf(): f64 {
if (isNaN(ivPctNow)) return NaN;
return ivPctNow >= STRESSED ? 2.0 : ivPctNow >= TRANSITIONAL ? 1.0 : 0.0;
}
function sbDay(day: f64): void { // "16OCT"
dateClock.update(day * DAY);
if (dateClock.dayOfMonth() < 10) sb_text("0");
sb_int(dateClock.dayOfMonth());
sb_text(MONTHS[dateClock.month() - 1]);
}
function writeWords(coarse: bool): void {
const held = ivs.span(lookback);
sb_clear();
if (coarse) sb_text("Needs a daily or finer chart");
else if (ivs.count() == 0) sb_text("Waiting for the daily options statistics");
else if (held < need) {
sb_text("Not enough history yet: ");
sb_int(held);
sb_text(" of ");
sb_int(need);
sb_text(" sessions");
} else if (isNaN(scoreNow)) sb_text("No spread: the IV has not moved in the window");
else {
const r = regimeOf();
sb_text(r == 2.0 ? "High IV, score " : r == 0.0 ? "Low IV, score " : "Normal IV, score ");
if (scoreNow >= 0.0) sb_text("+");
sb_f64(scoreNow, 2);
}
str_read_sb();
sb_clear();
const s = stressOf();
if (coarse || isNaN(s)) sb_text("No stress level");
else {
sb_text(s == 2.0 ? "Stressed, " : s == 1.0 ? "Transitional, " : "Calm, ");
sb_f64(ivPctNow, 0);
sb_text(" percentile");
}
str_stress_text_sb();
sb_clear();
sb_text("Volatility regime, 30-day IV");
if (!coarse && ivs.count() > 0) {
sb_text(", as of ");
sbDay(ivs.day(0));
}
str_title_sb();
}
// onBar() runs once per bar: the spacing, then the session's IV when it lands (measured once, held after); every bar
// writes the held readings, and a stressed bar's candle dims.
function onBar(): void {
const t = bar.time();
if (!isNaN(prevT) && t > prevT && (isNaN(barSec) || t - prevT < barSec)) barSec = t - prevT;
prevT = t;
const coarse = !isNaN(barSec) && barSec > 1.5 * DAY;
const iv = in_iv30();
if (!coarse && !isNaN(iv) && iv > 0.0) {
const day = Math.floor(t / DAY);
if (ivs.push(day, iv)) measure(day);
}
out_high_guide(HIGH);
out_low_guide(LOW);
out_score(coarse ? NaN : scoreNow);
out_regime(coarse ? 1.0 : regimeOf());
const s = coarse ? NaN : stressOf();
out_stress(s);
out_tint_on(tint && s == 2.0 ? 1.0 : 0.0);
out_iv(coarse || ivs.count() == 0 ? NaN : ivs.value(0));
out_iv_pct(coarse ? NaN : ivPctNow);
out_vov(coarse ? NaN : vovNow);
out_vov_pct(coarse ? NaN : vovPctNow);
out_sessions(coarse ? NaN : f64(ivs.span(lookback)));
out_status(coarse ? 2.0 : ivs.span(lookback) >= need ? 1.0 : 0.0);
if (bar.isLast()) writeWords(coarse);
}How it works
The score. zscore() reads the newest IV against the window's earlier sessions, so today never dampens its own score. The edges are fixed at plus and minus 0.5 standard deviations.
The stress level. percentile() is the share of the window's earlier sessions with a lower IV; the level's edges sit at the 55th and 80th percentiles. A stressed bar's candle dims to the muted text colour through a gate output (tint_on, 1 on a stressed bar while Tint candles is on), so calm and transitional bars keep the chart's own colours, and turning Tint candles off leaves every candle as it was.
The vol of vol. Over the newest vov_days daily log changes of the IV, each weighing (1 - a) to the power of its age in sessions with a = 2 / (vov_days + 1): recent changes count most. The year it annualizes over follows the market's clock (market.zone()): 365 days on crypto, 252 elsewhere. It is measured once per session and joins its own DayHistory for its percentile.
What the settings do
- Window, sessions: The card compares today with this many past trading days: 252 is about a year, 8 months on crypto.
- Minimum history, sessions: A reading shows only after this many trading days of data, so a few days never pass for a year.
- Vol of vol, sessions: The vol of vol is how much implied volatility itself jumps day to day. This sets how many recent days it weighs, the newest most.
- Tint candles: Dims the candles on stressed days, when the IV sits at its 80th percentile or higher.
- Regime: The verdict: high, normal or low IV for this symbol, with the score.
- Stress: Calm under the 55th percentile, transitional up to the 80th, stressed from the 80th up.
- Vol of vol trend: A small chart of how much the IV itself has jumped around lately.
- IV, 30 days: Today's 30-day implied volatility, as a yearly percent.
- Regime score: How far today's IV sits from its window average, in standard deviations.
- IV percentile: The share of past days in the window with a lower IV.
- Vol of vol: How much the IV itself moves from day to day, as a yearly percent.
- Vol of vol percentile: Where today's vol of vol ranks among the window's earlier days, 0 to 100.
- Trading days read: How many trading days of data the window holds.
Where it runs
It works on coins with listed options, on a daily or intraday chart. A copy you run from the editor (the code panel beside the chart) reads the same data. On a US stock chart, every indicator that runs in your browser reads it. The data is 15 minutes behind unless you have real-time US options data. On a CME (Chicago futures exchange) futures chart, every indicator that runs in your browser reads it too, once you accept the CME market data terms (Limitations). CME data is 10 minutes behind unless you have real-time CME data.
When data is missing
The history starts the day OpenMarket switched on these daily readings. The score, the percentile and the stress tint need Minimum history (60 trading days). Until then, the columns stay empty and the candles keep their colours. The card reads "Not enough history yet: 12 of 60 sessions". The vol of vol needs 31 trading days of its own. A flat IV gives no spread, and the card says so. Before the first trading day, the card reads "Waiting for the daily options statistics". A chart with bars longer than a day reads "Needs a daily or finer chart".
Customize it
- Another year.
lookbacksets how many sessions the score and the percentiles read. - A faster or slower vol of vol.
vov_daysof 10 reacts within two weeks, 90 over a quarter. - Keep the candles. Turn Tint candles off to read the regime in the pane alone.
Run it
- In the editor's Explorer, press the Templates icon and pick Volatility Regime under Beyond the time axis.
- Press Run on BTCUSDT's daily chart.
- At the editor's Console prompt, type
score,iv_pctandvov.
Concepts used
- Data sources for
option_daily - Options kit for
DayHistory - Plotting for the columns, the guides and the candle tint
- HUD cards for the card and its sparkline