Premium by strike
A heat map behind the candles shows options money at each strike (the option's price level), bar by bar.
Up-colour boxes hold premium (the money paid for an option) betting on a rise, down-colour boxes betting on a fall. A line marks the strike where each bar's money centres, and its band shows how widely the money spread. The profile (bars on the price axis) totals today's money per strike. Use it to find 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 strike with strike_window_pct: 10 and fold_types: true (Data sources). It paints an out.grid through a plot.heatmap centred on 0 (Price canvases). It docks a plot.levels profile coloured per strike (Docked profiles). It draws three lines and a shaded band for the premium centre (the flow_vwap line, Plotting) and marks incomplete bars with isPartial (Data sources). This is also the premium-by-strike template: the Premium by Strike card under Order flow in the editor's starter list, and it compiles as written.
The wrun indicator
// Premium by Strike: where options money traded, strike by strike, as a heat map behind the candles. The heat map is a
// grid of coloured boxes. Premium is the money paid for options. A strike is an option's price level. Each column is
// one bar, and each box in it is one strike. A box in the chart's up colour holds money betting on a rise. Calls (bets
// on a rise) bought at the ask (buyers paying the seller's price) count as up money. Puts (bets on a fall) sold at the
// bid (sellers taking the buyer's price) count as up money too. Puts bought at the ask and calls sold at the bid count
// as down money, in the down colour. Brighter boxes hold more money. Read one strike from left to right to see when its
// money arrived. The profile (bars on the price axis) adds up today's money at each strike. A strike with heavy money
// is a level traders defend or target. The premium centre line marks the strike where each bar's money centred. Use it
// to find the prices options traders care about today.
//
// Under the hood: a strike's net premium is its bullish premium minus its bearish premium: calls bought at the ask and
// puts sold at the bid are bullish, puts bought at the ask and calls sold at the bid bearish, so a cell in the chart's
// up colour is money leaning up at that strike in that bar and one in its down colour money leaning down. Premium at
// the mid or with no quote has no side and counts in neither. The rows are the chain's strike spacing (read off the
// strikes that traded: the most common gap near the price) unless Strike step sets one, 48 of them centred on each
// bar's close; the docked profile sums the session (each trade date starts again) over the strikes within Profile
// window of the close. The cells come from option_strike_flow, the data plane's sums of each bar's flow per strike
// within 10% of the underlying, calls and puts in one row with the bullish side on the ask: a bar served in part (the
// partial bit, 14) gets a muted dot under its candle, its column a floor; a row that is not whole (no strike) is
// skipped and counted. 1-minute cells reach back 7 days and 5-minute cells 30 days. Every print takes a side, cross
// trades and late prints too: the heat map's and the profile's hover say so. The premium centre (the flow_vwap line,
// labelled Premium centre so no one takes it for the Flow VWAP indicator) is each bar's premium-weighted centre strike
// over every strike of its flow (all premium, every side, mid and unquoted too), a line on price with a band one
// premium-weighted standard deviation of the strikes either side, lightly shaded.
//
// Version 0.4 adds the premium centre: its two settings and three lines come after 0.3's, so every earlier slot keeps
// its place.
section("Strikes");
param.number("row_step", 0, { min: 0, max: 10000, step: 0.5, label: "Strike step", description: "How much price each level of the heat map covers. 0 uses the gap between listed strikes (option price levels), 500 to 5,000 on BTC." });
param.number("profile_pct", 8, { min: 1, max: 50, label: "Profile window, percent", description: "The profile shows today's options money per strike (option price level) on the price axis. This sets how far it reaches each way, in percent." });
section("Premium centre");
param.bool("flow_vwap", true, { label: "Premium centre", description: "A line at the price where each bar's options money centres. Each strike (option price level) counts by its premium (money paid)." });
param.bool("vwap_band", true, { label: "Premium centre band", when: "flow_vwap", description: "A light band one standard deviation (1σ) either side of the premium centre. A wide band means the money spread over many strikes." });
input("close", ohlcv.close); // the chart's own candles: the bar grid and each column's centre
input("trade_date", time.trade_date); // the bar's trade date: the docked profile starts again on each
input("flow", option_strike_flow.cells, { max_cells: 4000, group: "strike", strike_window_pct: 10, fold_types: true, description: "Each bar's options trades per strike within 10% of the price, calls and puts together, with bullish money on the ask side. Fields: [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]" });
output("partial_mark", shape, overlay, { color: "theme.muted", description: "A muted dot under a candle when only part of that bar's options data arrived. Its column is then a minimum." }); // first output on price: the package homes on the chart
output("heat_low", none, overlay, { description: "The price at the bottom edge of the heat map on this bar" }); // data-only: the heatmap reads it
output("heat_step", none, overlay, { description: "How much price each level of the heat map covers on this bar" });
out.grid("heat", { rows: 48 }); // 48 data-only outputs heat_0..heat_47, one per row, written with out_heat(row, value)
plot.heatmap({ name: "net_heat", grid: "heat", price_low: "heat_low", price_step: "heat_step", center: 0, auto_quantile: 0.98, opacity: 0.7, behind_candles: true, label: "Net premium by strike", tooltip: "{{value:usd}} net premium at the {{price}} strike. Includes cross and late trades" }); // the diverging default: the chart's down colour, its background, its up colour
// The readings, data-only: the Console reads them.
output("session_net", none, overlay, { description: "Today's bullish minus bearish premium (money paid for options) over every strike, in USD. Includes cross and late trades" });
output("top_bull_strike", none, overlay, { description: "The strike (option price level) holding today's largest bullish net premium" });
output("top_bull_net", none, overlay, { description: "That strike's net premium (money paid for options) today, in USD. Includes cross and late trades" });
output("top_bear_strike", none, overlay, { description: "The strike (option price level) holding today's largest bearish net premium" });
output("top_bear_net", none, overlay, { description: "That strike's net premium (money paid for options) today, in USD, below zero. Includes cross and late trades" });
output("skipped", none, overlay, { description: "Strike entries on this bar left out because they were incomplete" });
// Version 0.4's premium centre (the flow_vwap line), after the readings, so every output before it keeps its slot.
output("flow_vwap", line, overlay, { color: "theme.text", width: 2, format: "price", label: "Premium centre", description: "The strike (option price level) where this bar's premium (money paid for options) centres. It is the premium-weighted average strike, every side counted." });
output("vwap_hi", line, overlay, { color: "theme.muted", width: 1, line_style: "dotted", format: "price", label: "Premium centre +1σ", description: "The premium centre plus one standard deviation (1σ) of the bar's strikes, weighted by premium" });
output("vwap_lo", line, overlay, { color: "theme.muted", width: 1, line_style: "dotted", format: "price", label: "Premium centre -1σ", description: "The premium centre minus one standard deviation (1σ) of the bar's strikes, weighted by premium" });
fill("vwap_hi", "vwap_lo", { color: "theme.muted", opacity: 0.08 }); // the band, lightly shaded
string("note", { max_bytes: 64 }); // the one line while there is nothing to draw
const strike_rows = frame("strike_rows", { max_bytes: 24576 });
plot.levels({ name: "session_by_strike", frame: strike_rows, dock: "right", width_frac: 0.14, baseline: "center", labels: false, thickness_px: 8, hover: true, format: "usd" });
render.label("note_label", { position: "top_center", text: "note", color: "theme.muted", style: "plain", offset: [0, 8] });
const TUPLE = 15; // f64s per row: OPTION_STRIKE_FLOW_TUPLE
const ROWS = 48; // the heat map's rows, the grid's declared count
const MAX_SEEN = 1024; // distinct strikes kept over the run, the nearest the close: the spacing reads them
const MAX_STRIKES = 512; // the session's strikes, the nearest the close
const MAX_PROFILE = 256; // rows docked on the axis
const STEPS: StaticArray<f64> = [0.5, 1.0, 2.0, 2.5, 5.0, 10.0, 20.0, 25.0, 50.0, 100.0, 200.0, 250.0, 500.0, 1000.0, 2000.0, 2500.0, 5000.0]; // the listed strike spacings, a coin's too
const stepCount = new StaticArray<i32>(STEPS.length);
const seen = new StaticArray<f64>(MAX_SEEN); // the run's distinct strikes, ascending
const strikeAt = new StaticArray<f64>(MAX_STRIKES); // the session's strikes, ascending, and their net premium
const netAt = new StaticArray<f64>(MAX_STRIKES);
const rowHeat = new StaticArray<f64>(ROWS); // this bar's column
const rowTouched = new StaticArray<bool>(ROWS);
let fixedStep = 0.0; // settings, read in onStart()
let profilePct = 0.08;
let vwapOn = true;
let bandOn = true;
let day: f64 = NaN; // the trade date the profile sums
let seenCount = 0;
let strikeCount = 0;
let runCells = 0; // rows read over the whole run
let close: f64 = NaN; // this bar
function onStart(): void {
fixedStep = p_row_step();
profilePct = p_profile_pct() / 100.0;
vwapOn = p_flow_vwap() > 0.5;
bandOn = p_vwap_band() > 0.5;
}
// A row's premium, every side: at the ask and the bid (either lean), at the mid and with no quote.
function premiumOf(cells: StaticArray<f64>, i: i32): f64 {
const premium = cells[i + 10] + cells[i + 11] + cells[i + 12] + cells[i + 13];
return premium > 0.0 ? premium : 0.0;
}
function clearVwap(): void { // no premium centre on this bar
out_flow_vwap(NaN);
out_vwap_hi(NaN);
out_vwap_lo(NaN);
}
// The premium centre of the bar's whole rows: the premium-weighted mean strike and one premium-weighted standard deviation
// of the strikes either side; none where the bar holds no premium or the setting is off.
function writeVwap(cells: StaticArray<f64>, n: i32): void {
let weight = 0.0;
let moment = 0.0;
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) {
if (!rowOk(cells, i)) continue;
const premium = premiumOf(cells, i);
weight += premium;
moment += premium * cells[i + 1];
}
if (!vwapOn || !(weight > 0.0)) {
clearVwap();
return;
}
const centre = moment / weight;
let spread = 0.0;
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) {
if (!rowOk(cells, i)) continue;
const gap = cells[i + 1] - centre;
spread += premiumOf(cells, i) * gap * gap;
}
const sigma = Math.sqrt(spread / weight);
out_flow_vwap(centre);
out_vwap_hi(bandOn ? centre + sigma : NaN);
out_vwap_lo(bandOn ? centre - sigma : NaN);
}
// A row counts when it names a strike, calls and puts in one row, and its present mask is a whole number from 0 up
// (the all-zero row of a bar served in part with no flow does not).
function rowOk(cells: StaticArray<f64>, i: i32): bool {
const present = cells[i + 14];
return cells[i + 1] > 0.0 && cells[i + 2] == 0.0 && present >= 0.0 && present == Math.floor(present);
}
// Where a strike sits in an ascending table: its index when listed, else the index it would take.
function lowerBound(keys: StaticArray<f64>, count: i32, key: f64): i32 {
let lo = 0;
let hi = count;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (keys[mid] < key) lo = mid + 1;
else hi = mid;
}
return lo;
}
// Which end of a full table leaves for a new strike: 0 the low end, 1 the high end, -1 the new strike itself (it is
// the farthest from the close).
function evict(keys: StaticArray<f64>, count: i32, strike: f64): i32 {
const dLow = Math.abs(keys[0] - close);
const dHigh = Math.abs(keys[count - 1] - close);
const dNew = Math.abs(strike - close);
if (dNew >= dLow && dNew >= dHigh) return -1;
return dLow >= dHigh ? 0 : 1;
}
// One more distinct strike into the run's table, the nearest the close kept.
function noteSeen(strike: f64): void {
let at = lowerBound(seen, seenCount, strike);
if (at < seenCount && seen[at] == strike) return;
if (seenCount >= MAX_SEEN) {
const end = evict(seen, seenCount, strike);
if (end < 0) return;
if (end == 0) {
for (let k = 1; k < seenCount; k += 1) seen[k - 1] = seen[k];
at -= 1;
}
seenCount -= 1;
if (at > seenCount) at = seenCount;
}
for (let k = seenCount; k > at; k -= 1) seen[k] = seen[k - 1];
seen[at] = strike;
seenCount += 1;
}
// A contract's net premium onto its strike for the session, the nearest strikes to the close kept.
function addNet(strike: f64, net: f64): void {
let at = lowerBound(strikeAt, strikeCount, strike);
if (at < strikeCount && strikeAt[at] == strike) {
netAt[at] += net;
return;
}
if (strikeCount >= MAX_STRIKES) {
const end = evict(strikeAt, strikeCount, strike);
if (end < 0) return;
if (end == 0) {
for (let k = 1; k < strikeCount; k += 1) {
strikeAt[k - 1] = strikeAt[k];
netAt[k - 1] = netAt[k];
}
at -= 1;
}
strikeCount -= 1;
if (at > strikeCount) at = strikeCount;
}
for (let k = strikeCount; k > at; k -= 1) {
strikeAt[k] = strikeAt[k - 1];
netAt[k] = netAt[k - 1];
}
strikeAt[at] = strike;
netAt[at] = net;
strikeCount += 1;
}
// The chain's strike spacing: the most common gap between neighbouring strikes within 10% of the close, matched to
// a listed spacing (the smaller on a tie); the smallest gap when none matches; NaN with fewer than two strikes.
function spacing(): f64 {
for (let c = 0; c < STEPS.length; c += 1) stepCount[c] = 0;
let smallest: f64 = NaN;
let prev: f64 = NaN;
for (let k = 0; k < seenCount; k += 1) {
const strike = seen[k];
if (Math.abs(strike - close) > close * 0.1) continue;
if (!isNaN(prev)) {
const gap = strike - prev;
if (gap > 0.0 && (isNaN(smallest) || gap < smallest)) smallest = gap;
for (let c = 0; c < STEPS.length; c += 1) {
if (Math.abs(gap - STEPS[c]) <= STEPS[c] * 0.01) {
stepCount[c] += 1;
break;
}
}
}
prev = strike;
}
let best = -1;
for (let c = 0; c < STEPS.length; c += 1) if (stepCount[c] > 0 && (best < 0 || stepCount[c] > stepCount[best])) best = c;
return best >= 0 ? STEPS[best] : smallest;
}
function writeProfile(): void {
const lo = close * (1.0 - profilePct);
const hi = close * (1.0 + profilePct);
let first = 0;
while (first < strikeCount && strikeAt[first] < lo) first += 1;
let last = first;
while (last < strikeCount && strikeAt[last] <= hi) last += 1;
while (last - first > MAX_PROFILE) { // a wide window on a fine ladder: drop the row farther from the close
if (close - strikeAt[first] >= strikeAt[last - 1] - close) first += 1;
else last -= 1;
}
if (last <= first) return; // no strike inside the window: the profile stays absent
fb_clear();
fb_text("{\"prices\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_num(strikeAt[k]);
}
fb_text("],\"values\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_f64(netAt[k], 0);
}
fb_text("],\"colors\":[");
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_text(netAt[k] > 0.0 ? "\"theme.up\"" : netAt[k] < 0.0 ? "\"theme.down\"" : "\"theme.muted\""); // bullish up, bearish down
}
fb_text("],\"tooltips\":["); // each row's hover hint
for (let k = first; k < last; k += 1) {
if (k > first) fb_text(",");
fb_text("\"Includes cross and late trades\"");
}
fb_text("]}");
writeFrameBuffer(strike_rows);
}
// onBar() runs once per bar: a new trade date starts the profile again; the bar's rows add each strike's net
// premium to the strike for the session and to its heat row for this bar's column, and weigh its strikes by premium
// for the premium centre; then the readings, the column and, on the live bar, the docked profile.
function onBar(): void {
close = bar.close();
const date = in_trade_date();
if (!isNaN(date) && date != day) {
day = date;
strikeCount = 0;
}
for (let r = 0; r < ROWS; r += 1) {
rowHeat[r] = 0.0;
rowTouched[r] = false;
}
const n = in_flow_cells();
let skipped = 0;
let partial = false;
if (n >= TUPLE && !isNaN(close)) {
const cells = in_flow_view();
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) { // the strikes first: the spacing reads them
if (rowOk(cells, i)) noteSeen(cells[i + 1]);
}
const step = fixedStep > 0.0 ? fixedStep : spacing();
const gridLow = isNaN(step) ? NaN : (Math.round(close / step) - f64(ROWS / 2)) * step - step * 0.5; // rows centred on the spacing's multiples
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) {
if (!rowOk(cells, i)) {
skipped += 1;
continue;
}
runCells += 1;
if (isPartial(cells[i + 14])) partial = true;
const strike = cells[i + 1];
const net = cells[i + 10] - cells[i + 11]; // folded: bullish (the ask columns) minus bearish (the bid columns)
addNet(strike, net);
if (isNaN(gridLow)) continue;
const r = i32(Math.floor((strike - gridLow) / step));
if (r < 0 || r >= ROWS) continue; // off this bar's column
rowHeat[r] += net;
rowTouched[r] = true;
}
out_heat_low(gridLow);
out_heat_step(step);
writeVwap(cells, n);
} else {
out_heat_low(NaN);
out_heat_step(NaN);
clearVwap();
}
for (let r = 0; r < ROWS; r += 1) out_heat(r, rowTouched[r] ? rowHeat[r] : NaN); // NaN = an empty cell
out_partial_mark(partial ? bar.low() : NaN);
out_skipped(f64(skipped));
let sessionNet = 0.0;
let bullStrike: f64 = NaN;
let bullNet: f64 = NaN;
let bearStrike: f64 = NaN;
let bearNet: f64 = NaN;
for (let k = 0; k < strikeCount; k += 1) {
const net = netAt[k];
sessionNet += net;
if (net > 0.0 && (isNaN(bullNet) || net > bullNet)) {
bullNet = net;
bullStrike = strikeAt[k];
}
if (net < 0.0 && (isNaN(bearNet) || net < bearNet)) {
bearNet = net;
bearStrike = strikeAt[k];
}
}
out_session_net(strikeCount > 0 ? sessionNet : NaN);
out_top_bull_strike(bullStrike);
out_top_bull_net(bullNet);
out_top_bear_strike(bearStrike);
out_top_bear_net(bearNet);
if (!bar.isLast()) return;
if (strikeCount > 0 && !isNaN(close)) writeProfile();
str_note(runCells == 0 ? "No contract flow on this chart yet" : strikeCount == 0 ? "No contract flow yet this session" : ""); // an empty text draws no label
}How it works
Net premium per strike. The data plane sums each bar's prints per strike, calls and puts in one row with the bullish side on the ask (fold_types): prem_ask holds the calls' premium at the ask and the puts' at the bid, prem_bid the calls' at the bid and the puts' at the ask. A strike's net is the ask premium minus the bid premium, so it reads bullish above zero. Premium at the mid or with no quote has no side and counts in neither. On crypto and CME a print carries the taker's side, so the ask is what the taker bought and the bid what the taker sold.
The rows. The heat map's 48 rows sit on the chain's strike spacing: the package keeps every distinct strike that traded, and the spacing is the most common gap between neighbouring strikes within 10% of the close, matched to a listed spacing (0.5, 1, 2, 2.5, 5 and up to 100 on a stock, and 200, 250, 500, 1,000, 2,000, 2,500 and 5,000 on a coin's chain, so BTC's 1,000 ladder reads 1,000, never the 500 one strike between leaves); Strike step sets one by hand, up to 10,000. Each bar's rows are centred on its close, one row per spacing step with a strike in the middle of each, so a strike's flow lands on the row holding it. The rows of a bar sum its strikes there; a row no strike touched draws nothing.
The session by strike. The same nets add into a table of the session's strikes, which a new trade date empties; on the live bar the strikes within Profile window of the close dock on the price axis, in the up colour above zero and the down colour below. top_bull_strike and top_bear_strike name the session's strongest strikes either way.
The premium centre. On every bar with strike flow, flow_vwap is the bar's premium-weighted centre strike: each whole row's premium on every side (prem_ask, prem_bid, prem_mid and prem_none, so the mid and unquoted prints count here though they take no lean) times its strike, summed, over the premium summed. vwap_hi and vwap_lo sit one premium-weighted standard deviation of the bar's strikes either side, the square root of the premium-weighted mean of each strike's squared distance from the centre, and fill shades between them. A row that is not whole is left out, as it is from the heat map; a bar with no premium, or no block, draws no line. Premium centre turns the three lines off, Premium centre band the band alone.
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 heat map's hover, each docked row's hover and the descriptions of the net readings.
What the settings do
- Strike step: How much price each heat map level covers, where 0 uses the gap between listed strikes (option price levels).
- Profile window, percent: How far the profile on the price axis reaches above and below the price.
- Premium centre: Draws a line at the strike where each bar's premium (money paid for options) centres.
- Premium centre band: Shades one standard deviation (1σ) either side of that line, wider when the money spreads out.
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. The charts of that stock's option contracts work the same way. US options data is 15 minutes behind unless you have real-time US options 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). CME data is 10 minutes behind unless you have real-time CME data. It reads the strikes within 10% of the price. It shows the last 7 days on 1-minute charts and the last 30 days on 5-minute charts.
When data is missing
When only part of a bar's options data arrives, a muted dot sits under its candle. That column then shows a minimum, so the real amount may be higher. A bar with no options data shows an empty column. Incomplete entries are left out: no strike, calls and puts not added together, or an unreadable data flag. To count them, open the Console (the editor's panel that prints values) and type skipped. A label at the top says "No contract flow on this chart yet" until a bar has an options trade. It says "No contract flow yet this session" while today has none.
Customize it
- Coarser rows. Set Strike step to 5 on a stock whose strikes crowd, or to 2,000 on BTC, so each row sums a few strikes.
- The profile's reach. Widen Profile window to see the far strikes the session's money reached.
- The centre alone. Turn Premium centre band off to keep the line and drop the band.
- Today's expiries. Add
expiries: "0dte"to the input to paint the contracts expiring on the bar's trade date alone.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Premium by Strike under Order flow.
- Press Run on a chart of a coin with listed options or of a US stock: the heat map paints behind the candles and the session's profile docks on the price axis.
- At the editor's Console prompt, type
session_net,top_bull_strikeandtop_bear_striketo read the session, andflow_vwapfor the live bar's centre strike.
Concepts used
- Data sources for the
option_strike_flowtuple,strike_window_pctandfold_types - Price canvases for
out.gridandplot.heatmap - Docked profiles for
plot.levelsand per-row colours - Plotting for the premium centre's band
- Data sources for the partial bit
- Limitations for the US options rule