Interval flow

View as MarkdownOpen the editor

Interval Flow lists the option contracts that traded on this symbol in one bar, biggest first, under the chart.

Big orders often take many prints (single option trades) over minutes, so each line sums one contract over the bar. A high share at the ask (the seller's price) means buyers paid up for that contract. A histogram counts contracts passing your filters, and a strip scores each bar from -100 (bearish) to 100 (bullish). Use it on a US stock, coin or CME (Chicago futures exchange) future with options to see where money went.

Under the hood: a celled option_contract_flow.cells input is read tuple by tuple (Data sources). hasBit reads the values a tuple may lack and decodeSymbol the contract's root (Data sources). Each premium is the VWAP times the size times the market's option multiplier: 100 on a US stock, 50 on ES, 1 on a coin. Else it is the premium at the ask plus at the bid, a muted floor. The rows go into a styled panel.table (Cards, frames and panels). A histogram output is coloured per bar by a data-only ladder output, beside an out.inset strip (Cards, frames and panels). The options kit's flowSideCode, flowScore and optionsTradeDay give the scores (Flow score). This is also the interval-flow template: the Interval Flow card under Order flow in the editor's starter list, and it compiles as written.

The wrun indicator

// Interval Flow: the option contracts that traded on this symbol in one bar, in a table under the chart. A print is
// one option trade, and big orders often take many prints over minutes. So each line sums one contract over the bar:
// a 5-minute chart reads 5-minute intervals. A line shows the size, the premium (the money paid) and a score. Its Ask
// column is the share bought at the ask (the seller's price), where buyers paid up for that bet. Use it to see which
// contracts drew the money in the last bar.
//
// Under the hood: the option contracts that traded on the chart's underlying in one bar's interval, one line per
// contract, for spotting fills that take minutes rather than one print: a 5-minute chart reads 5-minute intervals. A
// table under the chart lists the interval's top contracts by premium (or by volume) that pass the filters: the
// contract, its size (contracts, or coins to four decimals), its premium, the share bought at the ask and sold at the
// bid, the average fill, the last IV and the interval's share of the contract's volume so far this session. The
// interval is the last closed bar by default (Forming reads the bar trading now), and a histogram under the table
// counts every bar's contracts that pass. Premium is the VWAP times the size times the market's option multiplier (100
// on a US stock, 50 on ES, 1 on a coin); where the cells carry no VWAP (present bit 0 clear) or the host does not know
// the multiplier, it is the premium at the ask plus at the bid, a floor, printed muted. The interval's time reads on
// the market's own clock. The cells come from option_contract_flow, one tuple per contract that traded in each bar: an
// interval whose block was cut down (the partial bit, 14) says so in the table's caption; a tuple whose contract is not
// whole (a root the symbol codec refuses, no expiry, a side other than call or put, no strike) is skipped and counted.
// 1-minute cells reach back 7 days and 5-minute cells 30 days. Each row also reads the contract's score, the options
// kit's flowScore from -100 bearish to 100 bullish: its contracts' scores by the side of the quote they took
// (flowSideCode's codes: above the ask, at it, at the bid, below it; the mid and unsided 0), averaged by size, call or
// put, the moneyness against the bar's close (the cells carry no underlying) and the days to expiry from the bar's
// trade date (no open interest and no repeat count: the size reads as past the open interest). Each bar's flow score,
// the premium-weighted mean of the passing contracts' scores, draws as a column in a strip at the foot of the price
// pane and tones the bar's Contracts passing column: the up colour from 20, the down colour from -20, between them the
// strip's muted ink and the column's text colour.

section("Filters");
param.choice("rank", ["premium", "volume"], "premium", { label: "Rank by", description: "Orders the table by premium (the money paid) or by contracts traded." });
param.number("min_premium", 25000, { min: 0, max: 10000000, step: 1000, label: "Smallest premium, USD", description: "A contract shows when its premium (the money paid) in the interval reaches this many USD." });
param.choice("side", ["any", "ask", "bid"], "any", { label: "Side", description: "any keeps every contract. ask keeps contracts with at least 55% bought at the ask (buyers paying up). bid keeps those with at least 55% sold at the bid (sellers giving in)." });
param.int("rows", 12, { min: 3, max: 30, label: "Contracts listed", description: "How many contracts the table shows." });
param.choice("shown", ["closed", "live"], "closed", { label: "Interval", description: "Pick the last finished bar (closed) or the bar trading now (live)." });
input("close", ohlcv.close); // the chart's own candles: the bar grid, one interval each
input("trade_date", time.trade_date); // the bar's trade date: each contract's session volume starts again on each
input("flow", option_contract_flow.cells, { max_cells: 6000, description: "Each contract that traded in the bar: [root_code, expiry_ms, side_cp, strike, vol_ask, vol_bid, vol_mid, vol_none, prem_ask, prem_bid, share_delta_net, vwap, last_price, iv_last, vol_above_ask, vol_below_bid, present]" }); // every expiry and strike of the chart's underlying
market.zone(); // the market's clock: the interval's time and each expiry's date
market.option_multiplier(); // the chain's USD per price unit and size unit: 100 on a US stock, 50 on ES, 1 on a coin; 0 unknown
output("hits", histogram, lower, { color_by: "score_tone", colors: ["theme.down", "theme.up", "theme.text"], label: "Contracts passing", format: "int", description: "Contracts in this bar that pass your filters, coloured by their flow score." });
output("hit_premium", none, lower, { description: "Their premium (the money paid), in USD." });
output("partial", none, lower, { description: "1 on a bar whose contracts were cut short. Its counts are a minimum." });
output("skipped", none, lower, { description: "Entries in this bar skipped because their contract details were incomplete." });
output("score_tone", none, lower, { description: "The flow score's colour: 0 at -20 or below, 1 at 20 or above, 2 between. Blank on a bar where no contract passes." });
out.inset("flow_score", { dock: "bottom", height_px: 32, shape: "histogram", color_by: "score_tone", colors: ["theme.down", "theme.up", "theme.muted"] }); // the bar's flow score, -100 to 100: the premium-weighted mean score of the contracts that pass, a column in a strip with its own scale; NaN on a bar no contract passes
string("note", { max_bytes: 64 }); // the one line while there is no contract flow to list
render.label("note_label", { position: "top_center", text: "note", color: "theme.muted", style: "plain", offset: [0, 8] });
const contract_rows = frame("contract_rows", { max_bytes: 16384 });
panel.table({
  name: "contracts",
  title: "Interval flow",
  x: "category",
  place: "below",
  frame: contract_rows,
  height_frac: 0.3,
  font_size: 10,
  cell_padding: 3,
  grid_lines: "rows",
  header_text_color: "theme.muted",
  series: [
    { name: "Contract" },
    { name: "Volume", align: "right", format: "auto" },
    { name: "Premium", align: "right", format: "usd" },
    { name: "Ask", align: "right", format: "0", unit: "%" },
    { name: "Bid", align: "right", format: "0", unit: "%" },
    { name: "Avg price", align: "right", format: "0.00" },
    { name: "IV", align: "right", format: "0.0", unit: "%" },
    { name: "Of day", align: "right", format: "0", unit: "%" },
    { name: "Score", align: "right", format: "0.0", signed: true },
  ],
});

const TUPLE = 17; // f64s per contract: OPTION_CONTRACT_FLOW_TUPLE
const MAX_ROWS = 30; // the table's rows, the Rows setting's ceiling
const CAP = 16384; // contracts a session's volume table holds (a power of two)
const SIDE_SHARE = 55.0; // the Side filter's share, percent
// The session's volume per contract: open addressing, a slot free when it belongs to an earlier session.
const keyRoot = new StaticArray<f64>(CAP);
const keyExpiry = new StaticArray<f64>(CAP);
const keySide = new StaticArray<f64>(CAP);
const keyStrike = new StaticArray<f64>(CAP);
const slotSession = new StaticArray<i32>(CAP);
const dayVolume = new StaticArray<f64>(CAP);
// The top rows of this bar (cur) and of the bar before it (prev): one field per array, MAX_ROWS each.
const ROW_FIELDS = 12; // root, expiry, side, strike, volume, premium, floor, ask %, bid %, vwap, iv, score
const curRows = new StaticArray<f64>(MAX_ROWS * ROW_FIELDS);
const prevRows = new StaticArray<f64>(MAX_ROWS * ROW_FIELDS);
const curDay = new StaticArray<f64>(MAX_ROWS); // the interval's share of the contract's session volume, percent
const prevDay = new StaticArray<f64>(MAX_ROWS);
let timeClock = new Clock("UTC"); // the interval's open on the market's own clock, set in onStart()

let byVolume = false; // settings, read in onStart()
let minPremium = 25000.0;
let sideFilter = 0;
let rowLimit = 12;
let forming = false;
let zone = 0; // the market facts, read in onStart()
let optMult: f64 = NaN; // NaN where the host does not know the multiplier: the premium falls back to the sided floor
let day: f64 = NaN; // the trade date the volume table runs over
let sessionId = 1; // the volume table's session: a slot holding another number is free (every slot starts at 0)
let used = 0; // slots taken this session
let curCount = 0;
let prevCount = 0;
let curTime: f64 = NaN; // the bars' opens, epoch seconds
let prevTime: f64 = NaN;
let curPartial = false;
let prevPartial = false;
let curHits = 0;
let prevHits = 0;
let curHitPremium = 0.0; // the premium of every contract that passes this bar, not only the listed ones
let curScorePremium = 0.0; // their premium times their score, summed: over curHitPremium, the bar's flow score
let runCells = 0; // tuples read over the whole run

function onStart(): void {
  byVolume = p_rank() == 1.0;
  minPremium = p_min_premium();
  sideFilter = i32(p_side());
  rowLimit = i32(p_rows());
  forming = p_shown() == 1.0;
  zone = i32(p_market_zone());
  optMult = p_market_option_multiplier() > 0.0 ? p_market_option_multiplier() : NaN;
  timeClock = new Clock(SESSION_TZ_IDS[zone]);
}

// The symbol codec's rule without decoding: a whole number from 1 to 38^10 - 1 with no zero digit in base 38.
function rootOk(code: f64): bool {
  if (!(code >= 1.0) || code > 6278211847988223.0 || code != Math.floor(code)) return false;
  let rest = code;
  while (rest > 0.0) {
    const digit = rest % 38.0;
    if (digit == 0.0) return false;
    rest = (rest - digit) / 38.0;
  }
  return true;
}

// A tuple counts when its contract is whole and its present mask is a whole number from 0 up.
function contractOk(cells: StaticArray<f64>, i: i32): bool {
  const present = cells[i + 16];
  const side = cells[i + 2];
  return rootOk(cells[i]) && cells[i + 1] > 0.0 && (side == 1.0 || side == -1.0) && cells[i + 3] > 0.0 && present >= 0.0 && present == Math.floor(present);
}

function hashOf(root: f64, expiry: f64, side: f64, strike: f64): i32 {
  let h: i64 = i64(root % 1000000007.0);
  h = h * 31 + i64(expiry / 60000.0);
  h = h * 31 + i64(Math.round(strike * 100.0));
  h = h * 2 + (side > 0.0 ? 1 : 0);
  h ^= h >> 17;
  h *= 0x2545f491;
  h ^= h >> 13;
  return i32(h & i64(CAP - 1));
}

// The contract's slot in this session's volume table, claimed when new; -1 once the table is seven eighths full.
function slotOf(root: f64, expiry: f64, side: f64, strike: f64): i32 {
  const h = hashOf(root, expiry, side, strike);
  for (let probe = 0; probe < CAP; probe += 1) {
    const at = (h + probe) & (CAP - 1);
    if (slotSession[at] != sessionId) {
      if (used >= CAP - CAP / 8) return -1;
      slotSession[at] = sessionId;
      keyRoot[at] = root;
      keyExpiry[at] = expiry;
      keySide[at] = side;
      keyStrike[at] = strike;
      dayVolume[at] = 0.0;
      used += 1;
      return at;
    }
    if (keyRoot[at] == root && keyExpiry[at] == expiry && keySide[at] == side && keyStrike[at] == strike) return at;
  }
  return -1;
}

// 0 out of the money, 1 at the money (the strike within 0.5% of the close), 2 in the money; out without a close.
function moneynessOf(sideCp: f64, strike: f64, spot: f64): i32 {
  if (!(spot > 0.0)) return 0;
  if (Math.abs(strike - spot) <= spot * 0.005) return 1;
  return (sideCp > 0.0 ? strike > spot : strike < spot) ? 0 : 2;
}

// A contract's score in the interval (flowScore), its contracts' scores by the side of the quote they took averaged by
// size: above the ask (vol_above_ask, at most the ask's) and the rest at the ask, at the bid and below it (vol_below_bid,
// at most the bid's), each at flowSideCode's code for it, the mid and unsided at 0; call or put, the moneyness against
// the bar's close and the days to expiry from the bar's trade date `day`, no open interest and no repeat count.
function contractScore(cells: StaticArray<f64>, i: i32, volume: f64, close: f64, day: f64): f64 {
  const sideCp = cells[i + 2];
  const m = moneynessOf(sideCp, cells[i + 3], close);
  const dte = optionsTradeDay(cells[i + 1], zone) - day;
  const volAsk = cells[i + 4];
  const volBid = cells[i + 5];
  const above = Math.min(Math.max(cells[i + 14], 0.0), volAsk);
  const below = Math.min(Math.max(cells[i + 15], 0.0), volBid);
  const atAsk = (volAsk - above) * flowScore(flowSideCode(1.0, 0.0), sideCp, m, dte, NaN, 0);
  const overAsk = above * flowScore(flowSideCode(1.0, 1.0), sideCp, m, dte, NaN, 0);
  const atBid = (volBid - below) * flowScore(flowSideCode(-1.0, 0.0), sideCp, m, dte, NaN, 0);
  const underBid = below * flowScore(flowSideCode(-1.0, -1.0), sideCp, m, dte, NaN, 0);
  return (atAsk + overAsk + atBid + underBid) / volume;
}

// One row into this bar's top rows, kept in rank order; a row ranking below a full table is dropped.
function keepRow(cells: StaticArray<f64>, i: i32, volume: f64, premium: f64, floor: bool, askPct: f64, bidPct: f64, dayPct: f64, score: f64): void {
  const key = byVolume ? volume : premium;
  let at = curCount;
  while (at > 0) {
    const above = (at - 1) * ROW_FIELDS;
    const aboveKey = byVolume ? curRows[above + 4] : curRows[above + 5];
    if (aboveKey >= key) break;
    at -= 1;
  }
  if (at >= rowLimit) return;
  const last = curCount < rowLimit ? curCount : rowLimit - 1;
  for (let k = last; k > at; k -= 1) {
    for (let f = 0; f < ROW_FIELDS; f += 1) curRows[k * ROW_FIELDS + f] = curRows[(k - 1) * ROW_FIELDS + f];
    curDay[k] = curDay[k - 1];
  }
  const o = at * ROW_FIELDS;
  const present = cells[i + 16];
  curRows[o] = cells[i];
  curRows[o + 1] = cells[i + 1];
  curRows[o + 2] = cells[i + 2];
  curRows[o + 3] = cells[i + 3];
  curRows[o + 4] = volume;
  curRows[o + 5] = premium;
  curRows[o + 6] = floor ? 1.0 : 0.0;
  curRows[o + 7] = askPct;
  curRows[o + 8] = bidPct;
  curRows[o + 9] = hasBit(present, 0) ? cells[i + 11] : NaN; // the VWAP when the cells carry it
  curRows[o + 10] = hasBit(present, 1) ? cells[i + 13] : NaN; // the last IV, percent, when they carry it
  curRows[o + 11] = score;
  curDay[at] = dayPct;
  if (curCount < rowLimit) curCount += 1;
}

// One bar's block: every contract adds to its session volume; the ones that pass the filters count as hits, add their
// premium times their score to the bar's flow score and compete for the bar's top rows.
function fold(n: i32): i32 {
  const cells = in_flow_view();
  const close = bar.close();
  const barDay = optionsTradeDay(bar.time() * 1000.0, zone); // the bar's trade date on the market's calendar
  let skipped = 0;
  for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) {
    if (!contractOk(cells, i)) {
      skipped += 1;
      continue;
    }
    runCells += 1;
    const present = cells[i + 16];
    if (isPartial(present)) curPartial = true;
    const volAsk = cells[i + 4];
    const volBid = cells[i + 5];
    const volume = volAsk + volBid + cells[i + 6] + cells[i + 7];
    if (!(volume > 0.0)) continue;
    const slot = slotOf(cells[i], cells[i + 1], cells[i + 2], cells[i + 3]);
    let dayPct: f64 = NaN;
    if (slot >= 0) {
      dayVolume[slot] += volume;
      dayPct = (100.0 * volume) / dayVolume[slot];
    }
    const floor = !hasBit(present, 0) || isNaN(optMult); // no VWAP or no multiplier: the premium at the ask plus at the bid, a floor
    const premium = floor ? cells[i + 8] + cells[i + 9] : cells[i + 11] * volume * optMult;
    if (premium < minPremium) continue;
    const askPct = (100.0 * volAsk) / volume;
    const bidPct = (100.0 * volBid) / volume;
    if (sideFilter == 1 && askPct < SIDE_SHARE) continue;
    if (sideFilter == 2 && bidPct < SIDE_SHARE) continue;
    const score = contractScore(cells, i, volume, close, barDay);
    curHits += 1;
    curHitPremium += premium;
    curScorePremium += premium * score;
    keepRow(cells, i, volume, premium, floor, askPct, bidPct, dayPct, score);
  }
  return skipped;
}

