Market share

View as MarkdownOpen the editor

A donut and a table under the chart split today's US options trading by exchange.

The shares count calls (bets on a rise) and puts (bets on a fall), or one side alone. A bigger slice means more of the market's contracts trade on that exchange. Exchanges you do not pick show as Other, and the card names the leader with its share. Use it on US stock charts to see where options trade: crypto and CME (Chicago futures exchange) are not covered.

Under the hood: the recipe reads options_flow call and put contracts, the whole market's under scope: "market". Each exchange's comes under scope: "venue" named by its exchange id, behind the options of a multi setting through when and when_bit (Data sources). The trade date comes from the time source (Data sources). It draws a panel.pie and a panel.table from frames written on the live bar (Frames and panels). It also draws a render.hud card in the chart's default look from data-only readings and string texts (HUD cards, The default look). It is also the market-share template, the Market Share card under Beyond the time axis in the editor's starter list, and it compiles as written.

The wrun indicator

// Market Share: a donut and a table under the chart split today's US options trading by exchange. The shares count
// calls (bets on a rise) and puts (bets on a fall), or one side alone. A bigger slice means more of the market's
// contracts trade on that exchange. Exchanges you do not pick show as Other, and the card names the leader with its
// share. Use it on US stock charts to see where options trade: crypto and CME (Chicago futures exchange) are not
// covered.
//
// Technical notes: where the US listed options market trades its contracts, exchange by exchange. A donut under the
// chart cuts the market's contracts of today, or of the newest sessions, into each exchange's share, the part no picked
// exchange accounts for as Other, the total in the hole; a table beside it lists each exchange with its exchange id,
// its call and put contracts, the contracts measured and its share, largest first, then Other and every venue together.
// Calls or puts narrows the measure to one side. A card at the top right names the leader with its share, the next two,
// how much of the market the picked exchanges account for and the bars left out. Each exchange is one read
// (options_flow's venue scope, named by its exchange id), fetched only while it is picked in Exchanges; the whole is
// the market scope's own total. Every exchange read is one data slot of the chart's budget on a copy run from the
// editor (the market and nine exchanges are ten, a Plus chart's whole budget; OpenMarket's own package charges one), so
// the nine exchanges that trade the most contracts are read by name, two fields each, the five largest picked by
// default and the other four in Exchanges, and the rest (Cboe BZX, Nasdaq MRX, MIAX Sapphire and Emerald, MEMX, Nasdaq
// GEMX and BX, Cboe C2, MIAX Pearl and any newer venue) read as Other. A bar counts only when the market and at least
// one exchange both served a row, so the shares always divide like by like; a bar with one and not the other is left
// out and counted. Venue rows are kept 7 days at 1 minute and daily for good (no 5-minute tier), the market's 7 days at
// 1 minute, 30 at 5 minutes and daily for good, so on an intraday chart older bars carry no venue row. The shares are a
// US stock chart's (market.zone() 1): a CME chain trades on one venue and the crypto venues are not read here, so on
// those charts no read is asked (needed_by), nothing draws and the card says why.

