Greek exposure
A snapshot of now: the longer a bar, the more dealers (the market makers who hedge options) must hedge there.
Bars beside the prices show each strike (the option's price level), bars below each expiry (the day the option ends). Labels mark the biggest strike (top) and the biggest below price (floor), above it (ceiling) and before the top (gate). Hedging there can pin price or speed it up. Use it before big expiries to see where hedging piles up.
Under the hood: it reads this symbol's whole options list on the live bar (options_chain.cells, Data sources). It prices the greeks and each expiry's time left with Greeks, optionsAsOfMs, optionsLiveUntilMs, optionsYearsToGo and optionsTradeDay. The gamma lens, the regime and the flip come from GammaCurve and bsGamma. They follow the open-interest model, where dealers are long the calls and short the puts. It labels strikes with NodeBoard and counts presets with expiryPresetCount. It docks three plot.levels frames on the price axis and one panel.bars frame under the chart (Cards, frames and panels). It draws a render.hud card in the default look. It is the greek-exposure template: Greek Exposure under HUDs in the editor's starter list, and it compiles as written.
The wrun indicator
// Greek Exposure: a snapshot of where dealers (the market makers who hedge options) must hedge most in this symbol's
// options. Gamma (how fast dealers must hedge as price moves) is the default view. Long gamma (dealers calm price):
// they sell rallies and buy dips, so price tends to calm. Short gamma (dealers chase price): they buy rallies and sell
// dips, so price tends to trend. Bars on the price axis show each strike (the option's price level). Bars under the
// chart show each expiry (the day the option ends). A longer bar means more hedging at that price, which can pin price
// or push it. Labels mark the biggest strike (top) and the biggest below price (floor), above it (ceiling) and before
// the top (gate). Other views show delta, vanna, charm, vega or open interest (contracts still held open). Use it
// before key levels or expiries to see where dealer hedging piles up.
//
// Under the hood: The Lens setting picks gamma (the default), delta, vanna, charm or vega, or the open interest
// itself and IV times open interest; the Expiries setting counts every live expiry, the one settling today, those
// within 7 or 30 trade days, the N nearest, or every expiry stacked by days to go (0, 1-7, 8-30, 31-60, 61-120,
// 121+). The exposure by strike docks on the price axis (net, calls against puts, or the stacked days), the exposure
// by expiry stands in bars under the chart, and a card reads the lens in one plain line first (Long gamma: dealers
// calm price), then the net, the calls, the puts, the same-day expiry, the strikes that matter and the gamma flip.
// The gamma lens and the flip are the options kit's GammaCurve over the counted expiries, the rule every card reads:
// gamma priced at the chain's as-of (optionsAsOfMs: the live bar's close time) to each expiry's end
// (optionsYearsToGo: 16:15 New York on OPRA), the regime the sign of net GEX at spot, the flip the curve's zero
// nearest spot. The gamma lens's totals count every contract the curve reads; every other lens counts the strike
// table's (the 1,024 strikes nearest spot), as the data plane's exposure fold does. The convention is the
// open-interest model: dealers long the calls and short the puts, so calls add and puts subtract on every lens but
// delta, which keeps each option's own sign as delta views do. Units: dollars, or units of the underlying (shares on
// a US stock, contracts on CME, coins on crypto) for gamma per 1% move of spot, delta held, vanna per IV point and
// charm per calendar day (never times 365); vega in dollars per IV point. The chain rides the live bar only: history
// bars draw nothing, everything is measured on the last bar. The node words name the lens's nodes over the strike
// table (the options kit's NodeBoard over each strike's net, read against spot): the top (the largest |net|,
// starred), the gate (the largest between spot and the top, at 35% of the top or more), the floor (the largest below
// spot) and the ceiling (the largest above it) label their rows in whichever docked profile the settings draw. Expiry
// preset picks the expiries by the calendar (the front one, to this or next Friday, to the monthly or quarterly opex,
// all) in place of the Expiries setting's range; count keeps that range.
section("Lens");
param.choice("lens", ["gamma", "delta", "vanna", "charm", "vega", "iv_x_oi", "oi"], "gamma", { label: "Lens", description: "What the bars measure. gamma: hedging per 1% move. delta: stock dealers hold to hedge. charm, vanna: how that hedge changes with time or option prices. vega: gain as option prices rise. iv_x_oi: implied volatility times open interest. oi: open interest." });
param.choice("units", ["dollars", "underlying"], "dollars", { label: "Units", when: "lens in 0,1,2,3", description: "dollars: in dollars. underlying: in this symbol's own units (shares, contracts or coins). It applies to gamma, delta, vanna and charm." });
param.choice("split", ["net", "calls_puts"], "net", { label: "By strike", when: "scope!=5", description: "net: one bar per strike, calls minus puts. calls_puts: the calls one way, the puts the other." });
section("Expiries and strikes");
param.choice("scope", ["all", "0dte", "week", "month", "nearest", "buckets"], "all", { label: "Expiries", description: "Which expiries count while Expiry preset is count. all: every live one. 0dte: the one that expires today. week: within 7 trade days. month: within 30. nearest: the N soonest. buckets: all of them, stacked by days left, under every preset." });
param.int("nearest", 4, { min: 1, max: 24, label: "Nearest expiries", when: "scope=4", description: "How many of the soonest live expiries count when Expiries is nearest." });
param.number("window_pct", 8, { min: 1, max: 50, label: "Strike window, percent", description: "How far the strikes on the price axis reach above and below the price, in percent." });
param.number("rate_pct", 4, { min: 0, max: 20, step: 0.25, label: "Rate, percent", when: "lens in 2,3,4", description: "The interest rate used to price vanna, charm and vega on US stock and CME options. Crypto options use 0." });
input("close", ohlcv.close); // the chart's own close: spot where a contract reports no underlying, and the window's centre
input("chain", options_chain.cells, { max_cells: 4000, venue: "auto", description: "This symbol's options: US listed options on a US stock, CME options on futures, Deribit on BTC and ETH." }); // [strike, expiry_ms, side, oi, gamma, delta, mark_iv, underlying, multiplier, vega] per contract
market.zone(); // the market's clock: 0 UTC (crypto), 1 New York (US stocks), 2 Chicago (CME): the calendar, the model and the unit word
chart.interval_sec(); // the bar's length: the chain's as-of is the live bar's close time, the block naming none
// The expiry preset, after the market's clock and the bar's length, which the chart fills, so every setting before
// them keeps its slot.
param.choice("expiry_preset", ["front", "to_friday", "to_next_friday", "to_opex", "to_next_opex", "to_q_opex", "all", "count"], "count", { label: "Expiry preset", description: "Picks expiries by the calendar. front: the nearest. to_friday, to_next_friday: through this or next Friday. to_opex, to_next_opex: through this or next monthly expiry (third Friday). to_q_opex: the next quarterly one. all: every one. count: use Expiries." });
// The readings, data-only: the card's tiles read them and the Console can too. Each is NaN on history bars.
output("net_exposure", none, overlay, { description: "The lens over the counted expiries: calls add, puts subtract, and delta keeps each option's own sign. In the title's unit, on the live bar only." });
output("calls_exposure", none, overlay, { color: "theme.up", description: "The calls' part of the net" });
output("puts_exposure", none, overlay, { color: "theme.down", description: "The puts' part of the net, signed as it counts" });
output("today_exposure", none, overlay, { description: "The net of the expiry that settles today. Blank when none is listed or counted." });
output("top_strike", none, overlay, { description: "The strike with the largest net exposure, either way. On the gamma lens it is the magnet, which tends to pull price." });
output("top_exposure", none, overlay, { description: "That strike's net exposure" });
output("zero_cross", none, overlay, { description: "The gamma flip for the counted expiries, on every lens: the price nearest now where dealer gamma crosses zero. Blank when none lies within 50%." });
output("above_spot", none, overlay, { description: "The net over the strikes above the price." });
output("below_spot", none, overlay, { description: "The net over the strikes at or below the price." });
output("tone", none, overlay, { description: "The headline's colour code: 0 net below zero, 1 no reading, 2 net above zero. Live bar only." });
output("expiries_counted", none, overlay, { description: "The live expiries the Expiries setting counts" });
string("read", { max_bytes: 64 }); // the headline: the lens's one plain line, or why there is no reading
string("title", { max_bytes: 64 }); // the card's title: the lens, its unit and the expiries counted
// The docked profiles, one per shape; only the one the settings pick is written, so the other two stay absent.
const net_rows = frame("net_rows", { max_bytes: 24576 });
const split_rows = frame("split_rows", { max_bytes: 32768 });
const day_rows = frame("day_rows", { max_bytes: 65536 });
const expiry_rows = frame("expiry_rows", { max_bytes: 8192 });
// Each frame's labels_text names the nodes on their rows, every other row bare.
plot.levels({ name: "by_strike", frame: net_rows, dock: "right", width_frac: 0.14, baseline: "center", color: "theme.muted", thickness_px: 10, hover: true, format: "si" });
plot.levels({ name: "calls_puts", frame: split_rows, dock: "right", width_frac: 0.14, baseline: "center", thickness_px: 10, hover: true, format: "si", series: [{ name: "Calls", color: "theme.up" }, { name: "Puts", color: "theme.down" }] });
plot.levels({ name: "by_days", frame: day_rows, dock: "right", width_frac: 0.16, baseline: "center", thickness_px: 10, hover: true, format: "si", series: [{ name: "0d", color: "#f43f5e" }, { name: "1-7d", color: "#f59e0b" }, { name: "8-30d", color: "#eab308" }, { name: "31-60d", color: "#22c55e" }, { name: "61-120d", color: "#38bdf8" }, { name: "121d+", color: "#a78bfa" }] });
panel.bars({ name: "by_expiry", title: "Net by expiry", x: "category", place: "below", frame: expiry_rows, orientation: "vertical", color_mode: "sign", positive_color: "theme.up", negative_color: "theme.down", series: [{ name: "Net" }], format: "si", hover_card: true, legend_style: "title", height_frac: 0.18 });
// The card: the lens's plain line leads as the headline, the title names the lens, its unit and the expiries counted.
render.hud("exposure", {
position: "bottom_center",
title: "{{title}}",
columns: 2,
tiles: [
tile.pill("Dealers", "read", { headline: true }),
tile.value("Net", "net_exposure", { format: "si" }),
tile.value("Same-day expiry", "today_exposure", { format: "si" }),
tile.value("Calls", "calls_exposure", { format: "si" }),
tile.value("Puts", "puts_exposure", { format: "si" }),
tile.rows([
["Largest strike", "top_strike", "price"],
["Its exposure", "top_exposure", "si"],
["Gamma flip", "zero_cross", "price"],
["Above price", "above_spot", "si"],
["At or below price", "below_spot", "si"],
]),
],
});
const TUPLE = 10; // f64s per contract: strike, expiry_ms, side, oi, gamma, delta, mark_iv, underlying, multiplier, vega
const MAX_STRIKES = 1024; // distinct strikes the table keeps (the profile, the largest strike, every lens's totals but gamma's), the nearest spot when the chain lists more
const MAX_EXPIRIES = 64; // live expiries kept, the nearest when the chain lists more
const MAX_ROWS = 256; // rows in the docked profile, the strikes nearest spot inside the window
const DAYS = 6; // the stacked buckets: 0, 1-7, 8-30, 31-60, 61-120, 121+ days to go
const MIN_T_MS = 900000.0; // 15 minutes: a contract closer to its expiry prices no time left, as the chart's greeks do
const GAMMA = 0;
const DELTA = 1;
const VANNA = 2;
const CHARM = 3;
const VEGA = 4;
const IV_X_OI = 5;
const SCOPE_ALL = 0;
const SCOPE_TODAY = 1;
const SCOPE_WEEK = 2;
const SCOPE_MONTH = 3;
const SCOPE_NEAREST = 4;
const SCOPE_BUCKETS = 5;
const LENS_NAMES: String[] = ["Gamma", "Delta", "Vanna", "Charm", "Vega", "IV x OI", "Open interest"];
const LENS_WORDS: String[] = ["gamma", "delta", "vanna", "charm", "vega", "implied volatility", "open interest"]; // the no-reading line
const strikePrice = new StaticArray<f64>(MAX_STRIKES); // the strike table, ascending
const callAt = new StaticArray<f64>(MAX_STRIKES); // the calls' exposure per strike
const putAt = new StaticArray<f64>(MAX_STRIKES); // the puts' exposure per strike, signed as it counts
const dayAt = new StaticArray<f64>(MAX_STRIKES * DAYS); // the net per strike and bucket: [strike * DAYS + bucket]
const expiryAt = new StaticArray<f64>(MAX_EXPIRIES); // the live expiries, ascending
const expiryDays = new StaticArray<f64>(MAX_EXPIRIES); // days to go on the market's calendar, 0 on the expiry day
const expiryNet = new StaticArray<f64>(MAX_EXPIRIES);
const contractValue = new StaticArray<f64>(in_chain_max_cells); // each contract's exposure on the lens; NaN when it does not count
const expiryKept = new StaticArray<bool>(MAX_EXPIRIES); // counted by the Expiries setting
const greeks = new Greeks(); // prices vanna, charm and vega per contract; allocated once
let curve = new GammaCurve(1); // the counted expiries' gamma curve: the regime and the flip; built in onStart()
const netAt = new StaticArray<f64>(MAX_STRIKES); // each kept strike's net on the lens, the nodes' reading
let board = new NodeBoard(1); // the lens's nodes over the strike table; built in onStart()
let preset = EXPIRY_PRESET_COUNT; // Expiry preset: an EXPIRY_PRESET_* code; count reads the Expiries setting
let lens = GAMMA; // settings, read in onStart()
let inUnderlying = false;
let splitSides = false;
let scope = SCOPE_ALL;
let nearestCount = 4;
let windowPct = 0.08;
let rate = 0.04;
let zone = 0;
let intervalMs = 0.0; // the bar's length in milliseconds, read in onStart(); 0 where the host writes none
let close: f64 = NaN; // this bar
let t: f64 = NaN;
let strikeCount = 0;
let expiryCount = 0;
let counted = 0; // expiries the setting counts
let readings = 0; // contracts that carried a nonzero reading for the lens
let net: f64 = NaN; // the readings, measured on the live bar
let calls: f64 = NaN;
let puts: f64 = NaN;
let today: f64 = NaN;
let topStrike: f64 = NaN;
let topValue: f64 = NaN;
let zeroCross: f64 = NaN;
let regime: f64 = NaN; // the sign of net GEX at spot over the counted expiries: 1, -1 or 0
let above: f64 = NaN;
let below: f64 = NaN;
function onStart(): void {
curve = new GammaCurve(in_chain_max_cells); // a slot per contract the block can carry, so a load is never refused
lens = i32(p_lens());
inUnderlying = p_units() == 1.0;
splitSides = p_split() == 1.0;
scope = i32(p_scope());
nearestCount = i32(p_nearest());
windowPct = p_window_pct() / 100.0;
zone = i32(p_market_zone());
intervalMs = p_chart_interval_sec() * 1000.0;
rate = zone == 0 ? 0.0 : p_rate_pct() / 100.0; // crypto chains are quoted at a rate of 0
// A host that serves no Expiry preset hands NaN: it then reads count (the Expiries setting's range, whatever a code
// 0 would pick).
const presetArg = p_expiry_preset();
preset = presetArg >= 0.0 && presetArg <= f64(EXPIRY_PRESET_COUNT) ? i32(presetArg) : EXPIRY_PRESET_COUNT;
board = new NodeBoard(MAX_STRIKES); // the per-strike buffers are its only allocation
}
// ── The tables: sorted insertion, the nearest kept when full ──
function noteExpiry(ms: f64): void {
let lo = 0;
let hi = expiryCount;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (expiryAt[mid] < ms) lo = mid + 1;
else hi = mid;
}
if (lo < expiryCount && expiryAt[lo] == ms) return;
if (expiryCount >= MAX_EXPIRIES) {
if (lo >= expiryCount) return; // later than every kept expiry
expiryCount -= 1; // the latest makes room
}
for (let k = expiryCount; k > lo; k -= 1) expiryAt[k] = expiryAt[k - 1];
expiryAt[lo] = ms;
expiryCount += 1;
}
function findExpiry(ms: f64): i32 {
let lo = 0;
let hi = expiryCount;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (expiryAt[mid] < ms) lo = mid + 1;
else hi = mid;
}
return lo < expiryCount && expiryAt[lo] == ms ? lo : -1;
}
function copyRow(from: i32, to: i32): void {
strikePrice[to] = strikePrice[from];
callAt[to] = callAt[from];
putAt[to] = putAt[from];
for (let b = 0; b < DAYS; b += 1) dayAt[to * DAYS + b] = dayAt[from * DAYS + b];
}
function findStrike(strike: f64): i32 { // the row of a kept strike, -1 when the table does not hold it
let lo = 0;
let hi = strikeCount;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (strikePrice[mid] < strike) lo = mid + 1;
else hi = mid;
}
return lo < strikeCount && strikePrice[lo] == strike ? lo : -1;
}
function strikeSlot(strike: f64): i32 { // the row of this strike, inserted when new; -1 when the table is full and it is the farthest from spot
let lo = 0;
let hi = strikeCount;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (strikePrice[mid] < strike) lo = mid + 1;
else hi = mid;
}
if (lo < strikeCount && strikePrice[lo] == strike) return lo;
if (strikeCount >= MAX_STRIKES) { // full: the strike farthest from spot leaves, the lower one on a tie
const dLow = Math.abs(strikePrice[0] - close);
const dHigh = Math.abs(strikePrice[strikeCount - 1] - close);
const dNew = Math.abs(strike - close);
if (dLow >= dHigh) {
if (dNew > dLow || (dNew == dLow && strike < strikePrice[0])) return -1;
for (let k = 1; k < strikeCount; k += 1) copyRow(k, k - 1);
strikeCount -= 1;
if (lo > 0) lo -= 1;
} else {
if (dNew > dHigh || (dNew == dHigh && strike < strikePrice[strikeCount - 1])) return -1;
strikeCount -= 1;
if (lo > strikeCount) lo = strikeCount;
}
}
for (let k = strikeCount; k > lo; k -= 1) copyRow(k - 1, k);
strikePrice[lo] = strike;
callAt[lo] = 0.0;
putAt[lo] = 0.0;
for (let b = 0; b < DAYS; b += 1) dayAt[lo * DAYS + b] = 0.0;
strikeCount += 1;
return lo;
}
function bucketOf(days: f64): i32 { // 0, 1-7, 8-30, 31-60, 61-120, 121+ days to go
return days <= 0.0 ? 0 : days <= 7.0 ? 1 : days <= 30.0 ? 2 : days <= 60.0 ? 3 : days <= 120.0 ? 4 : 5;
}
// ── One contract's exposure on the lens, in the setting's unit, signed as it counts ──
function exposureOf(cells: StaticArray<f64>, i: i32, nowMs: f64): f64 {
const side = cells[i + 2] > 0.0 ? 1.0 : -1.0; // dealers long the calls, short the puts
const oi = cells[i + 3];
if (lens == IV_X_OI) return side * cells[i + 6] * oi; // IV points times open interest
if (lens > IV_X_OI) return side * oi; // open interest
const under = cells[i + 7] > 0.0 ? cells[i + 7] : close;
const multiplier = cells[i + 8] > 0.0 ? cells[i + 8] : 1.0;
let perUnit: f64 = NaN; // the delta change (or delta) one unit of the underlying carries per unit of open interest
if (lens == GAMMA) perUnit = side * bsGamma(under, cells[i], cells[i + 6] / 100.0, optionsYearsToGo(cells[i + 1], nowMs, zone)) * under * 0.01; // the delta change for a 1% move of spot, the gamma priced at the chain's as-of with the kit's time to go (to the expiry's end, a second at least on OPRA), as GammaCurve prices it
else if (lens == DELTA) perUnit = cells[i + 5]; // each option's own sign, as delta views read it
else {
const left = optionsLiveUntilMs(cells[i + 1], zone) - nowMs; // the time to the expiry's end: 16:15 New York on OPRA
const years = left < MIN_T_MS ? 0.0 : left / OPTIONS_YEAR_MS;
const sigma = cells[i + 6] / 100.0; // mark IV rides the chain in percentage points
if (zone == 1) greeks.spot(side, under, cells[i], years, sigma, rate); // a US stock: Black-Scholes on spot
else greeks.forward(side, under, cells[i], years, sigma, rate); // futures and crypto: the underlying is the forward
if (lens == VEGA) return side * (cells[i + 9] > 0.0 ? cells[i + 9] : greeks.vega) * oi * multiplier; // dollars per IV point
perUnit = side * (lens == VANNA ? greeks.vanna : greeks.charm);
}
const dollars = perUnit * oi * multiplier * under;
if (!inUnderlying) return dollars;
return zone == 2 ? dollars / (under * multiplier) : dollars / under; // CME: futures contracts; else shares or coins
}
// ── The chain, measured on the live bar ──
function measure(n: i32): void {
const cells = in_chain_view(); // the live chain in place: the first n values of the build's own buffer
const nowMs = optionsAsOfMs(t * 1000.0, intervalMs); // the chain's as-of: the live bar's close time
const todayKey = optionsTradeDay(nowMs, zone);
strikeCount = 0;
expiryCount = 0;
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) if (cells[i] > 0.0 && optionsLiveUntilMs(cells[i + 1], zone) > nowMs) noteExpiry(cells[i + 1]); // the live expiries
counted = 0;
// Expiry preset: count keeps the Expiries setting's range; any other preset keeps a run of the live expiries from the
// front (the kit's expiryPresetCount on the market's trade days at the as-of).
const presetKept = preset == EXPIRY_PRESET_COUNT ? 0 : expiryPresetCount(expiryAt, expiryCount, nowMs, zone, preset, 0);
for (let e = 0; e < expiryCount; e += 1) {
const days = optionsTradeDay(expiryAt[e], zone) - todayKey; // a calendar question: 0 on the expiry day, never the hours left
expiryDays[e] = days;
expiryNet[e] = 0.0;
const kept = preset != EXPIRY_PRESET_COUNT ? e < presetKept : scope == SCOPE_TODAY ? days <= 0.0 : scope == SCOPE_WEEK ? days <= 7.0 : scope == SCOPE_MONTH ? days <= 30.0 : scope == SCOPE_NEAREST ? e < nearestCount : true;
expiryKept[e] = kept;
if (kept) counted += 1;
}
// The counted expiries are always the nearest ones (every scope keeps a run from the front), so the curve reads them
// as its nearest N: the regime and the flip over the same contracts the card counts.
if (counted > 0) curve.load(cells, n, nowMs, counted < expiryCount ? counted : 0, close, zone);
regime = counted > 0 ? curve.regime() : NaN;
zeroCross = counted > 0 ? curve.flip() : NaN;
readings = 0;
calls = 0.0;
puts = 0.0;
above = 0.0;
below = 0.0;
// Two passes. The first notes each counted contract's exposure and fills the strike table (the MAX_STRIKES nearest
// spot when the chain lists more); the second adds the exposures of the contracts whose strike was kept to the table's
// strikes and day buckets, so the table reads the same strikes whatever order the chain arrives in. The gamma lens is
// the curve's: the first pass adds each exposure to its totals, its expiries and its sums each side of spot, over
// every contract, the set the curve reads. Every other lens counts the table's strikes, as the data plane's exposure
// fold does: its expiries in the second pass, its totals from the table's rows.
const curveSet = lens == GAMMA;
const count = n / TUPLE < contractValue.length ? n / TUPLE : contractValue.length;
for (let c = 0; c < count; c += 1) {
const i = c * TUPLE;
contractValue[c] = NaN;
const strike = cells[i];
if (!(strike > 0.0) || !(cells[i + 3] > 0.0) || !(optionsLiveUntilMs(cells[i + 1], zone) > nowMs)) continue;
const e = findExpiry(cells[i + 1]);
if (e < 0 || !expiryKept[e]) continue;
const v = exposureOf(cells, i, nowMs);
if (!isFinite(v)) continue; // no reading for this lens (no IV to price, a NaN greek)
contractValue[c] = v;
if (curveSet) {
if (cells[i + 2] > 0.0) calls += v;
else puts += v;
if (strike > close) above += v;
else below += v;
expiryNet[e] += v;
if (v != 0.0) readings += 1;
}
strikeSlot(strike);
}
for (let c = 0; c < count; c += 1) {
const v = contractValue[c];
if (isNaN(v)) continue;
const i = c * TUPLE;
const slot = findStrike(cells[i]);
if (slot < 0) continue; // left out of the full table: out of its rows (and, off the gamma lens, out of the totals)
const e = findExpiry(cells[i + 1]);
if (cells[i + 2] > 0.0) callAt[slot] += v;
else putAt[slot] += v;
dayAt[slot * DAYS + bucketOf(expiryDays[e])] += v;
if (!curveSet) {
expiryNet[e] += v;
if (v != 0.0) readings += 1;
}
}
// The table's largest strike, ascending, and every lens's totals but gamma's.
topStrike = NaN;
topValue = NaN;
let best = 0.0;
for (let k = 0; k < strikeCount; k += 1) {
const row = callAt[k] + putAt[k];
if (!curveSet) {
calls += callAt[k];
puts += putAt[k];
if (strikePrice[k] > close) above += row;
else below += row;
}
if (Math.abs(row) > best) {
best = Math.abs(row);
topStrike = strikePrice[k];
topValue = row;
}
}
net = calls + puts;
today = NaN;
for (let e = 0; e < expiryCount; e += 1) if (expiryKept[e] && expiryDays[e] <= 0.0) today = (isNaN(today) ? 0.0 : today) + expiryNet[e];
// The nodes of the lens over the table's strikes, read against spot (the chart's close).
for (let k = 0; k < strikeCount; k += 1) netAt[k] = callAt[k] + putAt[k];
board.load(strikePrice, netAt, strikeCount, close);
}
// ── The frames: the docked profile and the bars by expiry, built in the kit's frame buffer without allocating ──
function fbGrouped(n: i64): void { // 84210 -> 84,210
if (n >= 1000) {
fbGrouped(n / 1000);
fb_text(",");
const r = n % 1000;
if (r < 100) fb_text("0");
if (r < 10) fb_text("0");
fb_int(r);
} else fb_int(n);
}
function fbStrike(v: f64): void { // a whole strike without decimals (660, 6,650, 67,000), else at the decimals its size takes
if (v >= 1000.0) fbGrouped(i64(Math.round(v)));
else if (v >= 1.0 && v == Math.floor(v)) fb_int(i64(v));
else fb_f64(v, v >= 100.0 ? 2 : v >= 1.0 ? 3 : 5);
}
function fbNodeLabel(k: i32): void { // a profile row's node word, quoted: "103 ★ top", "101 gate 36%", "97 floor 60%"; "" for none
fb_text("\"");
const role = board.role(k);
if (role >= NODE_ROLE_CEILING) { // the top, the gate, the floor and the ceiling
fbStrike(strikePrice[k]);
if (role == NODE_ROLE_TOP) fb_text(" ★ top");
else {
fb_text(" ");
fb_text(roleWord(role));
fb_text(" ");
fb_int(i64(Math.round(board.pctOfTop(k)))); // its share of the top's size, a whole percent
fb_text("%");
}
}
fb_text("\"");
}
function writeProfile(): void {
const lo = close * (1.0 - windowPct);
const hi = close * (1.0 + windowPct);
let first = 0; // the window's rows: [first, last)
while (first < strikeCount && strikePrice[first] < lo) first += 1;
let last = first;
while (last < strikeCount && strikePrice[last] <= hi) last += 1;
while (last - first > MAX_ROWS) { // a wide window on a fine ladder: drop the row farther from spot
if (close - strikePrice[first] >= strikePrice[last - 1] - close) first += 1;
else last -= 1;
}
if (last <= first) return; // no strike inside the window: the profile stays absent
fb_clear();
fb_text("{\"prices\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_num(strikePrice[k]);
}
fb_text("],\"values\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_num(callAt[k] + putAt[k]);
}
fb_text("],\"labels_text\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fbNodeLabel(k); // the top, the gate, the floor and the ceiling by name; "" elsewhere
}
if (scope == SCOPE_BUCKETS) {
fb_text("],\"series\":[");
for (let b = 0; b < DAYS; b += 1) {
fb_text(b > 0 ? ",[" : "[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_num(dayAt[k * DAYS + b]);
}
fb_text("]");
}
fb_text("]}");
writeFrameBuffer(day_rows);
} else if (splitSides) {
fb_text("],\"series\":[[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_num(callAt[k]);
}
fb_text("],[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_num(putAt[k]);
}
fb_text("]]}");
writeFrameBuffer(split_rows);
} else {
fb_text("],\"colors\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
const row = callAt[k] + putAt[k];
fb_text(row > 0.0 ? "\"theme.up\"" : row < 0.0 ? "\"theme.down\"" : "\"theme.muted\""); // above zero up, below down
}
fb_text("]}");
writeFrameBuffer(net_rows);
}
}
function writeExpiries(): void {
fb_clear();
fb_text("{\"title\":");
fb_text("\"");
fb_text(LENS_NAMES[lens]);
fb_text(" by expiry\",\"rows\":[");
let wrote = 0;
const nowMs = optionsAsOfMs(t * 1000.0, intervalMs); // the chain's as-of: an expiry in another year names it
for (let e = 0; e < expiryCount; e += 1) {
if (!expiryKept[e]) continue;
if (wrote > 0) fb_text(",");
fb_text("[\"");
fbExpiryLabel(expiryAt[e], nowMs, zone); // the expiry's trade date: 16 Oct, or 15 Jan '27 in another year
fb_text(" ");
fb_int(i64(expiryDays[e]));
fb_text("d\",");
fb_num(expiryNet[e]);
fb_text("]");
wrote += 1;
}
fb_text("]}");
writeFrameBuffer(expiry_rows);
}
// ── The card's words ──
function headlineSign(): f64 { // the headline's sign: the dealer regime on the gamma lens (the kit's curve), the net's on every other
if (lens == GAMMA) return regime;
return net > 0.0 ? 1.0 : net < 0.0 ? -1.0 : 0.0;
}
function writeRead(): void {
sb_clear();
if (readings == 0 || isNaN(net)) {
sb_text("No ");
sb_text(LENS_WORDS[lens]);
sb_text(" in this symbol's options");
} else if (lens == GAMMA) sb_text(regime > 0.0 ? "Long gamma: dealers calm price" : regime < 0.0 ? "Short gamma: dealers chase price" : "Neutral gamma: no dealer hedging");
else if (lens == DELTA) sb_text(net >= 0.0 ? "Net long delta: the calls outweigh the puts" : "Net short delta: the puts outweigh the calls");
else if (lens == VANNA) sb_text(net >= 0.0 ? "Long vanna: an IV rise makes dealers sell" : "Short vanna: an IV rise makes dealers buy");
else if (lens == CHARM) sb_text(net >= 0.0 ? "Charm: each day passing makes dealers sell" : "Charm: each day passing makes dealers buy");
else if (lens == VEGA) sb_text(net >= 0.0 ? "Dealers long vega: an IV rise pays them" : "Dealers short vega: an IV rise costs them");
else if (lens == IV_X_OI) sb_text(net >= 0.0 ? "The calls hold the richer open interest" : "The puts hold the richer open interest");
else sb_text(net >= 0.0 ? "More call than put open interest" : "More put than call open interest");
str_read_sb();
}
function writePreset(): void { // the expiries the preset keeps, in words, with how many
if (preset == EXPIRY_PRESET_ALL) {
sb_text("all ");
sb_int(expiryCount);
sb_text(" expiries");
return;
}
sb_text(preset == EXPIRY_PRESET_FRONT ? "front" : preset == EXPIRY_PRESET_TO_FRIDAY ? "to Friday" : preset == EXPIRY_PRESET_TO_NEXT_FRIDAY ? "to next Friday" : preset == EXPIRY_PRESET_TO_OPEX ? "to monthly opex" : preset == EXPIRY_PRESET_TO_NEXT_OPEX ? "to next opex" : "to quarterly opex");
sb_text(" (");
sb_int(counted);
sb_text(counted == 1 ? " expiry)" : " expiries)");
}
function unitWord(): String {
return zone == 1 ? "shares" : zone == 2 ? "contracts" : "coins";
}
function writeTitle(): void {
sb_clear();
sb_text(LENS_NAMES[lens]);
sb_text(", ");
if (lens == IV_X_OI) sb_text("IV points x OI");
else if (lens > IV_X_OI) sb_text(zone == 0 ? "coins" : "contracts"); // open interest in the venue's own unit
else if (lens == VEGA) sb_text("$ per IV point");
else {
sb_text(inUnderlying ? unitWord() : "$");
sb_text(lens == GAMMA ? " per 1% move" : lens == DELTA ? " held" : lens == VANNA ? " per IV point" : " per day");
}
sb_text(", ");
if (preset != EXPIRY_PRESET_COUNT) { // the preset in place of the Expiries setting's range
writePreset();
str_title_sb();
return;
}
if (scope == SCOPE_TODAY) sb_text("same day");
else if (scope == SCOPE_WEEK) sb_text("within 7 days");
else if (scope == SCOPE_MONTH) sb_text("within 30 days");
else if (scope == SCOPE_NEAREST && nearestCount < expiryCount) {
sb_text("nearest ");
sb_int(nearestCount);
sb_text(" of ");
sb_int(expiryCount);
sb_text(" expiries");
str_title_sb();
return;
} else {
sb_text("all ");
sb_int(expiryCount);
sb_text(" expiries");
str_title_sb();
return;
}
sb_text(" (");
sb_int(counted);
sb_text(counted == 1 ? " expiry)" : " expiries)");
str_title_sb();
}
// onBar() runs once per bar: history rows carry an empty block and cost one read; the live bar measures the chain, writes
// the readings (NaN on history rows), the profile, the bars by expiry and the card's words.
function onBar(): void {
close = bar.close();
t = bar.time();
let measured = false; // the live bar carried a chain with a live expiry the setting counts
let chainCells = -1;
if (bar.isLast()) {
chainCells = in_chain_cells();
if (chainCells >= TUPLE && !isNaN(close) && !isNaN(t)) {
measure(chainCells);
measured = counted > 0;
}
}
const reading = measured && readings > 0;
out_net_exposure(reading ? net : NaN);
out_calls_exposure(reading ? calls : NaN);
out_puts_exposure(reading ? puts : NaN);
out_today_exposure(reading ? today : NaN);
out_top_strike(reading ? topStrike : NaN);
out_top_exposure(reading ? topValue : NaN);
out_zero_cross(reading ? zeroCross : NaN);
out_above_spot(reading ? above : NaN);
out_below_spot(reading ? below : NaN);
out_tone(reading ? 1.0 + headlineSign() : bar.isLast() ? 1.0 : NaN);
out_expiries_counted(measured ? f64(counted) : NaN);
if (measured) {
if (reading) writeProfile();
writeExpiries();
writeRead();
writeTitle();
} else if (bar.isLast()) {
// The live bar carried nothing to measure: the headline says why, so the card is never a row of blanks.
sb_clear();
sb_text(chainCells < TUPLE ? "Waiting for this symbol's options" : expiryCount == 0 ? "No expiry is still trading" : "No expiry in this setting's range");
str_read_sb();
sb_clear();
sb_text(LENS_NAMES[lens]);
sb_text(", no options data yet");
str_title_sb();
}
}How it works
One lens at a time. Every contract the Expiries setting counts adds one number to its strike and to its expiry. The strike table behind the profile and the largest strike keeps at most the 1,024 strikes nearest spot when a chain lists more. On the gamma lens the totals (the net, the calls, the puts, the same-day expiry, each expiry's bar and the sums each side of spot) read every counted contract, the same set the gamma curve reads; on every other lens they read the table's strikes, as the data plane's exposure fold sums them. Per contract, before the sign, with oi its open interest, multiplier its multiplier (100 on a US listed option, the point value on CME, 1 on Deribit) and spot its underlying:
| Lens | Per contract | Unit in dollars |
|---|---|---|
gamma | bsGamma(spot, strike, iv, years) * oi * multiplier * spot * spot * 0.01 | the dealers' delta change for a 1% move of spot, in dollars |
delta | delta * oi * multiplier * spot | the delta held, in dollars |
vanna | vanna * oi * multiplier * spot | the delta change for one IV point |
charm | charm * oi * multiplier * spot | the delta change as one calendar day passes |
vega | vega * oi * multiplier | the value change for one IV point |
iv_x_oi | mark_iv * oi | IV points times open interest (where the expensive open positions sit) |
oi | oi | open interest, contracts (coins on crypto) |
The sign: dealers long the calls, short the puts. That is the open-interest model the gamma map uses: customers sell the calls dealers hold and buy the puts dealers write, so the calls add and the puts subtract on gamma, vanna, charm, vega, IV times open interest and open interest. Delta keeps each option's own sign (a call's delta is positive, a put's negative), the way delta views read the chain. On the gamma lens the headline is the dealer regime of the options kit's GammaCurve over the counted expiries, the sign of net GEX at spot: above zero is long gamma (hedging leans against moves), below zero short gamma, exactly zero neutral; it is the same regime Gamma Map and the Options Dashboard print over the same expiries (The canonical numbers). Net vanna above zero means an IV rise lifts the dealers' delta, so they sell to stay hedged; below zero they buy. Charm above zero means each day passing lifts their delta, so they sell; below zero they buy.
Priced greeks. Delta is the chain's own. Gamma is priced as the kit's GammaCurve prices it, bsGamma() from the contract's mark IV and underlying at the chain's as-of with no rate, so the gamma lens's net over every expiry is the net GEX every options card reads. Vanna, charm and, where a venue serves none, vega are priced per contract by the kit's Greeks: Black-Scholes on spot on a US stock, at the Rate setting (4% by default); Black-76 on the underlying on futures and crypto, whose underlying is already the forward (crypto at a rate of 0). The chain's as-of is the live bar's close time, optionsAsOfMs(bar.time() * 1000, chart.interval_sec() * 1000): the block names the moment it was served to no module, and the bar's close is the clock Spot exposures reads its strike rows at on the same bar, never a time solved back from a gamma (two solves of one minute named two times, and a same-day gamma scales with 1 / sqrt(T)). Each contract's time to go runs from the as-of to its expiry's end in 365-day years, optionsYearsToGo(): on a US stock to 15 minutes past the stamp (a PM expiry stamped 16:00 New York trades until 16:15) and never under a second while it trades, so the same-day book keeps its gamma until 16:15; on CME and crypto to the stamp itself. For vanna, charm and vega a contract within 15 minutes of its expiry's end prices no time left. Charm is per calendar day: tools that multiply it by 365 print a yearly figure 365 times larger.
Units. dollars is the table above. underlying divides the four delta lenses by spot: shares on a US stock, coins on crypto, and on CME by spot times the point value, which is futures contracts. Vega stays in dollars per IV point, and the last two lenses keep their own units. The card's title names the unit in use (Gamma, $ per 1% move, all 11 expiries).
Expiries by the calendar. An expiry counts while it trades: on a US stock until 15 minutes past its stamp (optionsLiveUntilMs()), on CME and crypto until the stamp. 0dte counts the expiry whose trade date is today's on the market's own clock (optionsTradeDay(): New York on a US stock, Chicago on CME, UTC on crypto), never the one under 24 hours away, so at 16:05 New York the expiry stamped 16:00 is still today's; week and month count the expiries 7 and 30 trade days out or less on the same calendar (the difference of the two optionsTradeDay() dates; week is the rule Spot Exposures keeps its strike rows by, so the two cards count one set of expiries); nearest the N nearest live expiries; buckets every expiry, stacked by days to go: 0, 1 to 7, 8 to 30, 31 to 60, 61 to 120 and 121 or more. A tall bar built from the near buckets is exposure that decays within days; one built from the far buckets persists. Expiry preset (count) counts by the calendar in place of that range (Expiry presets): front the nearest live expiry, to_friday and to_next_friday every expiry on or before this Friday or the next one, to_opex and to_next_opex every expiry to this month's third Friday (next month's once it has passed) or to the one after, to_q_opex every expiry to the next quarterly third Friday, and all every one, each day a trade day on the market's clock; count keeps the Expiries setting, and buckets still stacks the counted expiries by days to go. The title then names the preset and how many it counts (Gamma, $ per 1% move, to Friday (3 expiries)).
By strike. The strikes within window_pct (8) percent of the chart's close dock on the price axis, at most 256, one row per strike, centred on zero: net above zero to one side in the up colour, below zero to the other in the down colour. split: calls_puts draws the calls one way and the puts the other; buckets stacks the six day buckets. Each shape has its own plot.levels, and only the one the settings pick gets a frame, so the other two stay absent. Whichever is drawn names the lens's nodes on their rows through the frame's labels_text (Node roles): the kit's NodeBoard loads each strike's net of the table against spot, the top is the largest net either way (on a tie the strike nearest spot, then the lower) and carries a star, the gate is the largest strictly between spot and the top at 35% of the top or more, and the floor and the ceiling are the largest strictly below and above spot, each with its share of the top as a whole percent (103 ★ top, 101 gate 36%, 97 floor 60%). Every other row stays bare, and the card keeps its numbers.
By expiry. One bar per counted expiry under the chart, labelled by its date and its days to go (16 Oct 1d, the kit's fbExpiryLabel; an expiry in another year reads its year, 15 Jan '27), in the up colour above zero and the down colour below. The panel's title names the lens.
The card reads the outputs. The headline is the lens's plain line; under it the net, the same-day expiry, the calls and the puts in si (1.24B), then five rows: the strike holding the largest net either way (the gamma magnet on the gamma lens), its exposure, the gamma flip over the counted expiries on every lens (the kit curve's zero nearest spot, walked out up to 50% each side; zero_cross reads NaN when none lies within 50%), and the sums over the strikes above and at or below spot.
What the settings do
- Lens: what the bars measure. gamma: what dealers trade per 1% move. delta: how much stock dealers must hold to hedge. charm, vanna: how that hedge changes with time (charm) or with option prices (vanna). vega: how much dealers gain or lose when option prices rise. iv_x_oi: implied volatility (how big a move option prices expect) times open interest. oi: open interest (contracts still held open).
- Units: dollars: in dollars. underlying: in this symbol's own units (shares, contracts or coins), for gamma, delta, vanna and charm.
- By strike: net: one bar per strike, calls minus puts. calls_puts: calls drawn one way, puts the other.
- Expiries: which expiries (the days the options end) count. all: every one still trading. 0dte: the one that expires today. week: within 7 trade days. month: within 30. nearest: the N soonest. buckets: all of them, stacked by days left.
- Nearest expiries: how many of the soonest expiries count when Expiries is set to nearest.
- Strike window, percent: how far the strikes on the price axis reach above and below the price, 8% by default.
- Rate, percent: the interest rate used to price vanna, charm and vega on US stock and CME options, while crypto uses 0.
- Expiry preset: picks expiries by the calendar, up to the date each choice names. front: the nearest expiry. to_friday, to_next_friday: this or next Friday. to_opex, to_next_opex: this or next monthly expiry, on the third Friday. to_q_opex: the next quarterly expiry (March, June, September or December). all: every expiry. count: follow the Expiries setting.
- Dealers: the lens in one plain line, such as whether dealers calm or chase price on gamma.
- Net: the lens summed over the counted expiries, calls adding and puts subtracting. On gamma, above zero means dealers calm price.
- Same-day expiry: the net of the expiry that settles today.
- Calls: the calls' part of the net.
- Puts: the puts' part of the net.
- Largest strike: the strike with the largest net either way. On gamma it is the magnet, a strike that tends to pull price.
- Its exposure: that strike's net.
- Gamma flip: the price where dealers switch from calming price to pushing it, for the counted expiries.
- Above price: the net of the strikes above the price.
- At or below price: the net of the strikes at or below the price.
Where it runs
It runs on coins with options on Deribit (a crypto options exchange), such as BTC, ETH and SOL. There a copy you run from the editor (where you write and run your own indicators) reads the coin's options. On a US stock chart it reads the stock's US listed options. On a futures chart from CME (Chicago futures exchange), it reads that future's options. Every indicator can read US listed options, 15 minutes behind unless you have real-time US options data. Every indicator in your browser can read CME options too, once you accept the CME market data terms. They run 10 minutes behind unless you have real-time CME data, and the legend names the source. Copies you run from the editor, publish yourself or run as a Cloud (Protected) copy all read US listed options. A Protected copy runs on OpenMarket's servers and keeps its code hidden. It does not run on a CME chart.
When data is missing
The card's headline says why instead of going blank. It reads "Waiting for this symbol's options" while the live bar has none. It reads "No expiry is still trading" when every listed expiry has stopped trading. It reads "No expiry in this setting's range" when Expiries counts none. 0dte does that on a day with no expiry. It reads "No gamma in this symbol's options", or the lens's own word, when no counted contract has a reading. That happens on an index whose option risk numbers (greeks) are not published yet. It also happens on options without implied volatility. The card's numbers then read - and the strike bars do not draw. The bars by expiry still stand while expiries are counted.
Customize it
- Another greek. Set Lens to
vannabefore an event that moves implied volatility, or tocharminto the close and over a weekend. - Shares instead of dollars. Set Units to
underlyingto read the hedge in the market's own units. - What decays and what stays. Set Expiries to
bucketsand read which days build each strike's bar. - This week's exposure. Set Expiry preset to
to_friday;to_q_opexcounts through the next quarterly expiry. - A wider ladder. Raise
window_pcton a volatile underlying; the window narrows the profile, never the totals.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Greek Exposure under HUDs.
- Press Run on a BTC chart: the profile docks on the price axis once the chain arrives, the bars by expiry stand under the chart and the card appears at the bottom centre.
- At the editor's Console prompt, type
net_exposureandzero_crossto read the net and the gamma flip on the live bar.
Concepts used
- Data sources for the
options_chaincelled class, its tuple and thevenueword - Options kit for
Greeks,optionsAsOfMs,optionsLiveUntilMs,optionsYearsToGoandoptionsTradeDay - Node roles for
NodeBoardand Expiry presets forexpiryPresetCount - Cards, frames and panels for frames,
plot.levelswith series andpanel.bars, and Panel frames forfbExpiryLabel - HUD cards, Blocks and tiles and The default look for the card, its tiles, the slot in the title and what a card with no
lookdraws