function fbStrike(strike: f64): void { // "660", "662.5", "17.25": a whole strike prints bare
  if (strike == Math.floor(strike)) fb_int(i64(strike));
  else if (strike * 10.0 == Math.floor(strike * 10.0)) fb_f64(strike, 1);
  else fb_f64(strike, 2);
}

function fbContract(o: i32, rows: StaticArray<f64>, nowMs: f64): void { // "SPY 16 Oct 660C", the expiry 15 Jan '27 in another year
  fb_text("\"");
  fb_text(decodeSymbol(rows[o]));
  fb_text(" ");
  fbExpiryLabel(rows[o + 1], nowMs, zone);
  fb_text(" ");
  fbStrike(rows[o + 3]);
  fb_text(rows[o + 2] > 0.0 ? "C\"" : "P\"");
}

// The table on the live bar: the interval the setting picks, its top rows in rank order.
function writeTable(): void {
  const rows = forming ? curRows : prevRows;
  const dayPcts = forming ? curDay : prevDay;
  const count = forming ? curCount : prevCount;
  const t = forming ? curTime : prevTime;
  const partial = forming ? curPartial : prevPartial;
  const hits = forming ? curHits : prevHits;
  fb_clear();
  fb_text("{\"title\":\"Interval flow");
  if (!isNaN(t)) {
    timeClock.update(t);
    fb_text(", ");
    if (timeClock.hour() < 10) fb_text("0");
    fb_int(timeClock.hour());
    fb_text(":");
    if (timeClock.minute() < 10) fb_text("0");
    fb_int(timeClock.minute());
    if (forming) fb_text(", live");
  }
  fb_text("\",\"caption\":\"");
  if (partial) fb_text("Some contracts left out: the counts are a minimum");
  else if (count == 0) fb_text("No contract passes the filters in this interval");
  else {
    fb_int(hits);
    fb_text(hits == 1 ? " contract passes" : " contracts pass");
  }
  fb_text("\",\"rows\":[");
  for (let k = 0; k < count; k += 1) {
    const o = k * ROW_FIELDS;
    if (k > 0) fb_text(",");
    fb_text("[");
    fbContract(o, rows, t * 1000.0);
    fb_text(",");
    fb_f64(rows[o + 4], rows[o + 4] == Math.floor(rows[o + 4]) ? 0 : 4); // whole contracts bare, a coin size to four decimals
    fb_text(",");
    if (rows[o + 6] > 0.0) { // a floor: muted
      fb_text("{\"value\":");
      fb_f64(rows[o + 5], 0);
      fb_text(",\"text_color\":\"theme.muted\"}");
    } else fb_f64(rows[o + 5], 0);
    fb_text(",");
    fb_f64(rows[o + 7], 1);
    fb_text(",");
    fb_f64(rows[o + 8], 1);
    fb_text(",");
    fb_f64(rows[o + 9], 2);
    fb_text(",");
    fb_f64(rows[o + 10], 1);
    fb_text(",");
    fb_f64(dayPcts[k], 1);
    fb_text(",{\"value\":"); // the score: the up colour above 0, the down colour below, muted at 0, bold from 60 either way
    fb_num(rows[o + 11]);
    fb_text(rows[o + 11] > 0.0 ? ",\"text_color\":\"theme.up\"" : rows[o + 11] < 0.0 ? ",\"text_color\":\"theme.down\"" : ",\"text_color\":\"theme.muted\"");
    fb_text(Math.abs(rows[o + 11]) >= 60.0 ? ",\"font_weight\":\"bold\"}]" : "}]");
  }
  fb_text("]}");
  writeFrameBuffer(contract_rows);
}