section("What it measures");
param.choice("types", ["calls and puts", "calls", "puts"], "calls and puts", { label: "Calls or puts", description: "Which contracts count: calls (bets on a rise) and puts (bets on a fall), calls only or puts only." });
param.int("sessions", 1, { min: 1, max: 30, label: "Sessions", description: "How many of the newest sessions the shares cover, today included." });
param.multi("venues", ["Cboe Options", "NYSE Arca", "NYSE American", "Nasdaq PHLX", "Nasdaq Options", "MIAX Options", "Cboe EDGX", "Nasdaq ISE", "BOX"], ["Cboe Options", "NYSE Arca", "NYSE American", "Nasdaq PHLX", "Nasdaq Options"], { label: "Exchanges", description: "The exchanges to show. Each one loads its own data, only while picked. On a copy you run from the editor, each one counts once against the chart's data budget. Trading on other exchanges shows as Other." });
input("close", ohlcv.close); // the chart's own candles: the bar grid (the shares read the whole US market on any US stock chart)
input("trade_date", time.trade_date); // the bar's trade date, the New York date on a US stock: the sessions the window counts
// The whole: the market scope's call and put contracts. Then each exchange's under the venue scope, named by its id
// and read only while picked (when_bit is its place in Venues).
input("mkt_calls", options_flow.call_contracts_total, { scope: "market", missing: "nan", needed_by: { size_unit: [2, 3] }, description: "All exchanges: call contracts in this bar." });
input("mkt_puts", options_flow.put_contracts_total, { scope: "market", missing: "nan", needed_by: { size_unit: [2, 3] }, description: "All exchanges: put contracts in this bar." });
input("xcbo_calls", options_flow.call_contracts_total, { scope: "venue", venue: "XCBO", when: "venues", when_bit: 0, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Cboe Options: call contracts in the bar" });
input("xcbo_puts", options_flow.put_contracts_total, { scope: "venue", venue: "XCBO", when: "venues", when_bit: 0, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Cboe Options: put contracts in the bar" });
input("arco_calls", options_flow.call_contracts_total, { scope: "venue", venue: "ARCO", when: "venues", when_bit: 1, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "NYSE Arca: call contracts in the bar" });
input("arco_puts", options_flow.put_contracts_total, { scope: "venue", venue: "ARCO", when: "venues", when_bit: 1, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "NYSE Arca: put contracts in the bar" });
input("amxo_calls", options_flow.call_contracts_total, { scope: "venue", venue: "AMXO", when: "venues", when_bit: 2, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "NYSE American: call contracts in the bar" });
input("amxo_puts", options_flow.put_contracts_total, { scope: "venue", venue: "AMXO", when: "venues", when_bit: 2, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "NYSE American: put contracts in the bar" });
input("xphl_calls", options_flow.call_contracts_total, { scope: "venue", venue: "XPHL", when: "venues", when_bit: 3, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Nasdaq PHLX: call contracts in the bar" });
input("xphl_puts", options_flow.put_contracts_total, { scope: "venue", venue: "XPHL", when: "venues", when_bit: 3, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Nasdaq PHLX: put contracts in the bar" });
input("xndq_calls", options_flow.call_contracts_total, { scope: "venue", venue: "XNDQ", when: "venues", when_bit: 4, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Nasdaq Options: call contracts in the bar" });
input("xndq_puts", options_flow.put_contracts_total, { scope: "venue", venue: "XNDQ", when: "venues", when_bit: 4, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Nasdaq Options: put contracts in the bar" });
input("xmio_calls", options_flow.call_contracts_total, { scope: "venue", venue: "XMIO", when: "venues", when_bit: 5, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "MIAX Options: call contracts in the bar" });
input("xmio_puts", options_flow.put_contracts_total, { scope: "venue", venue: "XMIO", when: "venues", when_bit: 5, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "MIAX Options: put contracts in the bar" });
input("edgo_calls", options_flow.call_contracts_total, { scope: "venue", venue: "EDGO", when: "venues", when_bit: 6, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Cboe EDGX: call contracts in the bar" });
input("edgo_puts", options_flow.put_contracts_total, { scope: "venue", venue: "EDGO", when: "venues", when_bit: 6, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Cboe EDGX: put contracts in the bar" });
input("xisx_calls", options_flow.call_contracts_total, { scope: "venue", venue: "XISX", when: "venues", when_bit: 7, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Nasdaq ISE: call contracts in the bar" });
input("xisx_puts", options_flow.put_contracts_total, { scope: "venue", venue: "XISX", when: "venues", when_bit: 7, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "Nasdaq ISE: put contracts in the bar" });
input("xbox_calls", options_flow.call_contracts_total, { scope: "venue", venue: "XBOX", when: "venues", when_bit: 8, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "BOX: call contracts in the bar" });
input("xbox_puts", options_flow.put_contracts_total, { scope: "venue", venue: "XBOX", when: "venues", when_bit: 8, missing: "nan", needed_by: { size_unit: [2, 3] }, description: "BOX: put contracts in the bar" });
market.zone(); // the market's clock: the shares are a US stock chart's (zone 1)
// The readings, data-only, one value per bar over the window ending at that bar: the card reads them and the Console
// can too.
output("market_total", none, overlay, { format: "si", description: "The whole market's contracts over the window's counted bars: calls, puts or both, as Calls or puts picks." });
output("venues_total", none, overlay, { format: "si", description: "The picked exchanges' contracts over the same bars" });
output("coverage", none, overlay, { format: "%", decimals: 1, description: "The picked exchanges' contracts as a percent of the whole market's. Below 100, the rest shows as Other." });
output("top_share", none, overlay, { format: "%", decimals: 1, description: "The leading exchange's share of the whole market's contracts, in percent." });
output("other_share", none, overlay, { format: "%", decimals: 1, description: "The share of the whole market's contracts that no picked exchange accounts for, in percent." });
output("counted_bars", none, overlay, { description: "Bars in the window with data from both the whole market and at least one exchange." });
output("skipped_bars", none, overlay, { description: "Bars in the window left out because only the whole market or only the exchanges had data." });
string("lead_text", { max_bytes: 48 }); // the card's headline: the leader and its share, or why there is none
string("second_text", { max_bytes: 32 }); // the next two
string("third_text", { max_bytes: 32 });
string("title", { max_bytes: 48 }); // the card's title: the side and the window

// The donut and the table, written on the live bar only; the frames carry the rows and the per-run words.
const share_rows = frame("share_rows", { max_bytes: 2048 });
const venue_rows = frame("venue_rows", { max_bytes: 4096 });
panel.pie({ name: "share", title: "Market share", x: "category", place: "below", frame: share_rows, hole: 0.6, labels: false, legend_style: "none", hole_total: true, hole_caption: "contracts today", slice_gap: 1, format: "si", chrome: "none", height_frac: 0.25 }); // the exchanges ride the table, in the same colours
panel.table({
  name: "venues",
  title: "By exchange",
  x: "category",
  place: "below",
  frame: venue_rows,
  height_frac: 0.25,
  font_size: 10,
  cell_padding: 3,
  valign: "middle",
  header_text_color: "theme.muted",
  grid_color: "theme.grid",
  grid_width: 1,
  grid_lines: "rows",
  border_width: 0,
  series: [
    { name: "Exchange" },
    { name: "Code" },
    { name: "Calls", align: "right", format: "si" },
    { name: "Puts", align: "right", format: "si" },
    { name: "Contracts", align: "right", format: "si" },
    { name: "Share", align: "right", format: "%", decimals: 1 },
  ],
});

// The card: the leader and its share, the next two, the picked exchanges' coverage of the market and the bars left
// out.
render.hud("share_card", {
  position: "top_right",
  safe_area: true,
  title: "{{title}}",
  columns: 1,
  tiles: [
    tile.pill("Leader", "lead_text", { headline: true }),
    tile.rows([
      ["Second", "second_text"],
      ["Third", "third_text"],
      ["Picked exchanges", "coverage", "%"],
      ["Bars left out", "skipped_bars", "int"],
    ]),
  ],
});

const VENUES = 9; // the options of Venues, in its order
const ENTITIES = 10; // the market, then each exchange
const STORE = 3; // per entity: call contracts, put contracts, bars with a row
const MAX_SESSIONS = 30; // the sessions setting's largest value
const NAMES: StaticArray<string> = ["Cboe Options", "NYSE Arca", "NYSE American", "Nasdaq PHLX", "Nasdaq Options", "MIAX Options", "Cboe EDGX", "Nasdaq ISE", "BOX"];
const IDS: StaticArray<string> = ["XCBO", "ARCO", "AMXO", "XPHL", "XNDQ", "XMIO", "EDGO", "XISX", "XBOX"];
const INKS: StaticArray<string> = ["#1d4ed8", "#d97706", "#fbbf24", "#0f766e", "#14b8a6", "#6d28d9", "#60a5fa", "#2dd4bf", "#e11d48"];
const OTHER_INK = "#64748b";
const SIDES: StaticArray<string> = ["contracts", "call contracts", "put contracts"];
const HOLE_SIDES: StaticArray<string> = ["contracts", "calls", "puts"]; // the hole's caption holds 24 characters: "calls, 30 sessions"
const ring = new StaticArray<f64>(MAX_SESSIONS * ENTITIES * STORE); // the finished sessions' sums, newest at head - 1
const ringBars = new StaticArray<i32>(MAX_SESSIONS); // each finished session's counted bars
const ringSkipped = new StaticArray<i32>(MAX_SESSIONS); // and its bars left out
const today = new StaticArray<f64>(ENTITIES * STORE); // today's sums
const past = new StaticArray<f64>(ENTITIES * STORE); // the window's finished sessions, summed at each new trade date
const win = new StaticArray<f64>(ENTITIES * STORE); // the window: past plus today
const got = new StaticArray<f64>(2); // this bar's call and put contracts of one entity
const barRows = new StaticArray<f64>(ENTITIES * STORE); // this bar's rows, entity by entity
const shown = new StaticArray<f64>(VENUES); // the window's measure per picked exchange
const order = new StaticArray<i32>(VENUES); // the picked exchanges sorted by the measure, largest first
const itemKey = new StaticArray<i32>(VENUES); // each item's exchange index

let types = 0; // settings, read in onStart()
let sessions = 1;
let venues = 0.0;
let day: f64 = NaN; // today's trade date
let head = 0; // the ring's next slot, and how many slots hold a session
let stored = 0;
let todayBars = 0; // today's counted bars and bars left out
let todaySkipped = 0;
let pastBars = 0; // the same over the window's finished sessions
let pastSkipped = 0;
let runBars = 0; // counted bars over the whole run
let items = 0; // how many exchanges the donut and the table list: the picked ones
let zone = 0; // the market's clock, read in onStart()

function onStart(): void {
  zone = i32(p_market_zone());
  types = i32(p_types());
  sessions = i32(p_sessions());
  if (sessions < 1) sessions = 1;
  if (sessions > MAX_SESSIONS) sessions = MAX_SESSIONS;
  venues = p_venues();
}

// This bar's call and put contracts of entity e into got: the market (0), then exchange e - 1.
function readEntity(e: i32): void {
  if (e == 0) { got[0] = in_mkt_calls(); got[1] = in_mkt_puts(); }
  else if (e == 1) { got[0] = in_xcbo_calls(); got[1] = in_xcbo_puts(); }
  else if (e == 2) { got[0] = in_arco_calls(); got[1] = in_arco_puts(); }
  else if (e == 3) { got[0] = in_amxo_calls(); got[1] = in_amxo_puts(); }
  else if (e == 4) { got[0] = in_xphl_calls(); got[1] = in_xphl_puts(); }
  else if (e == 5) { got[0] = in_xndq_calls(); got[1] = in_xndq_puts(); }
  else if (e == 6) { got[0] = in_xmio_calls(); got[1] = in_xmio_puts(); }
  else if (e == 7) { got[0] = in_edgo_calls(); got[1] = in_edgo_puts(); }
  else if (e == 8) { got[0] = in_xisx_calls(); got[1] = in_xisx_puts(); }
  else { got[0] = in_xbox_calls(); got[1] = in_xbox_puts(); }
}

// Whether exchange v is read: picked in Venues (a host that fetches its lane anyway is not read).
function picked(v: i32): bool {
  return multiHas(venues, v);
}

// Entity e's contracts in sums, as the setting picks: both sides, the calls or the puts.
function measureIn(sums: StaticArray<f64>, e: i32): f64 {
  const at = e * STORE;
  return types == 1 ? sums[at] : types == 2 ? sums[at + 1] : sums[at] + sums[at + 1];
}

// A new trade date: today's sums join the ring as its newest session, and the window's finished sessions (the newest
// sessions - 1 of them) are summed again.
function closeSession(): void {
  const base = head * ENTITIES * STORE;
  for (let i = 0; i < ENTITIES * STORE; i += 1) {
    ring[base + i] = today[i];
    today[i] = 0.0;
  }
  ringBars[head] = todayBars;
  ringSkipped[head] = todaySkipped;
  todayBars = 0;
  todaySkipped = 0;
  head = (head + 1) % MAX_SESSIONS;
  if (stored < MAX_SESSIONS) stored += 1;
  for (let i = 0; i < ENTITIES * STORE; i += 1) past[i] = 0.0;
  pastBars = 0;
  pastSkipped = 0;
  const take = sessions - 1 < stored ? sessions - 1 : stored;
  for (let k = 1; k <= take; k += 1) {
    const slot = (head - k + MAX_SESSIONS) % MAX_SESSIONS;
    const at = slot * ENTITIES * STORE;
    for (let i = 0; i < ENTITIES * STORE; i += 1) past[i] += ring[at + i];
    pastBars += ringBars[slot];
    pastSkipped += ringSkipped[slot];
  }
}

// The picked exchanges and their measure over the window.
function fillShown(): void {
  items = 0;
  for (let v = 0; v < VENUES; v += 1) {
    if (!picked(v)) continue;
    itemKey[items] = v;
    shown[items] = measureIn(win, v + 1);
    items += 1;
  }
}

// The items sorted by the measure, largest first (insertion sort, ties in Venues' order).
function sortItems(): void {
  for (let k = 0; k < items; k += 1) order[k] = k;
  for (let i = 1; i < items; i += 1) {
    const key = order[i];
    let j = i - 1;
    while (j >= 0 && shown[order[j]] < shown[key]) {
      order[j + 1] = order[j];
      j -= 1;
    }
    order[j + 1] = key;
  }
}

// The picked exchanges' window calls (0) or puts (1): the part of the market they account for.
function pickedSide(side: i32): f64 {
  let sum = 0.0;
  for (let v = 0; v < VENUES; v += 1) if (picked(v)) sum += win[(v + 1) * STORE + side];
  return sum;
}

// The window in words: " today" or ", 5 sessions", into the frame or the line.
function fbWindow(): void {
  if (sessions == 1) fb_text(" today");
  else {
    fb_text(", ");
    fb_int(sessions);
    fb_text(" sessions");
  }
}

function sbWindow(): void {
  if (sessions == 1) sb_text(" today");
  else {
    sb_text(", ");
    sb_int(sessions);
    sb_text(" sessions");
  }
}

// The donut and the table, on the live bar. The donut: one slice per exchange with a share, largest first, then Other;
// the table: each exchange with its id, calls, puts, the measure and its share, then Other and every venue together.
// An exchange that read no row in the window says so instead of a zero.
function writeFrames(total: f64, venuesTotal: f64, reading: bool): void {
  fb_clear();
  fb_text('{"hole_caption":"');
  fb_text(HOLE_SIDES[types]);
  fbWindow();
  fb_text('","rows":[');
  let slices = 0;
  for (let j = 0; j < items; j += 1) {
    const k = order[j];
    if (!(shown[k] > 0.0)) continue;
    if (slices > 0) fb_text(",");
    fb_text("[");
    fb_str(NAMES[itemKey[k]]);
    fb_text(",");
    fb_f64(shown[k], 0);
    fb_text(",");
    fb_str(INKS[itemKey[k]]);
    fb_text("]");
    slices += 1;
  }
  if (reading && total - venuesTotal > 0.0) {
    if (slices > 0) fb_text(",");
    fb_text('["Other",');
    fb_f64(total - venuesTotal, 0);
    fb_text(",");
    fb_str(OTHER_INK);
    fb_text("]");
  }
  fb_text("]}");
  writeFrameBuffer(FRAME_SHARE_ROWS);

  fb_clear();
  fb_text('{"title":"By exchange');
  fbWindow();
  fb_text('","rows":[');
  for (let j = 0; j < items; j += 1) {
    const k = order[j];
    const at = (itemKey[k] + 1) * STORE;
    if (j > 0) fb_text(",");
    fb_text('[{"text":');
    fb_str(NAMES[itemKey[k]]);
    fb_text(',"text_color":');
    fb_str(INKS[itemKey[k]]);
    fb_text(',"font_weight":"bold"},');
    fb_str(IDS[itemKey[k]]);
    if (win[at + 2] == 0.0) {
      fb_text(',{"text":"no data","text_color":"theme.muted"},"","",""]');
      continue;
    }
    fb_text(",");
    fb_f64(win[at], 0);
    fb_text(",");
    fb_f64(win[at + 1], 0);
    fb_text(",");
    fb_f64(shown[k], 0);
    fb_text(",");
    if (reading) fb_f64((shown[k] / total) * 100.0, 1);
    else fb_text('""');
    fb_text("]");
  }
  if (reading) {
    if (items > 0) fb_text(",");
    fb_text('[{"text":"Other","text_color":"theme.muted"},"",');
    fb_f64(Math.max(win[0] - pickedSide(0), 0.0), 0);
    fb_text(",");
    fb_f64(Math.max(win[1] - pickedSide(1), 0.0), 0);
    fb_text(",");
    fb_f64(Math.max(total - venuesTotal, 0.0), 0);
    fb_text(",");
    fb_f64((Math.max(total - venuesTotal, 0.0) / total) * 100.0, 1);
    fb_text('],[{"text":"All exchanges","font_weight":"bold"},"",');
    fb_f64(win[0], 0);
    fb_text(",");
    fb_f64(win[1], 0);
    fb_text(",");
    fb_f64(total, 0);
    fb_text(",100.0]");
  }
  fb_text("]}");
  writeFrameBuffer(FRAME_VENUE_ROWS);
}

// The card's words, on the live bar: the leader, the next two and the title.
function writeWords(total: f64, reading: bool, counted: i32): void {
  sb_clear();
  if (items == 0) sb_text("Pick an exchange");
  else if (runBars == 0) sb_text("No exchange data on this chart yet");
  else if (counted == 0) sb_text("No exchange data in this window");
  else if (!reading) sb_text("Nothing traded in this window");
  else {
    sb_text(NAMES[itemKey[order[0]]]);
    sb_text(" leads: ");
    sb_f64((shown[order[0]] / total) * 100.0, 1);
    sb_text("%");
  }
  str_lead_text_sb();
  for (let place = 1; place <= 2; place += 1) {
    sb_clear();
    if (reading && items > place) {
      sb_text(NAMES[itemKey[order[place]]]);
      sb_text(" ");
      sb_f64((shown[order[place]] / total) * 100.0, 1);
      sb_text("%");
    } else sb_text("n/a");
    if (place == 1) str_second_text_sb();
    else str_third_text_sb();
  }
  sb_clear();
  sb_text("Market share, ");
  sb_text(SIDES[types]);
  sbWindow();
  str_title_sb();
}

// Off a US stock chart: no frame (the donut and the table stay off) and the card's reason, on the live bar.
function writeOff(): void {
  str_lead_text(zone == 2 ? "CME options trade on one exchange" : "Works on US stock charts only");
  str_second_text("n/a");
  str_third_text("n/a");
  str_title("Market share");
}

// onBar() runs once per bar: a new trade date closes today into the ring; this bar's rows join today when the market
// and at least one picked exchange both served one (otherwise the bar is left out and counted); then the window's
// readings and, on the live bar, the donut, the table and the card. Off a US stock chart every reading stays NaN.
function onBar(): void {
  if (zone != 1) { // a CME chain trades on one venue, and the crypto venues are not read here: no share to cut
    if (bar.isLast()) writeOff();
    return;
  }
  const date = in_trade_date();
  if (!isNaN(date) && date != day) {
    if (!isNaN(day)) closeSession();
    day = date;
  }
  let marketServed = false;
  let venueServed = false;
  for (let e = 0; e < ENTITIES; e += 1) {
    const at = e * STORE;
    barRows[at + 2] = 0.0;
    if (e > 0 && !picked(e - 1)) continue;
    readEntity(e);
    if (isNaN(got[0]) || isNaN(got[1])) continue;
    barRows[at] = got[0];
    barRows[at + 1] = got[1];
    barRows[at + 2] = 1.0;
    if (e == 0) marketServed = true;
    else venueServed = true;
  }
  if (marketServed && venueServed) {
    for (let e = 0; e < ENTITIES; e += 1) {
      const at = e * STORE;
      if (barRows[at + 2] != 1.0) continue;
      today[at] += barRows[at];
      today[at + 1] += barRows[at + 1];
      today[at + 2] += 1.0;
    }
    todayBars += 1;
    runBars += 1;
  } else if (marketServed || venueServed) todaySkipped += 1;
  for (let i = 0; i < ENTITIES * STORE; i += 1) win[i] = past[i] + today[i];
  const counted = pastBars + todayBars;
  const total = measureIn(win, 0);
  const reading = counted > 0 && total > 0.0;
  fillShown();
  let venuesTotal = 0.0;
  let top = 0.0;
  for (let k = 0; k < items; k += 1) {
    venuesTotal += shown[k];
    if (shown[k] > top) top = shown[k];
  }
  out_market_total(counted > 0 ? total : NaN);
  out_venues_total(counted > 0 ? venuesTotal : NaN);
  out_coverage(reading ? (venuesTotal / total) * 100.0 : NaN);
  out_top_share(reading && items > 0 ? (top / total) * 100.0 : NaN);
  out_other_share(reading ? (Math.max(total - venuesTotal, 0.0) / total) * 100.0 : NaN);
  out_counted_bars(f64(counted));
  out_skipped_bars(f64(pastSkipped + todaySkipped));
  if (!bar.isLast()) return;
  sortItems();
  writeFrames(total, venuesTotal, reading);
  writeWords(total, reading, counted);
}

How it works

The whole and its parts. The market scope's row carries every exchange's prints together; each venue row carries one exchange's (call_contracts_total and put_contracts_total, two of the five fields the venue rows serve). A share is an exchange's contracts over the market's, so the shares of the picked exchanges and Other add up to the whole.

Nine exchanges. Each read is one data slot of the chart's budget on a copy you run from the editor or publish yourself: one slot per distinct options_flow read, whether or not Exchanges picks it (OpenMarket's own package charges one). The market and nine exchanges are ten reads, a Plus chart's whole budget, so the package reads the nine that trade the most contracts by name: Cboe Options, NYSE Arca and American, Nasdaq PHLX and the Nasdaq Options Market, MIAX Options, Cboe EDGX, Nasdaq ISE and BOX, the five largest picked by default and the other four in Exchanges. The rest of the market (Cboe BZX, Nasdaq MRX, MIAX Sapphire and Emerald, MEMX, Nasdaq GEMX and BX, Cboe C2, MIAX Pearl and any newer venue) reads as Other, never as a share of the nine.

Like by like. A bar counts only when the market and at least one picked exchange both served a row; a bar with one and not the other is left out and counted (skipped_bars). Venue rows are kept 7 days at one minute and daily for good, with no five-minute tier, while the market's rows reach 30 days at five minutes: on an intraday chart the bars between 7 and 30 days back carry the market's row alone, and counting them would shrink every share. An exchange that served no row on a counted bar adds 0 there.

A US stock chart's shares. The shares are the US listed market's, so the package reads them on the New York zone only (market.zone() 1). Every options_flow input carries needed_by: { size_unit: [2, 3] } (the shares and contracts markets: a US stock and its option contracts' charts), so a crypto chart asks for nothing. On a CME chart, whose chain trades on one venue, and on a crypto chart, where the crypto venues are not read here, every reading stays NaN, no frame is written (the donut and the table stay off) and the card says why: "One venue: no share" on CME, "Reads US exchanges only" on crypto.

The window and Exchanges. Sessions is the newest trade dates the shares cover, today included; each finished session's sums are kept in a ring of 30, so the window is summed again only when a new trade date starts. venues is a multi setting, one option per exchange: every exchange's two inputs carry when: "venues" and that option's when_bit, so the chart fetches an exchange's rows only while it is picked, and the code reads the same bits (multiHas), so an exchange that is not picked is neither read nor listed, even on a host that fetched its lane anyway; its part of the market lands in Other.

What the settings do

  • Calls or puts: Counts calls and puts together, calls only or puts only.
  • Sessions: Sets how many of the newest sessions the shares cover, today included.
  • Exchanges: Picks which exchanges to show, each its own download, and trading elsewhere shows as Other.
  • Leader: The exchange with the biggest share, with its percent.
  • Second: The exchange in second place, with its share.
  • Third: The exchange in third place, with its share.
  • Picked exchanges: How much of the whole market the picked exchanges cover, in percent.
  • Bars left out: Bars in the window where only the market or only the exchanges had data.

Where it runs

It works on US stock and ETF charts, and on the charts of their option contracts. Every indicator in your browser can read it there. US options data runs 15 minutes behind unless you have real-time US options data. The chart asks for each exchange by its exchange code. If it cannot ask for an exchange, the legend names that exchange. The shares cover the whole US options market, whatever symbol the chart shows. A CME futures chart has one exchange, and crypto exchanges are not covered. On those charts nothing draws and the card says why. On a daily chart the window reaches back to the first day of stored data. On an intraday chart it reaches back 7 days. Alerts and Protected indicators (published ones that run on OpenMarket's servers) cannot read it. They say which data they lack.

When data is missing

The card says why instead of going blank. On a CME chart it reads "CME options trade on one exchange". On a crypto chart it reads "Works on US stock charts only". It reads "Pick an exchange" while Exchanges has nothing picked. It reads "No exchange data on this chart yet" until a bar has both market and exchange data. It reads "No exchange data in this window" while the window has none. Bars left out counts the window's bars where only one side had data. In the table, an exchange with no data in the window says "no data" instead of a zero. If the chart cannot load a data source, the legend shows a chip with the reason.

Customize it

  • A week of shares. Set Sessions to 5: the donut and the table cover the newest five trade dates.
  • Where the calls trade. Set Calls or puts to calls: each exchange's share of the call contracts.
  • Another exchange. Change one exchange's venue id ("MXOP" for MEMX, "C2OX" for Cboe C2) with its name and colour in the lists: the reads stay at ten, and the exchange it replaces moves to Other. Each exchange you add is one more data slot on a copy run from the editor.

Run it

  1. In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Market Share under Beyond the time axis.
  2. Press Run on a US stock chart: the donut and the table draw under the chart and the card at the top right, at your own tier, and the legend names the tier.
  3. At the editor's Console prompt, type top_share, coverage and other_share to read the window on the live bar, or skipped_bars to see how many bars were left out.

Concepts used