Strike footprint
Coloured boxes behind the candles show where options traded, at each strike (option price level) and in each bar.
The up colour means the premium (money paid for options) there leaned bullish, the down colour bearish. Read a strike from left to right to see when traders kept coming back to it. The Lens setting switches to calls alone, puts alone, or contracts traded. Use it to spot levels traders defend or target, on coins, CME (Chicago futures exchange) futures or US stocks.
Under the hood: it reads option_strike_flow.cells grouped by expiry and strike (Data sources) through its present mask (The present mask and partial bars). It paints an out.grid of 41 levels through a diverging plot.heatmap whose hover format follows the Lens setting's style_values (Options on a setting). It places each bar's boxes through two data-only values (Heatmaps, A grid the module computes). It washes incomplete bars with render.bgcolor (Plotting) and finds the same-day expiry with optionsTradeDay (the options functions). This is also the strike-footprint template: the Strike Footprint card under Order flow in the editor's starter list, and it compiles as written.
The wrun indicator
// Strike Footprint: where options traded, strike by strike and bar by bar, painted behind the candles. A strike is an
// option's price level, and each box sits at that price on the chart. Each column is one bar. A box in the up colour
// means bullish money outweighed bearish money at that strike. Calls (bets on a rise) bought at the ask (buyers paying
// the seller's price) are bullish. Puts (bets on a fall) sold at the bid (sellers taking the buyer's price) are bullish
// too. A box in the down colour means the reverse: more puts bought and calls sold. Brighter boxes mean more premium
// (money paid for options). The Lens setting can show calls alone, puts alone, or the number of contracts traded. Hover
// a box to read its value. Read a strike from left to right to see when traders kept coming back to it. A strike that
// keeps lighting up is a level traders defend or target. Use it to see which nearby strikes are busy right now.
//
// Under the hood: each column is one bar and each cell one strike, at its own price on the chart: the up colour where
// the flow leaned bullish (calls bought at the ask and puts sold at the bid outweighed calls sold and puts bought), the
// down colour where it leaned bearish, brighter with the premium. The default lens is that bullish net premium; the
// others are the calls' net premium alone, the puts' alone, and the contracts traded; the cell hover prints the lens in
// its own unit, dollars or a count of contracts. The strikes shown sit around each bar's close, one row per listed
// strike step (the most common gap between neighbouring strikes, or the step you set), every expiry summed, the
// same-day expiry alone (on crypto, the one within 24 hours), or the later ones. The data plane sums each bar's flow
// per expiry, strike and side, only the strikes within 15% of the underlying (a row further out draws empty), so each
// row keeps its expiry for the same-day rule and a session of five-minute bars fits the chart's read. A bar the chart
// served in part draws what it holds and a faint wash marks it, since its cells are a floor. It reads the chart's own
// underlying and draws at strike prices: on an option contract's chart no strike lands near the price axis and nothing
// draws. Every print takes a side, cross trades and late prints too: the cell hover and the Lens setting say so.
param.choice("lens", ["bullish net premium", "call net premium", "put net premium", "contracts"], "bullish net premium", { label: "Lens", description: "What each box measures: bullish net premium (money paid for options), calls or puts alone, or contracts traded. The premium choices include cross and late trades.", style_values: ["usd", "usd", "usd", "auto"] }); // style_values: the cell hover's number format per lens (the heatmap's format: "@lens"), dollars or a plain count
param.int("strikes", 17, { min: 5, max: 41, label: "Strikes shown", description: "How many strikes (option price levels) to show around the price, centred on the nearest one" });
param.number("strike_step", 0, { min: 0, max: 100000, step: 0.5, label: "Strike step", description: "The price gap between two neighbouring strikes (option price levels) on the chart. 0 uses the most common gap between listed strikes." });
param.choice("expiries", ["every expiry", "0DTE only", "after today"], "every expiry", { label: "Expiries", description: "Which expiry dates count. 0DTE only keeps options that expire on the bar's trading day, or within 24 hours on crypto. After today leaves those out." });
input("close", ohlcv.close); // the chart's own close: the strike each bar's rows centre on
input("flow", option_strike_flow.cells, { max_cells: 10000, group: "expiry_strike", strike_window_pct: 15, description: "Each bar's flow per expiry, strike and side of the underlying, strikes within 15% of the underlying" }); // [expiry_ms, strike, side_cp, dte_class, vol_ask, vol_bid, vol_mid, vol_none, vol_above_ask, vol_below_bid, prem_ask, prem_bid, prem_mid, prem_none, present] per expiry, strike and side
market.zone(); // the market's clock: the trade date the same-day expiry is judged on (on crypto, the next 24 hours)
output("grid_low", none, overlay, { description: "The price at the bottom edge of the boxes on this bar, half a step under the lowest strike" }); // data-only: the heatmap reads it
output("row_step", none, overlay, { description: "The strike step: how much price each box covers on this bar" });
output("flow_total", none, overlay, { format: "si", description: "The Lens value added up over the strikes shown on this bar, in dollars or contracts. Includes cross and late trades" });
output("partial", none, overlay, { description: "1 on a bar whose options data arrived only in part. Its boxes then show a minimum." });
out.grid("flow", { rows: 41 }); // one data-only output per row, flow_0 the lowest strike; out_flow(row, value)
plot.heatmap({ name: "strike_flow", grid: "flow", price_low: "grid_low", price_step: "row_step", center: 0, palette: ["theme.down", "theme.bg", "theme.up"], auto_quantile: 0.97, opacity: 0.8, behind_candles: true, format: "@lens", label: "Strike flow", tooltip: "{{value}} at the {{price}} strike. Includes cross and late trades" }); // {{value}} prints in the lens's format: $7.0K on a premium lens, 30 on contracts
render.bgcolor("served_in_part", { where: "partial", color: "#64748b14" }); // a faint wash over a bar served in part
const FLOW = 15; // f64s per row: OPTION_STRIKE_FLOW_TUPLE
const ROWS = 41; // the grid's declared rows
const NEAR = 0.1; // strikes within 10% of the close teach the step
const MAX_NEAR = 256; // distinct strikes a bar keeps for the step
const MAX_GAPS = 16; // distinct gaps the step's tally keeps
const cellSum = new StaticArray<f64>(ROWS); // this bar's cells
const cellSeen = new StaticArray<bool>(ROWS);
const nearStrikes = new StaticArray<f64>(MAX_NEAR); // this bar's distinct strikes near the close, ascending
const gapValue = new StaticArray<f64>(MAX_GAPS); // the gaps seen between neighbouring strikes, and how often
const gapCount = new StaticArray<f64>(MAX_GAPS);
let lens = 0; // settings, read in onStart()
let shown = 17;
let fixedStep = 0.0;
let expiries = 0;
let zone = 0; // the market's clock, read in onStart()
let gaps = 0; // distinct gaps in the tally
function onStart(): void {
lens = i32(p_lens());
shown = i32(p_strikes());
if (shown % 2 == 0) shown -= 1; // an odd count keeps the close's strike in the middle row
fixedStep = p_strike_step();
expiries = i32(p_expiries());
zone = i32(p_market_zone());
}
// Whether the contract expiring at expiryMs counts under the expiries setting, for the bar opening at barMs on the
// trade date `today`: the same day's expiry, on crypto (zone 0, dailies at 08:00 UTC) the one within 24 hours.
function counts(expiryMs: f64, today: f64, barMs: f64): bool {
if (expiries == 0) return true;
const sameDay = zone == 0 ? expiryMs > barMs && expiryMs - barMs <= 86400000.0 : optionsTradeDay(expiryMs, zone) == today;
return expiries == 1 ? sameDay : !sameDay;
}
// One row's value under the lens: its net premium (at the ask minus at the bid) signed by the side it leans (a call
// +1, a put -1), one side's net premium alone, or its contracts; NaN when the lens leaves it out.
function valueOf(cells: StaticArray<f64>, at: i32): f64 {
const sideCp = cells[at + 2];
const net = cells[at + 10] - cells[at + 11];
if (lens == 0) return sideCp > 0.0 ? net : -net;
if (lens == 1) return sideCp > 0.0 ? net : NaN;
if (lens == 2) return sideCp < 0.0 ? net : NaN;
return cells[at + 4] + cells[at + 5] + cells[at + 6] + cells[at + 7];
}
// The bar's distinct strikes within 10% of the close teach the tally of gaps between neighbours (to the cent).
function learnStep(cells: StaticArray<f64>, n: i32, close: f64): void {
let count = 0;
for (let i = 0; i + FLOW - 1 < n; i += FLOW) {
const strike = cells[i + 1];
if (!(strike > 0.0) || Math.abs(strike / close - 1.0) > NEAR) continue;
let j = 0;
while (j < count && nearStrikes[j] < strike) j += 1;
if (j < count && nearStrikes[j] == strike) continue; // listed already
if (count == MAX_NEAR) continue;
for (let k = count; k > j; k -= 1) nearStrikes[k] = nearStrikes[k - 1];
nearStrikes[j] = strike;
count += 1;
}
for (let k = 1; k < count; k += 1) {
const gap = Math.round((nearStrikes[k] - nearStrikes[k - 1]) * 100.0) / 100.0;
if (!(gap > 0.0)) continue;
let g = 0;
while (g < gaps && gapValue[g] != gap) g += 1;
if (g == gaps) {
if (gaps == MAX_GAPS) continue;
gapValue[g] = gap;
gapCount[g] = 0.0;
gaps += 1;
}
gapCount[g] += 1.0;
}
}
// The strike step: the setting, else the gap seen most often (the smaller on a tie); NaN before any gap.
function stepOf(): f64 {
if (fixedStep > 0.0) return fixedStep;
let best = -1;
for (let g = 0; g < gaps; g += 1) {
if (best < 0 || gapCount[g] > gapCount[best] || (gapCount[g] == gapCount[best] && gapValue[g] < gapValue[best])) best = g;
}
return best < 0 ? NaN : gapValue[best];
}
function clearRows(): void { // no column on this bar: every cell empty
for (let r = 0; r < ROWS; r += 1) out_flow(r, NaN);
}
// onBar() runs once per bar: the bar's strikes teach the step; the strike nearest the close takes the middle row and
// each row joins its strike's row; then the grid, its bottom edge and its step.
function onBar(): void {
const close = bar.close();
const n = in_flow_cells();
let partial = false;
if (n > 0) {
const block = in_flow_view();
for (let i = 0; i + FLOW - 1 < n; i += FLOW) if (isPartial(block[i + 14])) partial = true;
if (close > 0.0) learnStep(block, n, close);
}
out_partial(n < 0 ? NaN : partial ? 1.0 : 0.0);
const step = stepOf();
if (n <= 0 || !(close > 0.0) || isNaN(step)) {
out_grid_low(NaN);
out_row_step(NaN);
out_flow_total(n < 0 ? NaN : 0.0);
clearRows();
return;
}
const cells = in_flow_view();
const barMs = bar.time() * 1000.0;
const today = optionsTradeDay(barMs, zone);
const half = (shown - 1) / 2;
const middle = Math.round(close / step) * step; // the strike nearest the close
for (let r = 0; r < ROWS; r += 1) {
cellSum[r] = 0.0;
cellSeen[r] = false;
}
for (let i = 0; i + FLOW - 1 < n; i += FLOW) {
const strike = cells[i + 1];
if (!(strike > 0.0) || !counts(cells[i], today, barMs)) continue; // no strike: the all-zero row of a bar served in part
const value = valueOf(cells, i);
if (isNaN(value)) continue;
const r = i32(Math.round((strike - middle) / step)) + half;
if (r < 0 || r >= shown) continue; // outside the strikes shown
cellSum[r] += value;
cellSeen[r] = true;
}
let total = 0.0;
for (let r = 0; r < ROWS; r += 1) {
const value = r < shown && cellSeen[r] ? cellSum[r] : NaN;
if (!isNaN(value)) total += value;
out_flow(r, value);
}
out_grid_low(middle - (f64(half) + 0.5) * step);
out_row_step(step);
out_flow_total(total);
}How it works
Each strike's flow. The data plane sums each bar's prints per expiry, strike and option type (group: "expiry_strike"), the strikes within 15% of the underlying (strike_window_pct: 15, max_cells: 10000), and the input hands the bar one tuple per row: its contracts by side of the quote and its premium at the ask and at the bid. On a US stock 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, below it at the bid. A crypto venue and CME name the taker's side instead: bought at the ask, sold at the bid.
The read is what the grid draws. The grid draws at most 41 rows around the close, so the input asks for the strikes within 15% of the underlying, where it asked for 25%: the widest grid at a chain's listed step near the money sits inside that (41 rows at SPY's one-dollar step reach about 3% each side of the price, 17 rows at a coin's 1,000 step about 13%). The narrower ask holds fewer rows a bar, so the chart reads a whole regular session of five-minute bars at once instead of only its newest bars. A grid that reaches further, such as 41 rows at a step of 5 on SPY, draws its outermost rows empty; raise strike_window_pct in the source for it, and the chart reads fewer bars at a time.
The lens. Lens picks each row's value. Bullish net premium (the default) is a call's premium at the ask minus at the bid, and a put's the other way round, so calls bought and puts sold count up and calls sold and puts bought count down. Call net premium and Put net premium keep one side's premium at the ask minus at the bid. Contracts counts every contract traded, whatever its side, so it paints the up half of the scale alone. Expiries sums every expiry, keeps only the contracts expiring on the bar's own trade date on the market's clock (market.zone(): the New York date on a US stock, the CME trade date on a future; 0DTE only), or leaves those out (after today). On crypto, whose dailies expire at 08:00 UTC, 0DTE only keeps the contracts expiring within 24 hours after the bar's open: the daily that expired this morning never counts, and tomorrow's does.
The strike step. One row holds one strike. Strike step fixes the price between two rows; left at 0, the step is the gap seen most often between neighbouring strikes that traded within 10% of the close, counted to the cent over every bar so far (the smaller gap on a tie), so a chain listed every dollar near the money reads 1, and a BTC chain listed every 1,000 reads 1,000. Before any bar has taught a gap, nothing draws.
The rows around the close. The row in the middle holds the strike step's multiple nearest the bar's close, and Strikes shown (17, from 5 to 41) rows sit around it; an even count drops by one so the close's strike stays in the middle. Each tuple adds its value to its strike's row, and a strike outside the rows shown adds nothing. grid_low (half a step under the lowest row's strike) and row_step place the rows on the price axis bar by bar, so each column follows its own close.
The heatmap. plot.heatmap paints the grid behind the candles: the down colour below zero, the chart's background at zero, the up colour above, the scale's ends at the 97th percentile of the run, at 80% opacity. The hover reads the cell's value and its strike, in the lens's unit: format: "@lens" paints the heatmap's number format from the Lens setting, whose style_values give each choice its word (usd on the three premium lenses, auto on contracts), so the hover's {{value}} reads $7.0K on a premium lens and 30 on contracts. A row with no contract stays empty.
The readings. Data-only outputs on every bar: flow_total (the lens summed over the strikes shown, in dollars, or contracts on the contracts lens), grid_low, row_step and partial (1 on a bar the chart served in part), with the grid's own outputs flow_0 (the lowest strike) to flow_40.
Cross and late trades. The data plane sides every print by the quote, cross trades and late or out-of-sequence prints included, because the feed carries no sale conditions, so a source that leaves those prints unsided shows a different net premium. The package says so where its net premium shows: the cell hover, the hint of Lens and the description of flow_total.
What the settings do
- Lens: Picks what each box measures: bullish net premium, calls or puts alone, or contracts traded.
- Strikes shown: How many strikes (option price levels) appear around the price.
- Strike step: The price gap between two strikes, where 0 uses the most common listed gap.
- Expiries: Every expiry, only 0DTE (options that expire today), or only those after today.
Where it runs
It runs on coins with listed options and reads the coin's own options. A copy you run from the editor (where you write and run your own indicators) reads them too. On a US stock or ETF chart with US listed options, every indicator in your browser can read this data. On a futures chart from CME, the Chicago exchange, every indicator in your browser can read it too, once you accept the CME market data terms (Limitations). Alerts and Protected indicators (published ones that run on OpenMarket's servers) cannot read this data. They stop with an error that names it. It draws at strike prices, so use it on the stock's or coin's own chart. On an option contract's chart, the price axis shows the contract's own price, so nothing draws. A bar with more than 10,000 entries stops the run rather than cutting data. An entry is one expiry, strike and option type. US options data is 15 minutes behind unless you have real-time US options data. CME data is 10 minutes behind unless your account has real-time CME access. The chart's legend says which you see.
When data is missing
- No data. A bar older than the chart's options history has no data. Then the Console (the editor's panel that prints values) shows
flow_totalandpartialempty, and no column draws. - No trades. A bar where no option traded draws no column, and the Console's
flow_totalreading shows 0. - Part of a bar. Sometimes only part of a bar's options data arrives. On a busy symbol, an older bar may come as one empty marker instead of its trades. This indicator never counts that marker as a trade. Such a bar draws the boxes it has, a faint wash covers it, and the Console's
partialreading shows 1. Its boxes then show a minimum.
Customize it
- The same-day expiry. Set Expiries to 0DTE only on an index ETF: the strikes the day's expiring flow is fighting over.
- One side. Set Lens to call net premium to see where calls were bought and where they were sold, strike by strike.
- A wider ladder. Raise Strikes shown to 41 on a quiet chart, or set Strike step to 5 on a chain listed every five dollars; a grid that reaches past 15% of the underlying draws its outer rows empty until you raise
strike_window_pctin the source.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Strike Footprint under Order flow.
- Press Run on a Deribit BTC chart at 5 minutes or on a US stock chart such as SPY: the cells paint behind the candles; on a US stock the legend names the tier the read was served at.
- At the editor's Console prompt, type
flow_totalandrow_stepto read the newest bar's total and the strike step it drew with.
Concepts used
- Data sources for the
option_strike_flowcelled class, its tuple and its knobs, and The present mask and partial bars forisPartialand bit 14 - Options on a setting for
style_values, the hover's number format per lens - Heatmaps and A grid the module computes for
out.gridandplot.heatmapwithprice_lowandprice_step - Plotting for
render.bgcolorgated by a data-only output - Options kit for
optionsTradeDay