// onBar() runs once per bar: this bar's top rows become the previous bar's, a new trade date starts the session's
// volume table again, then the bar's block is folded, the histogram drawn and, on the live bar, the table written.
function onBar(): void {
  for (let k = 0; k < curCount * ROW_FIELDS; k += 1) prevRows[k] = curRows[k];
  for (let k = 0; k < curCount; k += 1) prevDay[k] = curDay[k];
  prevCount = curCount;
  prevTime = curTime;
  prevPartial = curPartial;
  prevHits = curHits;
  curCount = 0;
  curTime = bar.time();
  curPartial = false;
  curHits = 0;
  curHitPremium = 0.0;
  curScorePremium = 0.0;
  const date = in_trade_date();
  if (!isNaN(date) && date != day) {
    day = date;
    sessionId += 1;
    used = 0;
  }
  const n = in_flow_cells();
  const skipped = n >= TUPLE ? fold(n) : 0;
  out_hits(n >= TUPLE ? f64(curHits) : NaN);
  out_hit_premium(curHits > 0 ? curHitPremium : NaN);
  out_partial(curPartial ? 1.0 : 0.0);
  out_skipped(f64(skipped));
  const flowScoreNow = curHits > 0 && curHitPremium > 0.0 ? curScorePremium / curHitPremium : NaN; // the premium-weighted mean
  out_flow_score(flowScoreNow);
  out_score_tone(isNaN(flowScoreNow) ? NaN : flowScoreNow >= 20.0 ? 1.0 : flowScoreNow <= -20.0 ? 0.0 : 2.0);
  if (!bar.isLast()) return;
  if (runCells > 0) writeTable();
  str_note(runCells > 0 ? "" : "No contract flow on this chart yet"); // an empty text draws no label
}

