Spot exposures

View as MarkdownOpen the editor

Bar by bar, a heat map behind the candles shows where dealers (the market makers who hedge options) hedge most.

Up colour marks strikes (the option's price levels) where calls dominate, down colour where puts do. Lines mark the gamma flip (the price where dealers switch from calming price to pushing it). Two more mark the call and put walls (the strikes with the most dealer hedging). On an intraday chart with listed options, use it to see where hedging sits and how it shifts.

Under the hood: the headline reads net gamma, delta and vega over every expiry from the 10-minute options statistics (option_stats_10m). Those run up to 15 minutes behind the map. The map, the walls, the flip and the top node read the server's measure of each bar's strikes for the expiries within 7 trade days. That is option_strikes with fold: "kit", levels and curve (Data sources). It loads them through OptionStrikes.loadLevels, with its gamma curve read by the canonical numbers. It declares market.zone(), market.kind(), market.option_multiplier() and chart.interval_sec() for that measure. It ranks strikes with NodeBoard and paints an out.grid heat map. It restarts the change on each time.trade_date. It is the spot-exposures template: Spot Exposures under HUDs in the editor's starter list, and it compiles as written.

The wrun indicator

// Spot Exposures: bar by bar, a heat map shows where dealers (the market makers who hedge options) hedge most. Each
// band is a strike (the option's price level), painted behind the candles. Up colour means calls dominate a strike,
// down colour means puts do. Gamma (how fast dealers must hedge as price moves) leads the card. 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. A dashed line marks the gamma flip (the price where dealers switch
// from calming price to pushing it). Two more lines mark the call and put walls (the strikes with the most dealer
// hedging). A dotted line marks the top node, the strike with the largest exposure. A line under the chart follows net
// exposure through the day. Use it to see where dealer hedging sits and how it shifts.
//
// Under the hood: the headline reads every expiry: net gamma, delta and vega from the 10-minute options statistics
// (the option_stats_10m source: every live expiry and strike at open interest, gamma by Black-Scholes with no rate at
// each contract's stored mark IV, a row every ten minutes of the session), the newest row held on the bars after it
// until the next lands. The map and the levels read the strike rows the data plane folds every minute (the
// option_strikes source: each bar's newest minute of strike rows inside it, about seven days back) over the week
// Greek Exposure counts: the expiries live and 7 or fewer trade days out. The data plane measures each bar's week for
// the chart (the strike kit fold with its curve row), so a bar arrives as its levels, its gamma curve's readings and
// the lens at each strike, never the minutes' rows. A line under the chart follows the headline's net exposure (gamma
// per 1% move by default, delta held, or vega per IV point, in dollars), three step lines on the price chart follow
// the week's gamma flip and call and put walls, and a heat map behind the candles paints the lens strike by strike on
// every bar with strike rows (Map values shows each strike's level, or its change from the previous bar with strike
// rows). A card reads the gamma regime in one plain line, then the three nets, the change in net gamma since the
// session's first reading, the week's net gamma, the levels and the put/call open interest. Both sources share one
// convention: dealers long the calls and short the puts (calls add, puts subtract), delta in each option's own sign.
// The statistics run up to 15 minutes behind the strike rows (Statistics age counts the bars since the newest row,
// Strike data age the bars since the newest strike rows), and an underlying the data plane does not sample every ten
// minutes has none: until a row lands the headline reads the week's strike rows, and the card's title says so. The
// week's net gamma, its regime and the flip are the options kit's GammaCurve over each bar's week at its as-of
// (optionsAsOfMs: the bar's close time, the chain's clock too), each expiry live and priced to its chain's last trade
// (optionsLiveUntilMs on the market's zone and kind: a US stock or ETF expiry until 15 minutes past its stamp, a US
// index, CME or crypto expiry until its stamp), which the fold's curve row carries; only a bar with strike rows
// paints the map.
//
// Version 0.5 reads the headline over every expiry from the 10-minute statistics, where 0.4 read the week's strike
// rows; the week's net gamma stays an output of its own (net_gex_week).
//
// Version 0.6 marks the top node of each bar's strike rows (the options kit's NodeBoard over the lens by strike, read
// against the map's spot: the strike with the largest |exposure|) with a step line starred in its label and reads the
// net above spot and below it in the card.
//
// Version 0.7 reads the data plane's measure of each bar, where 0.6 downloaded every minute's strike rows and
// measured them itself, and declares the market's kind, so a US index chain's expiries leave at their stamp. 0.6's
// Expiry preset leaves with it: the fold counts the soonest expiries, never the calendar (Nearest expiries 1 is the
// front one).

section("Exposure");
param.choice("lens", ["gamma", "delta", "vega"], "gamma", { label: "Lens", description: "What the line and the map show, in dollars. gamma: what dealers trade per 1% move. delta: how much stock dealers must hold to hedge. vega: how much dealers gain or lose when option prices rise." });
param.choice("map_mode", ["level", "change"], "level", { label: "Map values", description: "level: each strike's exposure on the bar. change: how much it moved since the previous bar with strike data." });
param.int("nearest", 0, { min: 0, max: 7, label: "Nearest expiries", description: "How many of the soonest expiries (the days the options end) the map, flip, walls and week's numbers count. 0 counts every expiry within 7 trade days. The headline counts every expiry wherever the 10-minute statistics exist." });
param.number("window_pct", 3, { min: 0.5, max: 20, step: 0.5, label: "Map window, percent", description: "How far the map reaches above and below the price, in percent, at most 48 strike steps each way." });
input("close", ohlcv.close); // the chart's own close: the map's centre where the rows report no underlying
input("strikes", option_strikes.cells, { max_cells: 4000, venue: "auto", fold: "kit", nearest: "@nearest", window_pct: 100, lens: "@lens", step_rows: 1000, levels: true, curve: true, description: "This symbol's options by strike for each bar, for expiries within 7 trade days. The server measures each bar's levels, net gamma, gamma flip and lens at every strike up to twice the price." }); // per bar a levels row, a curve row and [0, strike, value] per strike, 14 values a row
input("trade_date", time.trade_date); // the bar's trade date: the change in net gamma counts from the session's first reading
input("stats_gex", option_stats_10m.net_gex, { venue: "auto", missing: "nan", description: "Net gamma over every live expiry, in dollars per 1% move, from the 10-minute options statistics. It lands on the bar of each sample and stays blank between samples and where this symbol is not sampled." }); // the three statistics share one read of the chain the strike rows read
input("stats_dex", option_stats_10m.net_dex, { venue: "auto", missing: "nan", description: "Net delta over every live expiry, in dollars held, each option in its own sign, from the same sample." });
input("stats_vex", option_stats_10m.net_vex, { venue: "auto", missing: "nan", description: "Net vega over every live expiry, in dollars per point of implied volatility, from the same sample." });
market.zone(); // the market's clock: the week's trade days and each chain's last trade, which the fold reads, and the trade date where the chart writes none
market.option_multiplier(); // the options' multiplier: 100 on a US stock, the point value on CME, 1 on a coin; the fold's gamma curve reads it
chart.interval_sec(); // the bar's length: the fold reads each bar at its close time, when its newest minute closes
// Version 0.7's market fact, after the chart's facts, where 0.6's Expiry preset stood.
market.kind(); // what the market trades: on New York's clock a US index (5) stops its options at their stamp, which the fold reads
output("exposure", line, lower, { color: "theme.text", width: 2, split: "level", up_color: "theme.up", down_color: "theme.down", split_fill: true, format: "usd", label: "Net exposure", description: "The headline's net exposure in the lens, in dollars, over every expiry from the 10-minute statistics. Where those do not exist, it reads the week's strikes." });
output("zero_gamma", line, overlay, { color: "theme.muted", width: 1, step: true, line_style: "dashed", format: "price", label: "Gamma flip", description: "The gamma flip for the week's counted expiries: the price nearest now where dealer gamma crosses zero. Blank when none lies within 50% of the price." });
output("call_wall", line, overlay, { color: "theme.up", width: 1, step: true, format: "price", label: "Call wall", description: "The call wall: the strike holding the most call gamma, often a ceiling." });
output("put_wall", line, overlay, { color: "theme.down", width: 1, step: true, format: "price", label: "Put wall", description: "The put wall: the strike holding the most put gamma, often a floor." });
// The readings, data-only: the card's tiles read them and the Console can too. Each carries its newest reading: the
// nets the newest statistics row (else the week's), the rest the newest strike rows at or before its bar.
output("net_gex", none, overlay, { description: "Net gamma at open interest, in dollars per 1% move, over every expiry from the newest 10-minute sample. Without those statistics it reads the week's net gamma." });
output("net_dex", none, overlay, { description: "Net delta, in dollars held, each option in its own sign. Every expiry from the statistics, or the week's strikes." });
output("net_vex", none, overlay, { description: "Net vega, in dollars per point of implied volatility. Every expiry from the statistics, or the week's strikes." });
output("call_gex", none, overlay, { description: "The calls' gamma, in dollars per 1% move." });
output("put_gex", none, overlay, { description: "The puts' gamma, in dollars per 1% move, as a positive number." });
output("gex_change", none, overlay, { description: "Net gamma now minus net gamma at the session's first reading from the same source, in dollars per 1% move." });
output("max_pain", none, overlay, { description: "Max pain: the strike where open options would pay out the least at expiry." });
output("put_call_oi", none, overlay, { description: "Put open interest (puts still open) divided by call open interest." });
output("rows_age", none, overlay, { description: "Bars since the newest bar with strike data: 0 on such a bar, blank before the first." });
output("tone", none, overlay, { description: "The headline's regime as a code: 0 short gamma, 1 no reading or flat, 2 long gamma." });
output("map_low", none, overlay, { description: "The bottom edge of the map's lowest band on this bar." }); // the heat map reads it
output("map_step", none, overlay, { description: "The height of one map band in price on this bar: the finest strike step inside the window." });
out.grid("map", { rows: 96 }); // 96 data-only outputs map_0..map_95, one per strike step, written with out_map(row, value)
plot.heatmap({ name: "exposure_map", grid: "map", price_low: "map_low", price_step: "map_step", palette: ["theme.down", "theme.bg", "theme.up"], center: 0, scale: "sqrt", auto_quantile: 0.98, opacity: 0.7, behind_candles: true, label: "Exposure by strike", tooltip: "{{value:usd}} at {{price}}" }); // the chart's down colour where puts carry the strike, its up colour where calls do
// Version 0.5's readings, after the map's, so every output before them keeps its slot.
output("net_gex_week", none, overlay, { description: "Net gamma of the week's counted expiries at the current price, in dollars per 1% move. It is the headline where the chart has no 10-minute statistics." });
output("stats_age", none, overlay, { description: "Bars since the newest 10-minute sample: 0 on its bar, blank before the first or where none are taken." });
// Version 0.6's reading, after 0.5's: the top node, starred in its label.
output("top_node", line, overlay, { color: "theme.text", width: 1, step: true, line_style: "dotted", format: "price", label: "Top node ★", description: "The top node: the strike with the largest exposure in the lens, either way, over the week's counted expiries. A tie goes to the strike nearest the price, then the lower one." });
string("read", { max_bytes: 64 }); // the headline: the gamma regime in one plain line and its age, or why there is none
string("title", { max_bytes: 96 }); // the card's title: the headline's measure, its expiries and where it reads them
string("sides", { max_bytes: 48 }); // the card's by-side row: the lens's net above spot and below it, compact and signed

// The card: the gamma regime leads as the headline, then the three nets, the week's net gamma, the levels of the newest
// strike rows (the top node and the lens's net either side of spot among them) and the two ages.
render.hud("spot", {
  position: "bottom_center",
  title: "{{title}}",
  columns: 2,
  tiles: [
    tile.pill("Dealers", "read", { headline: true }),
    tile.value("Net gamma", "net_gex", { format: "usd" }),
    tile.value("Change since session start", "gex_change", { format: "usd" }),
    tile.value("Net delta", "net_dex", { format: "usd" }),
    tile.value("Net vega", "net_vex", { format: "usd" }),
    tile.rows([
      ["Net gamma within 7 days", "net_gex_week", "usd"],
      ["Gamma flip", "zero_gamma", "price"],
      ["Call wall", "call_wall", "price"],
      ["Put wall", "put_wall", "price"],
      ["Top node ★", "top_node", "price"],
      ["Net above and below price", "sides"], // Above +1.2M | Below -640K: the lens's net of the strikes above spot and below it
      ["Max pain", "max_pain", "price"],
      ["Put/call open interest", "put_call_oi", "0.00"],
      ["Strike data age, bars", "rows_age", "int"],
      ["Statistics age, bars", "stats_age", "int"],
    ]),
  ],
});

const ROWS = 96; // the map's rows, the grid's declared count
const HALF = 48; // rows each side of the strike nearest the underlying
const GAMMA = 0;
const DELTA = 1;
const rowValue = new StaticArray<f64>(ROWS); // this bar's map, folded from the strike table
const prevStrike = new StaticArray<f64>(in_strikes_max_cells); // the previous strike rows' table: its strikes, ascending
const prevValue = new StaticArray<f64>(in_strikes_max_cells); // and the lens at each, for the change map
let table = new OptionStrikes(1); // one bar's week as the fold measured it: its levels, its curve's readings and the lens at each strike; sized in onStart()
let lens = GAMMA; // settings, read in onStart()
let changeMap = false;
let nearest = 0;
let windowPct = 0.03;
let zone = 0;
let prevCount = -1; // strikes in the previous table; -1 before the first bar with strike rows
let sessionKey: f64 = NaN; // the trade date the bars are in, days since 1970-01-01
let sessionFirstGex: f64 = NaN; // the week's net gamma at the session's first strike rows
let statsFirstGex: f64 = NaN; // net gamma at the session's first statistics row
let age = -1; // bars since the newest bar with strike rows; -1 before the first
let statsAge = -1; // bars since the bar the newest statistics row landed on; -1 before the first
// The newest strike rows' readings, the week's, carried to the bars after them until the next rows arrive.
let zeroGamma: f64 = NaN;
let callWall: f64 = NaN;
let putWall: f64 = NaN;
let weekGex: f64 = NaN;
let weekRegime: f64 = NaN; // the sign of the week's net gamma: 1, -1 or 0
let weekDex: f64 = NaN;
let weekVex: f64 = NaN;
let weekChange: f64 = NaN;
let callGex: f64 = NaN;
let putGex: f64 = NaN;
let maxPain: f64 = NaN;
let putCallOi: f64 = NaN;
// The newest statistics row's readings over every expiry, held until the next row lands.
let statsGex: f64 = NaN;
let statsDex: f64 = NaN;
let statsVex: f64 = NaN;
let statsChange: f64 = NaN;
let regime: f64 = NaN; // the headline's regime: the statistics' sign of net gamma once a row landed, else the week's
// Version 0.6: the newest strike rows' nodes, carried like the levels.
let board = new NodeBoard(1); // one bar's nodes over the lens by strike; sized in onStart()
let topNode: f64 = NaN;
let aboveNet: f64 = NaN; // the lens's net of the strikes above the map's spot and below it
let belowNet: f64 = NaN;

function onStart(): void {
  table = new OptionStrikes(in_strikes_max_cells); // a bar's week lists at most max_cells strikes, so a load is never refused
  lens = i32(p_lens());
  changeMap = p_map_mode() == 1.0;
  nearest = i32(p_nearest());
  windowPct = p_window_pct() / 100.0;
  zone = i32(p_market_zone());
  board = new NodeBoard(in_strikes_max_cells); // a block holds at most max_cells strikes
}

function trackSession(t: f64): void { // the session: net gamma's change counts from its trade date's first reading
  const stamp = in_trade_date(); // epoch seconds of the trade date, as the chart writes it
  const key = isFinite(stamp) ? Math.floor(stamp / 86400.0) : optionsTradeDay(t * 1000.0, zone);
  if (isNaN(key)) return;
  if (isNaN(sessionKey) || key > sessionKey) {
    sessionKey = key;
    sessionFirstGex = NaN; // a new session: its first strike rows and its first statistics row set the bases
    statsFirstGex = NaN;
  }
}

// ── The lens, strike by strike, and the previous rows' value at a strike ──
function lensAt(k: i32): f64 { // the lens at the table's k-th strike (ascending), as the fold measured it
  return table.value(k);
}
function previousAt(strike: f64): f64 { // the previous rows' lens at this strike; 0 where they did not list it
  let lo = 0;
  let hi = prevCount;
  while (lo < hi) {
    const mid = (lo + hi) >> 1;
    if (prevStrike[mid] < strike) lo = mid + 1;
    else hi = mid;
  }
  return lo < prevCount && prevStrike[lo] == strike ? prevValue[lo] : 0.0;
}
function keepTable(): void { // this bar's table becomes the previous rows
  const count = table.strikeCount();
  for (let k = 0; k < count; k += 1) {
    prevStrike[k] = table.strike(k);
    prevValue[k] = lensAt(k);
  }
  prevCount = count;
}

// ── The map: one row per strike step, centred on the strike nearest the underlying ──
function clearMap(): void { // no map on this bar: every cell empty
  for (let r = 0; r < ROWS; r += 1) out_map(r, NaN);
  out_map_low(NaN);
  out_map_step(NaN);
}
function writeMap(spot: f64): void {
  const count = table.strikeCount();
  const lo = spot * (1.0 - windowPct);
  const hi = spot * (1.0 + windowPct);
  let first = 0; // the window's strikes: [first, last)
  while (first < count && table.strike(first) < lo) first += 1;
  let last = first;
  while (last < count && table.strike(last) <= hi) last += 1;
  if (last <= first || (changeMap && prevCount < 0)) { // no strike inside the window, or no earlier rows to change from
    clearMap();
    return;
  }
  let step = Infinity; // the finest strike step inside the window: one row per step
  for (let k = first + 1; k < last; k += 1) {
    const gap = table.strike(k) - table.strike(k - 1);
    if (gap > 0.0 && gap < step) step = gap;
  }
  if (step == Infinity) { // one strike in the window: its step to a neighbour, else a tenth of a percent of spot
    if (first > 0) step = table.strike(first) - table.strike(first - 1);
    else if (first + 1 < count) step = table.strike(first + 1) - table.strike(first);
    else step = spot * 0.001;
  }
  let centre = first; // the strike nearest the underlying, the lower one on a tie
  for (let k = first + 1; k < last; k += 1) {
    if (Math.abs(table.strike(k) - spot) < Math.abs(table.strike(centre) - spot)) centre = k;
  }
  const anchor = table.strike(centre);
  for (let r = 0; r < ROWS; r += 1) rowValue[r] = NaN;
  for (let k = first; k < last; k += 1) {
    const strike = table.strike(k);
    const row = HALF + i32(Math.round((strike - anchor) / step));
    if (row < 0 || row >= ROWS) continue; // more than 48 steps from the centre
    const v = changeMap ? lensAt(k) - previousAt(strike) : lensAt(k);
    rowValue[row] = isNaN(rowValue[row]) ? v : rowValue[row] + v; // a strike off the step's grid shares the nearest row
  }
  for (let r = 0; r < ROWS; r += 1) out_map(r, rowValue[r]);
  out_map_low(anchor - (f64(HALF) + 0.5) * step); // each row spans its strike plus and minus half a step
  out_map_step(step);
}

// ── The card's words ──
function sbCompactSigned(v: f64): void { // a net in K, M, B or T with its sign: +1.2M, -640K, 0
  if (v > 0.0) sb_text("+");
  sb_compact(v, 1);
}
function writeWords(): void {
  const stats = statsAge >= 0;
  const ago = stats ? statsAge : age; // the headline's age: its statistics row's, else its strike rows'
  sb_clear();
  if (ago < 0) sb_text("No strike data on this chart yet");
  else if (regime > 0.0) sb_text("Long gamma: dealers calm price");
  else if (regime < 0.0) sb_text("Short gamma: dealers chase price");
  else sb_text("Neutral gamma: no dealer hedging"); // exactly 0, or no contract to read
  if (ago > 0) { // the headline's newest reading is on an earlier bar
    sb_text(" (");
    sb_int(ago);
    sb_text(ago == 1 ? " bar ago)" : " bars ago)");
  }
  str_read_sb();
  sb_clear();
  if (stats) sb_text("Net gamma, all expiries, open interest, up to 15 minutes behind the map");
  else {
    sb_text("Net gamma, ");
    if (nearest == 0) sb_text("expiries within 7 days");
    else {
      sb_text("nearest ");
      sb_int(nearest);
      sb_text(nearest == 1 ? " expiry" : " expiries");
    }
    sb_text(", no 10-minute statistics here");
  }
  str_title_sb();
  sb_clear(); // the newest strike rows' net either side of spot, in the lens
  if (age < 0) sb_text("-");
  else {
    sb_text("Above ");
    sbCompactSigned(aboveNet);
    sb_text(" | Below ");
    sbCompactSigned(belowNet);
  }
  str_sides_sb();
}

// onBar(): a bar with strike rows reads the data plane's measure of its week, one without keeps the newest readings; a
// bar holding a statistics row takes its readings over every expiry, one without keeps the newest; the headline reads
// the statistics once a row has landed, else the week's; the live bar writes the card.
function onBar(): void {
  const close = bar.close();
  const t = bar.time();
  trackSession(t);
  const n = in_strikes_cells();
  // The week's measure: the levels row, the curve row and the lens at each strike. A bar whose week keeps no strike
  // arrives empty, as a bar without rows; one whose minute held more than max_cells rows loads -1.
  const kept = n > 0 ? table.loadLevels(in_strikes_view(), n) : 0;
  if (kept > 0) {
    weekGex = table.gexAtSpot(); // the curve row: GammaCurve's net gamma at S0 over the week, its regime and its flip
    weekRegime = table.gammaRegime();
    weekDex = table.totalNetDex();
    weekVex = table.totalNetVex();
    callGex = table.totalCallGex();
    putGex = table.totalPutGex();
    maxPain = table.maxPain();
    putCallOi = table.putCallRatio();
    zeroGamma = table.gammaFlip();
    callWall = table.callWall();
    putWall = table.putWall();
    if (isNaN(sessionFirstGex)) sessionFirstGex = weekGex;
    weekChange = weekGex - sessionFirstGex;
    age = 0;
    const under = table.underlying();
    const spot = under > 0.0 ? under : close;
    if (spot > 0.0) writeMap(spot);
    else clearMap();
    keepTable();
    board.load(prevStrike, prevValue, prevCount, spot); // the nodes over this bar's lens by strike, read against the map's spot
    topNode = board.strike(board.top());
    aboveNet = board.aboveNet();
    belowNet = board.belowNet();
  } else {
    if (age >= 0) age += 1;
    clearMap();
  }
  const rowGex = in_stats_gex(); // finite on the bar a statistics row landed on
  if (isFinite(rowGex)) {
    statsGex = rowGex;
    statsDex = in_stats_dex();
    statsVex = in_stats_vex();
    if (isNaN(statsFirstGex)) statsFirstGex = rowGex;
    statsChange = rowGex - statsFirstGex;
    statsAge = 0;
  } else if (statsAge >= 0) statsAge += 1;
  const stats = statsAge >= 0;
  const netGex = stats ? statsGex : weekGex;
  const netDex = stats ? statsDex : weekDex;
  const netVex = stats ? statsVex : weekVex;
  regime = stats ? dealerRegime(statsGex) : weekRegime;
  const headAge = stats ? statsAge : age;
  out_exposure(lens == GAMMA ? netGex : lens == DELTA ? netDex : netVex);
  out_zero_gamma(zeroGamma);
  out_call_wall(callWall);
  out_put_wall(putWall);
  out_net_gex(netGex);
  out_net_dex(netDex);
  out_net_vex(netVex);
  out_call_gex(callGex);
  out_put_gex(putGex);
  out_gex_change(stats ? statsChange : weekChange);
  out_max_pain(maxPain);
  out_put_call_oi(putCallOi);
  out_rows_age(age >= 0 ? f64(age) : NaN);
  out_tone(headAge < 0 || isNaN(regime) ? 1.0 : 1.0 + regime);
  out_net_gex_week(weekGex);
  out_stats_age(stats ? f64(statsAge) : NaN);
  out_top_node(topNode);
  if (bar.isLast()) writeWords();
}

How it works

The server measures each bar. Each bar's strike rows are the newest minute of them inside it, one [strike, expiry_ms, net_gex, call_gex, put_gex, net_dex, net_vex, call_oi, put_oi, call_iv, put_iv, underlying] row per expiry and strike, and a bar holds hundreds to thousands of them. The template never downloads them. Its input asks the data plane for the strike kit fold (fold: "kit" with levels: true and curve: true), and the server measures each bar with the options kit's own rules and sends the result: a levels row (the totals, the call and put walls, max pain and the underlying), a curve row (the gamma curve's net gamma at S0, its flip, S0 and the as-of) and a [0, strike, value] row for each strike, value the lens. OptionStrikes.loadLevels(cells, count) reads them (Chain page views). A strike listed under two expiries is one row, its exposures summed; a side the strike does not list counts as 0. Nearest expiries (nearest: "@nearest") keeps the N soonest expiries of the bar's week (0 keeps every one), and Lens rides the ask too (lens: "@lens"), so changing either fetches again. window_pct: 100 with step_rows: 1000 sends every strike up to twice the underlying, so the map's window, the top node and the nets by side read the whole table as they would off the raw rows. A bar whose minute held more than max_cells (4,000) rows arrives refused (loadLevels() returns -1).

The week. The server keeps each bar's week before it measures anything: an expiry still trading at the bar's as-of, its close time (each expiry's last trade on the market's clock and kind: 15 minutes past the stamp on a US stock or ETF chain, since a PM expiry stamped 16:00 New York trades until 16:15; the stamp itself on a US index chain, on CME and on a coin), and whose trade date is 7 or fewer days after the as-of's on the market's calendar (New York on a US stock, Chicago on CME, UTC on a coin). market.zone() and market.kind() declare the two facts the fold's week reads, so an index chain's expiries leave at their stamp. It is the rule Greek Exposure's week counts by, so the two cards count one set of expiries on one chart. The data plane serves the expiries within 7 x 24 hours of the minute, so today the rule drops no row it serves; the totals, the walls, max pain, the strikes and the gamma curve all read the week, and a bar whose week keeps no strike arrives empty, as a bar without rows.

No Expiry preset. Expiry preset is removed in 0.7.0: the server's fold cannot pick expiries by the calendar yet (to Friday, to the monthly opex), so the setting could no longer do what it says. Nearest expiries counts the soonest expiries instead: 1 keeps the front expiry, 0 every expiry within 7 days.

The convention. The strike rows put the dealers long the calls and short the puts: a row's net_gex is the calls' dollar gamma minus the puts', per 1% move of the underlying, net_vex the calls' vega dollars minus the puts', and net_dex the delta dollars of both sides with each option in its own sign (puts negative). The 10-minute statistics keep the same convention, so the two sources add up the same way. The line follows the headline: net_gex on the gamma lens, net_dex or net_vex on the delta and vega lenses, each over every expiry from the statistics, or the week's table total (totalNetDex(), totalNetVex()) where the chart has none.

The headline: every expiry. input("stats_gex", option_stats_10m.net_gex, { venue: "auto", missing: "nan" }) and its twins stats_dex and stats_vex read the data plane's 10-minute options statistics of the chain the strike rows read: one read for the three, under the same venue word. Net gamma is open interest over every live expiry and strike (Black-Scholes gamma with no rate at each contract's stored mark IV, times the open interest and the multiplier, USD per 1% move), net delta each option in its own sign, and net vega per IV point. A row lands on the bar holding its stamp and reads NaN on the bars between, so the module holds the newest row itself and stats_age counts the bars since the bar it landed on. Once a row has landed, net_gex, net_dex, net_vex, the regime (the kit's dealerRegime(net_gex)), gex_change and the line read it, and the title reads Net gamma, all expiries, open interest, up to 15 minutes behind the map: the newest row is about 15 to 30 minutes old, up to 15 minutes behind the strike rows the map and the levels read. Before the first row, and on an underlying the data plane does not sample every ten minutes (CME roots other than ES and NQ, coins off its list), the inputs read NaN and the headline reads the week's strike rows, with the title Net gamma, expiries within 7 days, no 10-minute statistics here (nearest 2 expiries in place of the week when Nearest expiries counts fewer). net_gex_week keeps the week's net gamma beside the headline on every bar, the number the card's rows show as Net gamma within 7 days. Near a US stock's close the two sources count the same-day expiry apart: the statistics run its time to the 16:00 stamp with no 15 minutes of trading after it, so the 15:50 row carries a larger same-day book and the 16:00 and 16:10 rows none, while the week's strike rows keep it until 16:15.

The week's net gamma, its regime and the flip. The server computes the gamma curve for each bar and sends its readings in the curve row: it loads the week's rows into the kit's GammaCurve (loadStrikes), each row a call and a put with that side's open interest and IV, priced at the bar's as-of. The block names no minute (the chart stamps it at the bar's open), and the newest minute inside a bar closes when the bar does, so the as-of is the bar's close time (optionsAsOfMs): the same clock Greek Exposure and the Options Dashboard read the chain 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), so two cards on one chart read two numbers). Each contract's time to go runs to its expiry's last trade (optionsYearsToGo: 15 minutes past the stamp on a US stock or ETF, and never under a second while it trades, so a same-day contract keeps its gamma until 16:15; the stamp on a US index, CME or a coin). market.option_multiplier() and chart.interval_sec() declare the multiplier and the bar's length the curve reads: 100 on a US stock, the point value on CME, 1 on a coin. gexAtSpot() is net_gex_week, the curve at S0 (the nearest live expiry's median underlying), gammaRegime() the week's regime, its sign (the headline's where the chart has no statistics), and gammaFlip() is zero_gamma, the gamma flip, the curve's zero nearest S0 within 50%: the numbers the module's own GammaCurve gives over the same rows, bit for bit, and the numbers the Options Dashboard and every other options card read over the same expiries (The canonical numbers). The flip and the walls stay the week's even while the headline reads every expiry, so the regime and the side of the flip spot is on can disagree.

The levels. On every bar with strike rows the levels row carries the call wall and the put wall (callWall() and putWall(): the strikes holding the most call and put dollar gamma) and max pain (maxPain(): the listed strike where the open interest's payout at expiry is least), measured over every strike of the week. The three step lines draw the gamma flip and the two walls, and a fourth the top node; max pain reads in the card.

The top node. On every bar with strike rows the kit's NodeBoard loads the lens by strike (the fold's value(i) at each strike: net gamma, delta or vega) against the map's spot, the rows' underlying or else the chart's close (Node roles). top_node is the top: the strike with the largest exposure either way, on a tie the one nearest spot, then the lower, NaN when every strike nets to zero. It draws as a dotted step line labelled Top node ★ and reads as a row in the card. The card's "Net above and below price" row reads the sides slot: the lens's net of the strikes above spot and of those below it, compact and signed (Above +1.2M | Below -640K); a strike at spot counts in neither. Both are carried to the bars after them, like the levels.

The map. On a bar with strike rows the module writes 96 rows from the fold's strikes (strike(i) and the lens at it, value(i)), centred on the strike nearest the underlying (the rows' own underlying, else the chart's close), one row per strike step: the finest gap between neighbouring strikes inside Map window (3% each side by default), so a ladder of $1 strikes near the money and $5 strikes further out puts each strike on its own row and leaves the rows between the $5 strikes empty. A strike off the step's grid shares the nearest row. map_low is the bottom edge of the lowest row and map_step the row height, so each strike's row spans its price plus and minus half a step; plot.heatmap({ grid: "map", palette: ["theme.down", "theme.bg", "theme.up"], center: 0 }) paints the chart's down colour where puts carry the strike and its up colour where calls do. With Map values on change, each strike reads its lens minus the previous strike rows' (0 where they did not list it), and the first bar with strike rows paints nothing.

Carried readings. The lines and the card carry their newest readings, so a minute the rows missed does not break them: the levels and the week's numbers the newest strike rows at or before each bar (rows_age counts the bars since, 0 on a bar that carries its own), the headline the newest statistics row (stats_age). The headline says "(3 bars ago)" when its newest reading is not the live bar's. Only a bar with strike rows paints the map.

The session's change. gex_change is net gamma minus net gamma at the session's first reading of the same source: the first statistics row of the bar's trade date (time.trade_date, else the trade date on the market's clock), or its first strike rows where the chart has no statistics. It starts at 0 each session and reads how much dealer gamma the day added or removed; until the session's first reading lands it holds the previous session's.

What the settings do

  • Lens: what the line and the map show, in dollars. gamma: what dealers trade per 1% move. delta: how much stock dealers must hold to hedge. vega: how much dealers gain or lose when option prices rise.
  • Map values: level paints each strike's exposure, and change paints how much it moved since the previous bar with strike data.
  • Nearest expiries: how many of the soonest expiries (the days the options end) the map, flip and walls count. 0 counts all within 7 trade days.
  • Map window, percent: how far the map reaches above and below the price, 3% by default.
  • Dealers: whether dealers calm price (long gamma) or chase it (short gamma). It adds the reading's age in bars when it is not from the live bar.
  • Net gamma: what dealers must trade for each 1% move over every expiry, in dollars.
  • Change since session start: how much net gamma grew or shrank since the session's first reading.
  • Net delta: the position dealers hold, in dollars, each option counted in its own direction.
  • Net vega: what dealers gain or lose, in dollars, for each point of implied volatility.
  • Net gamma within 7 days: net gamma of the expiries within 7 trade days only.
  • Gamma flip: the price where dealer gamma turns from positive to negative for those expiries.
  • Call wall: the strike with the most call gamma, often a ceiling.
  • Put wall: the strike with the most put gamma, often a floor.
  • Top node ★: the strike with the largest exposure in the lens.
  • Net above and below price: the lens's net for the strikes above the price and for those below it.
  • Max pain: the strike where open options would pay out the least at expiry.
  • Put/call open interest: put open interest (contracts still held open) divided by call open interest.
  • Strike data age, bars: how many bars ago the newest strike data arrived.
  • Statistics age, bars: how many bars ago the newest 10-minute sample arrived.

Where it runs

It runs on coins with listed options, where the chart reads the coin's own options by strike. So does a copy you run from the editor (where you write and run your own indicators). On a US stock or ETF chart with US listed options, every indicator in the browser can read them. They run 15 minutes behind unless you have real-time US options data. On a futures chart from CME (Chicago futures exchange), every indicator in the browser can read them too, once you accept the CME market data terms (Limitations). They run 10 minutes behind unless you have real-time CME data. A chart whose market lists no options shows no strike data. The chart asks the server for each bar's measured strikes with the gamma curve. An older chart app without that measure shows an error that names it. The headline's 10-minute statistics cover the symbols sampled every ten minutes. On any other symbol the headline reads the strikes of the expiries within 7 trade days.

When data is missing

A bar without strike data paints no map and keeps the newest readings. That happens outside the session or on a minute the data skipped. A bar whose minute held more than 4,000 strike entries is skipped too, because it is too large to load. Net gamma, the regime and the flip stay blank on a bar whose nearest live expiry lacks the symbol's price. They never fall back to the chart's close, and stored strike data always carries a price. Before the first strike data the week's numbers stay blank. With no 10-minute sample either, the headline reads "No strike data on this chart yet". A bar without a new sample keeps the newest one. Before the first sample, or where the symbol is not sampled every ten minutes, the headline reads the week's strikes. The title then says "no 10-minute statistics here". A strike that lists one side reads that side alone. A side without implied volatility adds nothing to the implied volatility weighting. An expiry that has stopped trading, or is more than 7 trade days out, is left out of every reading. Strike data reaches back about seven days, so older bars on a longer chart draw nothing.

Customize it

  • The front expiry alone. Set Nearest expiries to 1 for the exposure that settles first: the map, the flip, the walls and the week's numbers follow it, and the headline keeps every expiry where the chart has the statistics.
  • Where it changed. Set Map values to change: rows in the up colour are strikes where dealer gamma grew since the previous bar, rows in the down colour where it fell.
  • A wider map. Raise Map window; a fine ladder stops at 48 strike steps each side.
  • Delta or vega. Set Lens to delta or vega: the line follows the headline's net delta or vega and the map the week's, strike by strike; the walls and the regime stay gamma's.

Run it

  1. In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Spot Exposures under HUDs.
  2. Press Run on a US stock or ETF chart on a 1m or 5m interval: the line, the walls and the map fill bar by bar once the strike rows arrive.
  3. At the editor's Console prompt, type net_gex (every expiry), net_gex_week (the week's), zero_gamma (the gamma flip) and gex_change to read them on the live bar; stats_age and rows_age say how old each source is.

Concepts used