Option prints
Option Prints lists the large option trades on this symbol, newest first, and marks each one on the price chart.
A print is one option trade, and its premium is the money paid for it. A big print at the ask (the seller's price) means someone paid up for that bet. That is bullish on a call (a bet on a rise), bearish on a put (a bet on a fall). Use it on a US stock, coin or CME (Chicago futures exchange) future to see where large money bets now.
Under the hood: a celled option_prints.cells input holds the window's 2,000 newest prints and each bar's 16 largest together (Data sources). It is read through its present mask (The present mask and partial bars). Five scalar options_flow inputs of scope prints carry the data plane's per-bar sums of every print at the smallest premium (Data sources). A ring keeps the newest kept prints for a frame that feeds a panel.table (Table). Its rows name their contracts in markets with fb_contract (Rows that open a market). A contract reads SPY 450C 21 Nov, or SPY 450C 15 Jan '27 in another year. Three plot.marks sections draw the contracts, a crypto chain's coins and the soft dots (Marks). A render.bgcolor wash covers the bars the chart served in part (Plotting). The options kit's optionsTradeDay gives the days to expiry (Options kit). Its flowSideCode and flowScore give each mark's score (Flow score). fbExpiryLabel names each contract's expiry (Panel frames). market.option_contract() marks an option contract's own chart (Quick reference). This is also the option-prints template: the Option Prints card under Order flow in the editor's starter list, and it compiles as written.
The wrun indicator
// Option Prints: the large option trades on this symbol, newest first, in a table under the chart. A print is one
// option trade, and each one also shows as a mark on the price where it traded. A line reads the time, the contract,
// the side of the quote, the size and the premium (the money paid). A big print at the ask (the seller's price) means
// someone paid up for that bet. That is bullish on a call (a bet on a rise), bearish on a put (a bet on a fall).
// Use it to see where large money bets right now.
//
// Under the hood: the option prints of the chart's underlying, filtered, newest first, in a table under
// the chart, each one also a mark on price at the underlying's price when it printed. The filters are settings: the
// smallest premium, calls or puts, the side of the quote, the days to expiry and out of the money only. A row reads the
// time (on the market's clock), the contract, its days to expiry, the side (AA above the ask, A at the ask, M the mid, B
// at the bid, BB below the bid, a dash with no quote; a crypto or CME print carries the taker's side, A bought and B
// sold), the size (contracts, coins on crypto), the price, the premium, the underlying's price, the IV, the delta and the
// lean: bullish for a call bought or a put sold, bearish for a call sold or a put bought, neutral at the mid. A crypto
// chain's marks ride a section of their own, its sizes being coins. A US listed row (OPRA) names its contract, so the
// chart can open it. The chart serves three days of prints at the smallest premium (10,000 and up), the days to expiry
// and the types you set: the window's 2,000 newest prints for the table and each bar's 16 largest for the marks, and the
// data plane sums every such print per bar for the readings of a bar cut to its largest. A bar past the history the data
// plane keeps is served in part: a faint wash covers it and partial reads 1.
// It reads the chart's own underlying: on an option contract's own chart (market.option_contract()) the table fills,
// its caption says so and the marks stay off, since the price axis is the contract's own. A contract names its expiry
// as 21 Nov, or 15 Jan '27 in another year. Each mark carries the print's score, the options kit's flowScore from -100
// bearish to 100 bullish (the side of the quote through flowSideCode, call or put, the moneyness against the price the
// mark sits at, the days to expiry; these marks read no open interest and count no repeat hits): its hover prints the
// score's size, its colour takes the full tone from 60 either way, a soft dot from 20 to 60 and the muted ink below 20,
// and Marks by score draws only the bullish prints (40 and up) or only the bearish ones (-40 and below).
section("Filters");
param.number("min_premium", 25000, { min: 10000, max: 1000000000, step: 5000, label: "Smallest premium, USD", description: "Hides trades with less premium (the money paid) than this. The chart loads trades from $10,000 up." });
param.choice("types", ["both", "calls", "puts"], "both", { label: "Calls or puts" });
param.choice("sides", ["every side", "at or above the ask", "at or below the bid", "outside the quote"], "every side", { label: "Side of the quote", description: "At the ask (the seller's price) keeps buyers paying up, at the bid (the buyer's price) sellers giving in. Outside the quote keeps trades past both prices, and none on crypto or CME, which carry no quote." });
param.int("max_dte", 0, { min: 0, max: 1000, label: "Days to expiry, at most", description: "Keeps options that expire within this many days. 0 keeps every expiry." });
param.bool("otm_only", false, { label: "Out of the money only", description: "Keeps calls (bets on a rise) whose strike (the option's price level) sits above the price. Keeps puts (bets on a fall) whose strike sits below it. A strike within 0.5% counts too. A trade that did not record that price stays out." });
section("Display");
param.int("rows", 30, { min: 5, max: 100, label: "Trades listed", description: "How many of the newest trades the table shows." });
param.number("mark_unit", 50000, { min: 1000, max: 1000000000, step: 1000, label: "Mark unit, USD", description: "A trade with this premium (the money paid) or less draws the smallest mark. Bigger trades draw bigger marks." });
param.choice("score_filter", ["all", "bullish", "bearish"], "all", { label: "Marks by score", description: "Each trade scores how strongly it leans, from -100 (bearish) to 100 (bullish). bullish marks scores of 40 and up, bearish -40 and below. The table and the readings keep every trade." });
input("close", ohlcv.close); // the chart's own close: where a print without its underlying is marked, and the check that the chart is the underlying's
input("prints", option_prints.cells, { max_cells: 16, newest: 2000, min_premium: "@min_premium", max_dte: "@max_dte", types: "@types", history: "3d", overflow: "largest", description: "This symbol's option trades at your premium, expiry and type filters. It loads the 2,000 newest and each bar's 16 largest over three days, live on a real-time chart." }); // [offset_ms, print_key, root_code, expiry_ms, side_cp, strike, price, size, premium, aggressor, outside, underlying, iv, delta, venue, present] per print
input("call_ask", options_flow.call_prem_ask, { scope: "prints", min_premium: "@min_premium", max_dte: "@max_dte", missing: "nan" }); // the data plane's per-bar sums of every print at the smallest premium and days to expiry, calls and puts by side: the readings of a bar cut to its largest
input("call_bid", options_flow.call_prem_bid, { scope: "prints", min_premium: "@min_premium", max_dte: "@max_dte", missing: "nan" });
input("put_ask", options_flow.put_prem_ask, { scope: "prints", min_premium: "@min_premium", max_dte: "@max_dte", missing: "nan" });
input("put_bid", options_flow.put_prem_bid, { scope: "prints", min_premium: "@min_premium", max_dte: "@max_dte", missing: "nan" });
input("printed", options_flow.prints, { scope: "prints", min_premium: "@min_premium", max_dte: "@max_dte", missing: "nan" }); // the count of those prints, calls and puts together
market.zone(); // the market's clock: a print's time, its days to expiry, and whether a row names a US listed contract
market.option_contract(); // 1 on an option contract's own chart: its price axis is the contract's premium, so no marks
// The readings, data-only: NaN on a bar the chart served no block for.
output("kept", none, overlay, { description: "Trades in this bar that pass your filters. Blank on a bar cut to its largest trades under a type, side or out of the money filter." });
output("bull_premium", none, overlay, { format: "usd", description: "Premium (the money paid) of the bullish trades kept, in USD. Bullish means calls (bets on a rise) bought and puts (bets on a fall) sold. Blank on a bar cut to its largest trades under outside the quote or out of the money only." });
output("bear_premium", none, overlay, { format: "usd", description: "Premium (the money paid) of the bearish trades kept, in USD. Bearish means calls (bets on a rise) sold and puts (bets on a fall) bought. Blank wherever bull_premium is blank." });
output("partial", none, overlay, { description: "1 on a bar older than the trade history OpenMarket keeps. Its trades can be incomplete." });
plot.marks({ name: "print_marks", slots: 16, size: { law: "sqrt", unit: "@mark_unit" }, opacity_pct: 35, x: 1, text: { mode: 0 }, colors: ["theme.down", "theme.up", "theme.muted"], tooltip: "{{qty}} premium at {{price}}, score {{fills}}" }); // up to 16 of the bar's kept prints, largest first, scoring 60 or more either way or under 20: side 0 bearish down, 1 bullish up, 2 muted; fills the score's size
plot.marks({ name: "coin_marks", slots: 16, size: { law: "sqrt", unit: "@mark_unit" }, opacity_pct: 35, x: 1, text: { mode: 0 }, colors: ["theme.down", "theme.up", "theme.muted"], tooltip: "{{qty}} premium at {{price}}, score {{fills}}" }); // the same marks on a crypto chain (zone 0), whose sizes are coins
plot.marks({ name: "soft_marks", slots: 16, size: { law: "sqrt", unit: "@mark_unit" }, opacity_pct: 10, look: 1, x: 1, text: { mode: 0 }, colors: ["theme.down", "theme.up"], tooltip: "{{qty}} premium at {{price}}, score {{fills}}" }); // the prints scoring 20 to 60 either way, on every chain: a soft dot, no edge, side 0 bearish, 1 bullish
render.bgcolor("served_in_part", { where: "partial", color: "#64748b14" }); // a faint wash over a bar served in part
const print_rows = frame("print_rows", { max_bytes: 49152 }); // the table, rewritten on the live bar
panel.table({
name: "print_table",
title: "Option prints",
x: "category",
place: "below",
frame: print_rows,
height_frac: 0.3,
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: "Time" },
{ name: "Contract" },
{ name: "Days left", align: "right", format: "int" },
{ name: "Side", align: "center" },
{ name: "Size", align: "right", format: "auto" },
{ name: "Price", align: "right", format: "0.00" },
{ name: "Premium", align: "right", format: "usd" },
{ name: "Spot", align: "right", format: "0.00" },
{ name: "IV", align: "right", format: "0.0", unit: "%" },
{ name: "Delta", align: "right", format: "0.00" },
{ name: "Lean" },
],
});
const PRINT = 16; // f64s per print: OPTION_PRINTS_TUPLE
const ROW = 16; // f64s a kept row holds: the time, the contract, price, size, premium, aggressor, outside, underlying, iv, delta, present, the bar's open, its place
const NEWEST = 2000.0; // the input's newest: the window's newest prints, every one of which the chart serves
const MAX_ROWS = 100; // the rows setting's largest value
const MAX_MARKS = 16; // the marks section's slots
const NEAR_SPOT = 0.2; // a print's underlying within 20% of the close: the chart is the underlying's
const MONTHS: StaticArray<string> = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
// A symbol code's characters (0-9 are 1 to 10, A-Z 11 to 36, the dot 37), written one by one so no row allocates.
const CODE_CHARS: StaticArray<string> = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "."];
const rootDigits = new StaticArray<i32>(10);
const kept = new StaticArray<f64>(MAX_ROWS * ROW); // the newest kept prints, a ring
const largest = new StaticArray<i32>(MAX_MARKS); // the bar's largest kept prints, as offsets into the block, biggest first
let clock = new Clock("UTC"); // a print's time of day on the market's own clock, set in onStart()
let minPremium = 25000.0; // settings, read in onStart()
let types = 0;
let sides = 0;
let maxDte = 0.0;
let otmOnly = false;
let rows = 30;
let scoreFilter = 0; // 0 every mark, 1 the bullish ones, 2 the bearish ones
let zone = 0; // the market's clock, read in onStart()
let optionContract = false; // the chart is one option contract's own: the table fills, the marks stay off
let head = 0; // the ring's next slot, and how many slots hold a row
let filled = 0;
let held = 0.0; // the prints the blocks held so far, oldest first: a print's place among them
let lastMarkerMs: f64 = NaN; // the open of the newest bar served in part, past the history the data plane keeps
let lastCutMs: f64 = NaN; // the open of the newest bar cut to its largest prints
let lastCutFirst = 0.0; // the place of that bar's first print
function onStart(): void {
minPremium = p_min_premium();
types = i32(p_types());
sides = i32(p_sides());
maxDte = p_max_dte();
otmOnly = pb_otm_only();
rows = i32(p_rows());
scoreFilter = i32(p_score_filter());
zone = i32(p_market_zone());
optionContract = i32(p_market_option_contract()) == 1;
clock = new Clock(SESSION_TZ_IDS[zone]);
}
// +1 bullish, -1 bearish, 0 neutral, from the contract's side (+1 call, -1 put) and the print's side of the quote
// (aggressor +1 the ask, -1 the bid, 0 the mid, 2 no quote).
function leanOf(sideCp: f64, aggressor: f64): i32 {
if (aggressor == 1.0) return sideCp > 0.0 ? 1 : -1;
if (aggressor == -1.0) return sideCp > 0.0 ? -1 : 1;
return 0;
}
// Whether the print at offset `at` passes the filters. A tuple whose size or premium is 0 is the chart's marker for a
// bar served in part, never a print.
function passes(cells: StaticArray<f64>, at: i32, barMs: f64): bool {
const premium = cells[at + 8];
if (!(cells[at + 7] > 0.0) || !(premium >= minPremium)) return false;
const sideCp = cells[at + 4];
if ((types == 1 && sideCp < 0.0) || (types == 2 && sideCp > 0.0)) return false;
const aggressor = cells[at + 9];
const outside = hasBit(cells[at + 15], 3) ? cells[at + 10] : 0.0; // bit 3: the quote was valid
if (sides == 1 && aggressor != 1.0) return false;
if (sides == 2 && aggressor != -1.0) return false;
if (sides == 3 && outside == 0.0) return false;
if (maxDte > 0.0 && optionsTradeDay(cells[at + 3], zone) - optionsTradeDay(barMs + cells[at], zone) > maxDte) return false;
if (otmOnly) {
if (!hasBit(cells[at + 15], 2)) return false; // bit 2: the print carries its underlying
const strike = cells[at + 5];
const spot = cells[at + 11];
const outOfMoney = sideCp > 0.0 ? strike >= spot * 0.995 : strike <= spot * 1.005;
if (!outOfMoney) return false;
}
return true;
}
// 0 out of the money, 1 at the money (the strike within 0.5% of the underlying), 2 in the money; out without a price.
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;
}
// The print's score, -100 to 100 (flowScore): the side of the quote (flowSideCode, `outside` read under a valid quote
// only), call or put, the moneyness against `spot` (where its mark sits: its underlying, else the close) and its days to
// expiry. No open interest and no repeat count: the size reads as past the open interest and no hit adds.
function scoreOf(cells: StaticArray<f64>, at: i32, barMs: f64, spot: f64): f64 {
const outside = hasBit(cells[at + 15], 3) ? cells[at + 10] : 0.0;
const sideCp = cells[at + 4];
const dte = optionsTradeDay(cells[at + 3], zone) - optionsTradeDay(barMs + cells[at], zone);
return flowScore(flowSideCode(cells[at + 9], outside), sideCp, moneynessOf(sideCp, cells[at + 5], spot), dte, NaN, 0);
}
// Where the print's mark sits: its underlying when it carries one above 0, else the close.
function markPrice(cells: StaticArray<f64>, at: i32, close: f64): f64 {
return hasBit(cells[at + 15], 2) && cells[at + 11] > 0.0 ? cells[at + 11] : close;
}
// Whether Marks by score draws the print at offset `at`: every print, the bullish ones (40 and up) or the bearish ones
// (-40 and below).
function scoreDraws(cells: StaticArray<f64>, at: i32, barMs: f64, close: f64): bool {
if (scoreFilter == 0) return true;
const score = scoreOf(cells, at, barMs, markPrice(cells, at, close));
return scoreFilter == 1 ? score >= 40.0 : score <= -40.0;
}
// The print at offset `at` into the ring, its time made absolute.
function keep(cells: StaticArray<f64>, at: i32, barMs: f64): void {
const base = head * ROW;
kept[base] = barMs + cells[at];
for (let f = 0; f < 4; f += 1) kept[base + 1 + f] = cells[at + 2 + f]; // root_code, expiry_ms, side_cp, strike
for (let f = 0; f < 8; f += 1) kept[base + 5 + f] = cells[at + 6 + f]; // price, size, premium, aggressor, outside, underlying, iv, delta
kept[base + 13] = cells[at + 15];
kept[base + 14] = barMs;
kept[base + 15] = held;
head = (head + 1) % rows;
if (filled < rows) filled += 1;
}
// Slides the print at offset `at` into the list of the bar's largest, biggest first; returns the list's new length.
function offer(cells: StaticArray<f64>, at: i32, count: i32): i32 {
const premium = cells[at + 8];
if (count == MAX_MARKS && premium <= cells[largest[count - 1] + 8]) return count;
let i = count < MAX_MARKS ? count : count - 1;
for (; i > 0 && cells[largest[i - 1] + 8] < premium; i -= 1) largest[i] = largest[i - 1];
largest[i] = at;
return count < MAX_MARKS ? count + 1 : count;
}
// ── The table ──
// The characters of a symbol code into rootDigits, last first, and their count; 0 for anything no symbol encodes to.
function rootLength(code: f64): i32 {
if (!(code >= 1.0) || code > 6278211847988223.0 || code != Math.floor(code)) return 0;
let rest = u64(code);
let count = 0;
while (rest > 0) {
const value = i32(rest % 38);
if (value == 0 || count == 10) return 0;
rootDigits[count] = value;
count += 1;
rest = rest / 38;
}
return count;
}
function fbRoot(code: f64): void { // the option root as listed, or ? when the code names none
const count = rootLength(code);
if (count == 0) fb_text("?");
for (let i = count - 1; i >= 0; i -= 1) fb_text(CODE_CHARS[rootDigits[i] - 1]);
}
function fbPad(value: i32): void { // two digits, zero first
if (value < 10) fb_text("0");
fb_int(value);
}
function fbStrike(strike: f64): void { // 450, 452.5, 1.25: the strike as listed
fb_f64(strike, strike == Math.floor(strike) ? 0 : strike * 10.0 == Math.floor(strike * 10.0) ? 1 : 2);
}
function fbContract(base: i32, nowMs: f64): void { // "SPY 450C 21 Nov": the root, the strike, call or put, the expiry's date (15 Jan '27 in another year)
fb_text("\"");
fbRoot(kept[base + 1]);
fb_text(" ");
fbStrike(kept[base + 4]);
fb_text(kept[base + 3] > 0.0 ? "C " : "P ");
fbExpiryLabel(kept[base + 2], nowMs, zone);
fb_text("\"");
}
function fbTime(ms: f64, todayKey: i32): void { // 15:59:58 today, 16OCT 15:59 on an earlier day, on the market's clock
clock.update(Math.floor(ms / 1000.0));
const today = clock.dayKey() == todayKey;
fb_text("\"");
if (!today) {
fbPad(clock.dayOfMonth());
fb_text(MONTHS[clock.month() - 1]);
fb_text(" ");
}
fbPad(clock.hour());
fb_text(":");
fbPad(clock.minute());
if (today) {
fb_text(":");
fbPad(clock.second());
}
fb_text("\"");
}
function fbSide(aggressor: f64, outside: f64, lean: i32): void { // AA, A, M, B, BB or a dash, inked by the lean
fb_text("{\"text\":\"");
if (aggressor == 1.0) fb_text(outside > 0.0 ? "AA" : "A");
else if (aggressor == -1.0) fb_text(outside < 0.0 ? "BB" : "B");
else if (aggressor == 0.0) fb_text("M");
else fb_text("-");
fb_text(lean > 0 ? "\",\"text_color\":\"theme.up\"}" : lean < 0 ? "\",\"text_color\":\"theme.down\"}" : "\",\"text_color\":\"theme.muted\"}");
}
// The contract a row names so the chart can open it: a US listed contract (OPRA, on the New York zone's charts) with a
// root of 1 to 6 characters, an expiry, a call or a put and a strike below 100,000; any other row names no market.
function fbMarket(base: i32): void {
const count = rootLength(kept[base + 1]);
const strike = kept[base + 4];
if (zone != 1 || count < 1 || count > 6 || !(kept[base + 2] > 0.0) || !(strike > 0.0) || strike >= 100000.0) fb_text("null");
else fb_contract(kept[base + 1], kept[base + 2], kept[base + 3] > 0.0 ? 1.0 : -1.0, strike);
}
function slotOf(k: i32): i32 { // the ring slot of the k-th newest row
return ((head - 1 - k + rows * 2) % rows) * ROW;
}
// Whether a print the table would list can be missing: a bar at or after the oldest row was served past the history the
// data plane keeps, or was cut to its largest prints while the oldest row is older than the window's 2,000 newest (each
// of those arrives, so rows among them are whole). A cut bar newer than the 2,000th newest print means a host that cut
// every bar to its largest: then any cut bar at or after the oldest row counts.
function servedInPart(): bool {
if (filled == 0) return false;
const oldest = slotOf(filled - 1);
const oldestBarMs = kept[oldest + 14];
if (lastMarkerMs >= oldestBarMs) return true;
if (!(lastCutMs >= oldestBarMs)) return false;
const newestWhole = held - lastCutFirst + 1.0 >= NEWEST; // the newest cut bar held the 2,000th newest print, or is older
const amongNewest = held - kept[oldest + 15] < NEWEST; // the oldest row is among the 2,000 newest
return !(newestWhole && amongNewest);
}
function writeTable(nowMs: f64): void {
clock.update(Math.floor(nowMs / 1000.0));
const todayKey = clock.dayKey();
fb_clear();
fb_text("{\"title\":\"Option prints, ");
fb_int(filled);
fb_text(filled == 1 ? " trade" : " trades");
fb_text("\",\"caption\":\"");
if (filled == 0) fb_text("No print passes the filters yet");
else if (optionContract) fb_text("On a contract's own chart, no marks"); // the price axis is the contract's premium
else if (servedInPart()) fb_text("Some bars here show only their largest trades");
else {
fb_text("Newest first, ");
fb_text(SESSION_TZ_LABELS[zone]); // New York, Chicago or UTC
fb_text(zone == 0 ? "" : " time");
}
fb_text("\",\"rows\":[");
for (let k = 0; k < filled; k += 1) {
const base = slotOf(k);
const sideCp = kept[base + 3];
const aggressor = kept[base + 8];
const present = kept[base + 13];
const lean = leanOf(sideCp, aggressor);
if (k > 0) fb_text(",");
fb_text("[");
fbTime(kept[base], todayKey);
fb_text(",");
fbContract(base, nowMs);
fb_text(",");
fb_f64(optionsTradeDay(kept[base + 2], zone) - optionsTradeDay(kept[base], zone), 0);
fb_text(",");
fbSide(aggressor, hasBit(present, 3) ? kept[base + 9] : 0.0, lean);
fb_text(",");
fb_f64(kept[base + 6], kept[base + 6] == Math.floor(kept[base + 6]) ? 0 : 4); // whole contracts bare, a coin size to four decimals
fb_text(",");
fb_num(kept[base + 5]);
fb_text(",");
fb_f64(kept[base + 7], 0);
fb_text(",");
if (hasBit(present, 2)) fb_num(kept[base + 10]); // bit 2: the underlying
else fb_text("\"\"");
fb_text(",");
if (hasBit(present, 0)) fb_num(kept[base + 11]); // bit 0: the IV, percent
else fb_text("\"\"");
fb_text(",");
if (hasBit(present, 1)) fb_num(kept[base + 12]); // bit 1: the delta
else fb_text("\"\"");
fb_text(lean > 0 ? ",{\"text\":\"Bullish\",\"text_color\":\"theme.up\"}]" : lean < 0 ? ",{\"text\":\"Bearish\",\"text_color\":\"theme.down\"}]" : ",{\"text\":\"Neutral\",\"text_color\":\"theme.muted\"}]");
}
fb_text("],\"markets\":[");
for (let k = 0; k < filled; k += 1) {
if (k > 0) fb_text(",");
fbMarket(slotOf(k));
}
fb_text("]}");
writeFrameBuffer(print_rows);
}
// A sum the data plane left unset (no print of that kind in the bar) reads 0.
function orZero(value: f64): f64 {
return isNaN(value) ? 0.0 : value;
}
function readings(count: f64, bull: f64, bear: f64, partial: f64): void {
out_kept(count);
out_bull_premium(bull);
out_bear_premium(bear);
out_partial(partial);
}
// The readings of a bar cut to its largest prints, from the data plane's sums of every print of the bar at the smallest
// premium and days to expiry: by lean on the sides kept (bullish a call at the ask or a put at the bid, bearish the other
// way round), the count with both types and every side kept alone (the sums count both types), and NaN where the sums
// cannot tell (outside the quote, out of the money only) or were not served (the chart's chip says why).
function cutReadings(): void {
const callAsk = in_call_ask();
const callBid = in_call_bid();
const putAsk = in_put_ask();
const putBid = in_put_bid();
const printed = in_printed();
if (sides == 3 || otmOnly || (isNaN(callAsk) && isNaN(callBid) && isNaN(putAsk) && isNaN(putBid) && isNaN(printed))) {
readings(NaN, NaN, NaN, 0.0);
return;
}
const ask = sides != 2; // every side, or at or above the ask
const bid = sides != 1; // every side, or at or below the bid
const bull = (types != 2 && ask ? orZero(callAsk) : 0.0) + (types != 1 && bid ? orZero(putBid) : 0.0);
const bear = (types != 2 && bid ? orZero(callBid) : 0.0) + (types != 1 && ask ? orZero(putAsk) : 0.0);
readings(types == 0 && sides == 0 ? orZero(printed) : NaN, bull, bear, 0.0);
}
// onBar() runs once per bar: the bar's prints through the filters, each kept one into the ring, the bar's largest into
// the marks; the readings on every bar (a bar cut to its largest reads the data plane's sums), the table on the live bar.
function onBar(): void {
const close = bar.close();
const barMs = bar.time() * 1000.0;
const n = in_prints_cells();
const cells = in_prints_view();
if (n < 0) readings(NaN, NaN, NaN, NaN); // no block on this bar: before the history the chart serves
else if (n == PRINT && !(cells[7] > 0.0) && isPartial(cells[15])) { // the marker alone: past the history the data plane keeps
lastMarkerMs = barMs;
readings(0.0, 0.0, 0.0, 1.0);
} else {
const first = held + 1.0; // the place of the bar's first print
let count = 0;
let marks = 0;
let bull = 0.0;
let bear = 0.0;
let cut = false; // bit 14: the bar arrived cut to its 16 largest and its prints among the window's newest
for (let i = 0; i + PRINT - 1 < n; i += PRINT) {
if (isPartial(cells[i + 15])) cut = true;
if (cells[i + 7] > 0.0) held += 1.0;
if (!passes(cells, i, barMs)) continue;
count += 1;
const lean = leanOf(cells[i + 4], cells[i + 9]);
if (lean > 0) bull += cells[i + 8];
else if (lean < 0) bear += cells[i + 8];
keep(cells, i, barMs);
if (scoreDraws(cells, i, barMs, close)) marks = offer(cells, i, marks); // Marks by score keeps it among the marks
}
if (cut) {
lastCutMs = barMs;
lastCutFirst = first;
cutReadings();
} else readings(f64(count), bull, bear, 0.0);
for (let k = 0; k < marks && !optionContract; k += 1) { // no marks on an option contract's own chart
const at = largest[k];
const price = markPrice(cells, at, close);
if (!(close > 0.0) || !(price > 0.0) || Math.abs(price / close - 1.0) > NEAR_SPOT) continue; // not the underlying's chart
const score = scoreOf(cells, at, barMs, price);
const strength = Math.abs(score);
const offset = cells[at];
const fills = i32(Math.floor(strength + 0.5)); // the hover's score, 0 to 100
const tone = strength < 20.0 ? 2 : score > 0.0 ? 1 : 0; // muted under 20, else the up or down colour
const offsetMs = !(offset > 0.0) ? 0 : offset >= 1073741824.0 ? 1073741824 : i32(offset);
if (strength >= 20.0 && strength < 60.0) out_soft_marks_mark(k, price, cells[at + 8], tone, fills, offsetMs); // 20 to 60: the soft tone
else if (zone == 0) out_coin_marks_mark(k, price, cells[at + 8], tone, fills, offsetMs); // a coin size: the coin section
else out_print_marks_mark(k, price, cells[at + 8], tone, fills, offsetMs);
}
}
if (bar.isLast()) writeTable(barMs);
}How it works
The chart serves the prints. The input asks for the prints at Smallest premium and up (min_premium: "@min_premium", the chart serving from 10,000), within Days to expiry, at most (max_dte: "@max_dte", 0 every expiry) and of the types Calls or puts keeps (types: "@types"), three days of history (history: "3d") and, on a real-time chart, the live prints as they print. Of those it reads two cuts in one read: the window's 2,000 newest prints (newest: 2000), which the table lists, and each bar's 16 largest by premium (overflow: "largest", max_cells: 16), which the marks draw. Each bar holds its 16 largest and every print of the 2,000 newest that falls in it, each once, in time order, so the input's buffer holds 2,016 prints. A bar cut that way carries bit 14 on its first print: a bar older than the 2,000 newest that held more than its 16 largest, and the bar holding the 2,000th newest print when it held more than 16, since its older prints past its largest are left out. A bar newer than that holds every print and never carries it. Each print is sixteen numbers: its time inside the bar, its key, the contract (root_code, expiry_ms, side_cp, strike), the price, the size, the premium, the side of the quote (aggressor, outside), the underlying, the IV, the delta, the venue and the present mask.
The sums. Five options_flow inputs of scope prints read the data plane's own sums of every print of the bar at the same smallest premium and days to expiry (min_premium: "@min_premium", max_dte: "@max_dte"), whichever prints the cuts kept: the premium of the calls at the ask and at the bid, of the puts at the ask and at the bid, and the count of those prints, calls and puts together (printed). They read NaN on a bar with no such print (missing: "nan"), which the package reads as 0. A bar cut to its largest prints takes its readings from them.
The filters are settings. Smallest premium (25,000 by default, 10,000 at least) drops the smaller prints. Calls or puts (both by default) keeps one type, and the chart serves that type alone. Side of the quote keeps the prints at or above the ask, at or below the bid, or outside the quote (above the ask or below the bid, read only where the quote was valid, bit 3). On a crypto or CME chart the first two keep the taker's buys and sells, and outside the quote keeps none, since those prints carry no quote. Days to expiry, at most keeps the expiries within that many days of the print's trade date on the market's clock (0 keeps every expiry). Out of the money only keeps calls struck at or above 99.5% of the print's underlying and puts struck at or below 100.5% of it (a strike within 0.5% counts as out), and leaves out a print that carries no underlying (bit 2 clear).
The side and the lean. The data plane judges each print against the national best bid and offer just before it, by the midpoint: above the mid it is at the ask (A), below it at the bid (B), exactly on it at the mid (M), and with no valid quote it has no side (a dash). AA is an ask-side print that printed above the ask, BB a bid-side print below the bid. The lean reads the side against the contract: a call at the ask or a put at the bid leans bullish, a call at the bid or a put at the ask bearish, the mid and no side neutral. On a crypto or CME chain the venue names the taker instead: a print the taker bought reads A, one it sold B, and bit 3 says only that the side is known, so no row there reads AA, BB, M or a dash. The side cell and the lean cell take the chart's up colour, its down colour or the muted ink.
The table. The newest kept prints sit in a ring as large as Trades listed (30, up to 100), filled bar by bar through the history and the live bar, and the table is rewritten on the live bar, newest first. The time is on the market's clock (market.zone(): New York on a US stock, Chicago on a CME future, UTC on crypto): hours, minutes and seconds on the newest bar's trade date, then the day, the month, hours and minutes before it (16OCT 15:59), and the days to expiry count on the same clock. Size prints whole contracts bare and a fractional size, a coin's, to four decimals. Price, Spot, IV and Delta print through their columns' formats; Spot, IV and Delta stay empty for a print that does not carry them (bits 2, 0 and 1). The title counts the trades (Option prints, 30 trades) and the caption names the clock ("Newest first, New York time", "Newest first, Chicago time" or "Newest first, UTC"). Every print among the window's 2,000 newest arrives, so the table is whole while its rows lie among them; the caption says "Some bars here show only their largest trades" when a listed row can be missing a print: a bar at or after the oldest row lies past the history the data plane keeps, or the filters reach a row older than the 2,000 newest on a bar cut to its largest.
Rows that name their contract. The frame's markets list holds one entry per row, in the rows' order: the row's contract written with fb_contract(root_code, expiry_ms, side_cp, strike) straight from the print. A row whose root does not decode to 1 to 6 characters, or whose strike is not above 0 and below 100,000, names no market (null), and its contract cell reads ? where the root would be. A row names a market on a US stock chart only (market.zone() 1, New York): a row's market is a US listed (OSI) contract and one bad entry fails the whole frame, so on any other market every row names no market.
The marks. Up to 16 of each bar's kept prints, largest premium first, are marks on price at the print's own time inside the bar (x: 1), at the underlying's price when the print carries it and at the bar's close when it does not, the area growing with the premium from the Mark unit (50,000), which draws the smallest mark. On a crypto chain (market.zone() 0) the size is coins: the marks ride a second section, coin_marks, the same look.
The score on the marks. Each mark's colour follows the print's flow score, the options kit's flowScore (Flow score) from -100 to 100: flowSideCode of its side of the quote (outside read only under a valid quote, bit 3), call or put, the moneyness against the price the mark sits at (at the money within 0.5%) and its days to expiry on the market's clock. These marks read no open interest and count no repeat hits, so the size factor reads as past the open interest and no hit adds; the flow tape's Score column reads both. A bought call or a sold put scores above 0, a sold call or a bought put below. From 60 either way the mark takes the full tone, the up colour or the down colour, in its chain's section; from 20 to 60 it is a soft dot of the same colour with no edge, in a third section, soft_marks, on every chain; under 20 (the mid, no quote) it takes the muted ink. The hover reads the premium, the price and the score's size (score 80; the colour says which way), carried in fills. Marks by score (all by default) keeps the bullish prints, scoring 40 and up, or the bearish ones, -40 and below, among the marks before they rank, so the 16 slots fill with that side's largest; the table and the readings keep every print. On an option contract's own chart, which market.option_contract() marks (i32(p_market_option_contract()) reads 1 there), no print draws a mark; on any chart a print whose underlying sits more than 20% from the bar's close draws none, since the chart is not the underlying's, the rule that keeps the marks off a contract's chart where the host writes 0.
The readings. Four data-only outputs on every bar: kept (the prints the filters kept), bull_premium and bear_premium (their premium by lean, USD) and partial (1 on a bar the chart served in part, past the history the data plane keeps). A whole bar reads them from its prints. A bar cut to its largest reads them from the sums: bull_premium the calls at the ask and the puts at the bid, bear_premium the calls at the bid and the puts at the ask, of the types and the sides kept, and kept the count of those prints with both types and every side kept. The sums do not split by outside the quote or out of the money, and count both types together, so on a cut bar bull_premium and bear_premium read NaN with Side of the quote at outside the quote or Out of the money only on, and kept reads NaN with one type, one side or out of the money only kept. Each reads NaN on a bar the chart served no block for.
What the settings do
- Smallest premium, USD: Hides trades with less premium (the money paid) than this, from $10,000 up.
- Calls or puts: Keeps calls (bets on a rise), puts (bets on a fall) or both.
- Side of the quote: Keeps trades at the ask (buyers paying up), the bid (sellers giving in), or outside both.
- Days to expiry, at most: Keeps options that expire within this many days, and 0 keeps every expiry.
- Out of the money only: Keeps calls with a strike (the option's price level) above the price, puts below it.
- Trades listed: How many of the newest trades the table shows, from 5 to 100.
- Mark unit, USD: The premium that draws the smallest mark, so bigger trades draw bigger marks.
- Marks by score: Marks all trades, or only strong leans: scores of 40 to 100 (bullish) or -40 to -100 (bearish).
Where it runs
On crypto, it reads each coin's own listed options, with prices in USD per coin and sizes in coins. A copy you run from the editor (where you write and run indicators) reads them too (Data sources). An exchange can list a coin's options in two sets, such as Deribit's BTC and BTC_USDC. The table and the marks read one set, the one named like the coin. A busy bar cut to its largest trades reads its totals from every set. On a US stock or ETF with listed options, every indicator in your browser can read them. 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). A CME trade's price is in points. Its premium (the money paid) counts each point at the contract's value, $50 on ES (the S&P 500 future). Alerts and Protected indicators (published ones that run on OpenMarket's servers) cannot read these trades. On an option contract's own chart, it reads the symbol behind that contract. There the table still lists trades, and its caption reads "On a contract's own chart, no marks". The marks stay off, since that chart's price axis is the option's own price. CME prints are 10 minutes behind unless you have real-time CME data, and crypto has no delay. The legend shows which delay applies.
When data is missing
- No data yet. A bar older than the three days the chart loads has no data, and it draws nothing. In the Console (the editor's prompt that shows a reading by its name), its four readings stay blank. They are the kept count (
kept), the bullish and bearish premium (bull_premium,bear_premium) and the incomplete-bar flag (partial). - A quiet bar. A bar where no trade meets your premium (the money paid) and expiry filters keeps 0 trades. It shows no premium and draws no mark.
- A bar cut to its largest trades. A busy bar sends its 16 largest trades and every trade among the 2,000 newest. Its marks are its largest trades anyway. Its readings come from totals of every trade in the bar. They stay blank where those totals cannot answer your filters. Two settings can leave such a bar with fewer marks than passing trades. They are Side of the quote and Out of the money only. OpenMarket picks the 16 largest before those two settings apply, so some of them drop out. If fewer than Trades listed of the 2,000 newest trades pass, the table goes on with older bars' largest trades. Its caption then says so.
- A bar older than the stored history. OpenMarket keeps a limited trade history. An older bar arrives as one empty marker, which never counts as a trade. A faint shade covers the bar. In the Console,
partialreads 1, and the premiums andkeptread 0. The caption reads "Some bars here show only their largest trades" while such a bar sits among the listed trades. - Trades without their totals. In the Console, a cut bar that arrives without its totals reads blank
kept,bull_premiumandbear_premium. Its trades and marks still draw. A chip on the legend names the data the chart could not load. - Nothing passes the filters. The table lists no trade, and its caption reads "No print passes the filters yet".
Customize it
- Only the big ones. Raise Smallest premium to 250,000 and Mark unit with it: the table and the marks keep the trades that move the most money.
- Short-dated flow. Set Days to expiry, at most to 7 and turn Out of the money only on: the table reads the near-term bets.
- Urgency. Set Side of the quote to outside the quote on a US stock chart: the prints that paid above the ask or sold below the bid, the ones that chose speed over price.
- One side of the flow. Set Marks by score to bullish: the chart marks only the bought calls and the sold puts that score 40 and up, while the table still lists every print.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Option Prints under Order flow.
- Press Run on a chart whose underlying lists options, a US stock such as SPY, ES1! or a BTC chart: the copy stands the table under the chart and sits the marks on the candles at the prints' times. On ES1! the copy reads the prints once you accept the CME market data terms, at your own tier, and the legend names the tier.
- At the editor's Console prompt, type
keptandbull_premiumto read the newest bar's counts.
Concepts used
- Data sources for the
option_printscelled class, its tuple and its knobs, and The present mask and partial bars forhasBit,isPartialand bit 14 - Table and Rows that open a market for
panel.tableover a frame, styled cells andmarkets - Marks for
plot.marks, its size law andx: 1 - Plotting for
render.bgcolorgated by a data-only output - Options kit for
optionsTradeDay - Panel frames for
fbExpiryLabel, and the Quick reference formarket.option_contract()