How it works

One line per contract. The bar's block holds one 17-value tuple per contract that traded in it. Its volume is the four sides added (vol_ask, vol_bid, vol_mid, vol_none); the ask and bid columns are those sides' shares of it. Premium is the contract's VWAP times its size times the market's option multiplier, the chart's market fact market.option_multiplier() (100 shares on a US stock, the point value on CME, 50 on ES, 1 on a coin chain whose prices are USD per coin). Volume prints whole contracts bare and a coin's size to four decimals: 2.5 BTC reads 2.5, never a whole contract. On crypto and CME the ask and bid columns are the taker's side: bought and sold. A tuple whose VWAP is not served (bit 0 of its present mask clear) has its premium at the ask plus at the bid instead, a floor, and the table prints it muted; its average fill stays blank. A chart that does not know the multiplier gets the same floor on every row, never a guessed 100. The last IV, in percent, needs bit 1.

The filters. A contract shows when its interval premium reaches Smallest premium, USD and, under Side, when at least 55% of its contracts were bought at the ask (ask) or sold at the bid (bid). The passing contracts compete for the table's Contracts listed, ranked by premium or by volume; a tie keeps the contract the block listed first.

The flow score. Each passing contract's score is the options kit's flowScore (Flow score) for its contracts by the side of the quote they took, averaged by size: the contracts above the ask (vol_above_ask, at most the ask's) at flowSideCode's +2, the rest of the ask at +1, the rest of the bid at -1, the contracts below the bid (vol_below_bid, at most the bid's) at -2, and the mid and the unsided at 0. The score reads call or put, the moneyness against the bar's close (at the money within 0.5%; the cells carry no underlying, so on an option contract's own chart, whose close is the contract's price, read the score with care) and the days to expiry from the bar's trade date on the market's clock; the cells carry no open interest and no repeat count, so the size factor reads as past the open interest. A bought call or a sold put scores above 0, a sold call or a bought put below. The Score column prints it with one decimal and its sign, in the up colour above 0, the down colour below, muted at 0, bold from 60 either way. The bar's flow score, flow_score, is the premium-weighted mean of its passing contracts' scores (the sum of each premium times its score over their premium), NaN on a bar no contract passes; it draws as a column in a strip with its own scale at the foot of the price pane (out.inset), and its tone, score_tone (1 at 20 or above, 0 at -20 or below, 2 between), colours both that column and the bar's Contracts passing column: the up colour, the down colour, and between them the strip's muted ink and the histogram's text colour.

The share of the day. Every contract's volume, filtered or not, runs into a session table keyed by the contract (root, expiry, side, strike) that a new trade date empties. Of day is the interval's volume over that running total: a contract printing 40% of its day in one interval is a fill worth a look.

Which interval. Interval reads the last closed bar (closed) or the bar trading now (live). Its time and each expiry's date read on the market's clock (market.zone(): New York on a US stock); a row names its contract with the expiry's label, the kit's fbExpiryLabel (SPY 16 Oct 660C, or SPY 15 Jan '27 660C for an expiry in another year). The package keeps each bar's top rows as it passes, so the closed interval's table is ready on the live bar.

What the settings do

  • Rank by: Orders the table by premium (the money paid) or by contracts traded.
  • Smallest premium, USD: Hides contracts with less premium (the money paid) in the interval than this.
  • Side: Keeps all contracts, or those at least 55% bought at the ask (seller's price) or sold at the bid.
  • Contracts listed: How many contracts the table shows, from 3 to 30.
  • Interval: Shows the last finished bar, or the bar trading now.

Where it runs

On crypto, it reads each coin's own listed options. A copy you run from the editor (where you write and run indicators) reads them too. On a US stock or ETF with listed options, every indicator in your browser can read them. That holds on its option contracts' charts too. They are real time if you have real-time US options data, and 15 minutes behind otherwise. On a CME futures chart, every indicator in your browser can read them too, once you accept the CME market data terms (Limitations). There they are real time if you have real-time CME data, and 10 minutes behind otherwise. It shows the last 7 days on 1-minute charts and the last 30 days on 5-minute charts.

When data is missing

The table's caption counts the contracts that pass, or reads "No contract passes the filters in this interval". It reads "Some contracts left out: the counts are a minimum" when the bar's list was cut short. A bar with no data draws no histogram column. An entry with an incomplete contract is never listed. In the Console (the editor's prompt that shows a reading by its name), skipped counts it. Incomplete means an unreadable symbol, no expiry date, no strike (the option's price level), or no option type. "No contract flow on this chart yet" means no bar on the chart carried a contract.

Customize it

  • The ask-side intervals. Set Side to ask and Smallest premium, USD to 100,000 for the aggressive buyers only.
  • Wider intervals. Read a 15-minute chart for fills spread over a quarter hour; the histogram then counts per quarter hour.
  • The one-sided intervals. Set Side to ask and watch the strip: a tall column in the up colour is an interval of bought calls and sold puts, in the down colour bought puts and sold calls.
  • Volume over open interest. Join the option_contract_state cells on the live bar to compare each contract's day volume with its open interest.

Run it

  1. In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Interval Flow under Order flow.
  2. Press Run on a five-minute chart of a coin with listed options or of a US stock: the last closed interval's contracts list under the chart.
  3. At the editor's Console prompt, type last 20 hits for the last 20 intervals' passing contracts, hit_premium for the newest interval's premium and last 20 flow_score for the intervals' flow scores.

Concepts used