Options odds cloud
This cloud on the price axis shows where traders think price ends by an expiry (the day the option ends).

Each horizontal bar is the odds price ends at that level, and the longest marks the most likely price. Solid lines mark the middle 68% of outcomes (1σ, one standard deviation) and dotted lines the middle 95% (2σ). Use it to see how far price can travel by the expiry, as market odds, not a forecast. It needs this symbol's options, on a coin, a CME (Chicago futures exchange) future or a US stock.
Under the hood: the odds are one curve, N(d2) with the smile's volatility at each price. It reads the expiry whose days to its end are closest to target_days, at least 12 hours after the chain's as-of (the live bar's close). Each strike gets one implied volatility, from its out-of-the-money contract. The grid follows the loaded bars' range plus a margin, within spot times exp(plus or minus 3σ). The card is titled "68% likely", with the expiry read and the 68% band as its headline. It reads options_chain.cells on the live bar (Options kit). It docks a frame on the price axis through plot.levels, with per-row colours, a gradient alpha profile and a poc line (Docked profiles). It places four draw.line lines and five plain draw.label tags from the newest bar (Run-level drawings). It draws a render.hud card with no look word (HUD cards, The default look, Blocks and tiles). It is also the options-odds-cloud template, the Options Odds Cloud card under Beyond the time axis in the editor's starter list, which compiles as written.
The wrun indicator
// Options Odds Cloud: where options traders think price will end by an expiry, as a cloud by the price axis.
// Each horizontal bar in the cloud shows the market's odds that price ends at that level. The longest bar is the most
// likely price, marked by a teal line and a Most likely tag. Solid lines mark the middle 68% of outcomes (1σ, one
// standard deviation), and dotted lines the middle 95% (2σ). A card at the top left names the 68% range and the odds
// of a 5% move either way. Use it to see how far price can travel by the expiry in the market's eyes. These are
// market odds, not a forecast.
//
// Technical notes: where the options market expects price to settle at the chosen expiry, docked on the price
// axis as one smooth profile. Each row is the chain's implied odds that price settles there: a ramp from slate tails
// to a sky core, every bar fading from its root to its tip so it reads as a cloud, the most likely row marked by a
// teal point-of-control line with a plain "Most likely 85.18K" tag beside the price axis. The rows follow the
// price scale the trader sees: the loaded bars' high..low widened by a margin, never wider than spot times
// exp(+-3 sigma), at least 'rows' rows across it, so the cloud is as fine on a 1m chart as on a 1h chart. The 16% and
// 84% prices (the middle 68%) run across the chart as solid muted lines with plain tags "+1σ 87.9K" / "-1σ 81.2K";
// the 2.5% and 97.5% prices are dotted muted lines tagged "+2σ" / "-2σ" (every line shows whenever the pane covers
// it). A card at the top left, under the legend, titled "68% likely" with the expiry read, carries the 68% band as
// its headline ("83.7K to 87.0K") and the odds of a 5% move either way. The chain is live only: history bars only
// widen the loaded price range; everything else is measured on the last bar at the chain's as-of (the live bar's
// close, never its open), every expiry's time running to its end (15 minutes past an OPRA stamp).
section("Expiry and cloud");
param.int("target_days", 2, { min: 1, max: 90, label: "Days to expiry", description: "Reads the expiry (the day the option ends) nearest this many days out, at least 12 hours away. Longer chart intervals suit more days." });
param.int("rows", 90, { min: 60, max: 160, label: "Price steps", description: "The fewest price steps the cloud splits into. They spread over the loaded candles' price range plus the margin. The cloud never reaches past 3σ (three standard deviations) from today's price." });
param.int("margin", 25, { min: 0, max: 100, label: "Margin, percent", description: "How far the cloud reaches past the loaded candles' high and low, in percent of that range." });
section("Look");
param.color("core_ink", "#38bdf8", { label: "Cloud core" });
param.color("tail_ink", "#94a3b8", { label: "Cloud tails" });
param.color("peak_ink", "#2dd4bf", { label: "Most likely price" });
input("close", ohlcv.close); // the chart's own close: the bar grid, and spot when the chain carries no underlying
input("chain", options_chain.cells, { max_cells: 4000, venue: "auto", description: "This symbol's options: listed coin options on crypto, US listed options on a US stock, CME options on a future. One entry per listed contract, read on the live candle only." }); // [strike, expiry_ms, side, oi, gamma, delta, mark_iv, underlying, multiplier, vega]; side +1 call, -1 put; mark_iv in percent a year
market.zone(); // the market's clock: an OPRA expiry trades 15 minutes past its stamp, and the expiry's date
chart.interval_sec(); // the bar's length: the chain's as-of is the live bar's close time, the block naming none
// The readings, data-only: the card and the Console read them. Each is NaN on history bars.
output("p_up_move", none, overlay, { format: "%", description: "The odds price ends 5% or more above today's price at the expiry, in percent. Live candle only." });
output("p_down_move", none, overlay, { format: "%", description: "The odds price ends 5% or more below today's price at the expiry, in percent." });
output("band_low", none, overlay, { format: "price", description: "The price with 16% odds of ending below it: the bottom of the middle 68%." });
output("band_high", none, overlay, { format: "price", description: "The price with 84% odds of ending below it: the top of the middle 68%." });
output("tail_low", none, overlay, { format: "price", description: "The price with 2.5% odds of ending below it: the bottom of the middle 95%." });
output("tail_high", none, overlay, { format: "price", description: "The price with 97.5% odds of ending below it: the top of the middle 95%." });
output("most_likely", none, overlay, { format: "price", description: "The price step with the highest odds: the cloud's peak." });
output("iv_atm", none, overlay, { format: "%", description: "The implied volatility (IV) at today's price for that expiry, in percent a year." });
output("days_to_expiry", none, overlay, { format: "0.0", description: "Days from when the options were read to the end of that expiry." });
output("t_first", none, overlay, { description: "The first loaded candle's open time, in epoch seconds: where the lines start." });
output("t_last", none, overlay, { description: "The live candle's open time, in epoch seconds: where the lines and tags end." });
string("title_text", { max_bytes: 48 }); // the card's title: the odds and the expiry read, "68% likely, 10 Oct 08:00 UTC"
string("band_text", { max_bytes: 32 }); // the card's headline: the 68% band, "81.2K to 87.9K"
string("up_text", { max_bytes: 16 }); // the card's rows: "12%"
string("down_text", { max_bytes: 16 });
string("tag_band_high", { max_bytes: 24 }); // the four price tags
string("tag_band_low", { max_bytes: 24 });
string("tag_tail_high", { max_bytes: 24 });
string("tag_tail_low", { max_bytes: 24 });
string("tag_most_likely", { max_bytes: 32 }); // the cloud's peak: "Most likely 85.18K", "Most likely 85176" on rows under 10 dollars
string("notice", { max_bytes: 48 }); // the one sentence on a market without a chain
handles.label({ anchor: "top_right", align: "right", size: 11, color: "theme.muted", style: "plain", padding: 6, safe_area: true }); // the notice, in pane pixels from the top-right corner
const cloud_rows = frame("cloud_rows", { max_bytes: 16384 }); // the docked cloud: one row per grid price
// The cloud: one bar per grid price docked right, a tenth of the pane wide so the newest candles stay readable, each
// row in its own colour from the frame (the slate-to-sky ramp), every bar fading from its root at the axis to its tip
// (the gradient's alpha profile), the most likely row marked by the point-of-control line in teal (its tag is the
// plain label below, beside the axis), a hover card per row printing the row's odds.
plot.levels({ name: "odds_by_price", frame: cloud_rows, dock: "right", width_frac: 0.1, labels: false, color: "@core_ink", opacity: 0.85, gradient: ["#38bdf8ff", "#38bdf859"], format: "%", decimals: 2, hover: true, poc: true, poc_color: "@peak_ink", poc_width: 2, poc_extend: "dock", poc_label: false });
// The lines across the whole pane, placed from the newest bar: the 68% band's edges solid, the 95% band's dotted,
// both in the muted ink; each shows whenever the pane covers it (an overlay never widens the price pane).
draw.line("band_high_line", { x1: "t_first", y1: "band_high", x2: "t_last", y2: "band_high", color: "theme.muted", width: 1, line_style: "solid", extend: "both" });
draw.line("band_low_line", { x1: "t_first", y1: "band_low", x2: "t_last", y2: "band_low", color: "theme.muted", width: 1, line_style: "solid", extend: "both" });
draw.line("tail_high_line", { x1: "t_first", y1: "tail_high", x2: "t_last", y2: "tail_high", color: "theme.muted", width: 1, line_style: "dotted", extend: "both" });
draw.line("tail_low_line", { x1: "t_first", y1: "tail_low", x2: "t_last", y2: "tail_low", color: "theme.muted", width: 1, line_style: "dotted", extend: "both" });
// The tags: plain muted text right-aligned beside the price axis, each on its line's price side, never across it.
draw.label("tag_band_high", { x: "t_last", y: "band_high", text: "tag_band_high", color: "theme.muted", style: "plain", align: "right", valign: "top", font_weight: "medium", sticky_right: true });
draw.label("tag_band_low", { x: "t_last", y: "band_low", text: "tag_band_low", color: "theme.muted", style: "plain", align: "right", valign: "bottom", font_weight: "medium", sticky_right: true });
draw.label("tag_tail_high", { x: "t_last", y: "tail_high", text: "tag_tail_high", color: "theme.muted", style: "plain", align: "right", valign: "top", font_weight: "medium", sticky_right: true });
draw.label("tag_tail_low", { x: "t_last", y: "tail_low", text: "tag_tail_low", color: "theme.muted", style: "plain", align: "right", valign: "bottom", font_weight: "medium", sticky_right: true });
// The most likely row's tag rides in the same column beside the price axis, plain, just above the POC line.
draw.label("tag_most_likely", { x: "t_last", y: "most_likely", text: "tag_most_likely", color: "theme.muted", style: "plain", align: "right", valign: "bottom", font_weight: "medium", sticky_right: true });
// The card: pinned at the top left under the legend, clear of the newest candles and the cloud on the right, the title
// carrying the odds and the expiry read ({{title_text}} reads the slot of that name), the 68% band alone as the
// headline, then the odds of a 5% move either way as two rows; 250 px fits the longest band ("112.3K to 118.9K").
render.hud("odds", {
position: "top_left",
title: "{{title_text}}",
columns: 1,
width: 250,
safe_area: true,
tiles: [
tile.pill("Range at expiry", "band_text", { headline: true, font_size: 24, draw: "text" }),
tile.rows([
["Up 5% or more", "up_text"],
["Down 5% or more", "down_text"],
]),
],
});
const TUPLE = 10; // f64s per contract
const MAX_STRIKES = 512; // distinct strikes one expiry may list
const MAX_EXPIRIES = 64; // distinct live expiries
const MAX_ROWS = 512; // the levels frame's cap; the rows setting stays far under it
const HALF_DAY_MS = 43200000.0;
const DAY_MS = 86400000.0;
const MOVE = 0.05; // the move the card prices: 5% either way
const strikePrice = new StaticArray<f64>(MAX_STRIKES); // the strike table of the expiry read, sorted ascending
const strikeIv = new StaticArray<f64>(MAX_STRIKES); // the out-of-the-money implied volatility at each strike, a fraction a year
const expiryMs = new StaticArray<f64>(MAX_EXPIRIES); // the live expiries, sorted ascending
const rowPrice = new StaticArray<f64>(MAX_ROWS); // the cloud grid: row centres
const rowProb = new StaticArray<f64>(MAX_ROWS); // the probability of settling inside each row
const edgeAbove = new StaticArray<f64>(MAX_ROWS + 1); // P(settle above the row's lower edge), one more than the rows
const notice = draw.label(0); // the one sentence on a market without a chain; handle objects allocate once
const expiryText = new TextBuilder(16); // the expiry's label, the kit's spelling, copied into the title
let targetDays = 2.0; // settings, read in onStart()
let rowsWanted = 90;
let marginShare = 0.25; // the margin setting as a share of the loaded range
let zone = 0;
let intervalMs = 0.0; // the bar's length in milliseconds; 0 where the host writes none
let nowMs: f64 = NaN; // the chain's as-of, the live bar's close
const coreRgb = new StaticArray<i32>(3); // the ramp's inks as r, g, b: read from the colour settings in onStart()
const tailRgb = new StaticArray<i32>(3);
let close: f64 = NaN; // this bar
let t: f64 = NaN;
let firstT: f64 = NaN; // the first bar's open time: where the lines start
let loadedHigh: f64 = -Infinity; // the loaded bars' price range: the cloud's rows follow it
let loadedLow: f64 = Infinity;
let strikeCount = 0;
let expiryCount = 0;
let expiry: f64 = NaN; // the expiry read, epoch ms
let spot: f64 = NaN; // the chain's underlying
let years: f64 = NaN; // time to the expiry's end in years, from the chain's as-of
let ivAtm: f64 = NaN; // a fraction a year
let sigmaT: f64 = NaN; // iv_atm times sqrt(T): one standard deviation of the log price
let gridLo: f64 = NaN;
let gridStep: f64 = NaN;
let gridRows = 0;
let peakRow = -1;
let q025: f64 = NaN; // the quantile prices
let q16: f64 = NaN;
let q84: f64 = NaN;
let q975: f64 = NaN;
let pUpMove: f64 = NaN; // odds of a 5% move, percent
let pDownMove: f64 = NaN;
// ── The strike table: sorted insertion, one row per strike ──
function strikeSlot(strike: f64): i32 { // the row of this strike, inserted when new; -1 when the table is full
let lo = 0;
let hi = strikeCount;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (strikePrice[mid] < strike) lo = mid + 1;
else hi = mid;
}
if (lo < strikeCount && strikePrice[lo] == strike) return lo;
if (strikeCount >= MAX_STRIKES) return -1;
for (let i = strikeCount; i > lo; i -= 1) {
strikePrice[i] = strikePrice[i - 1];
strikeIv[i] = strikeIv[i - 1];
}
strikePrice[lo] = strike;
strikeIv[lo] = NaN;
strikeCount += 1;
return lo;
}
function noteExpiry(ms: f64): void { // sorted insertion of a distinct live expiry
let lo = 0;
let hi = expiryCount;
while (lo < hi) {
const mid = (lo + hi) >> 1;
if (expiryMs[mid] < ms) lo = mid + 1;
else hi = mid;
}
if (lo < expiryCount && expiryMs[lo] == ms) return;
if (expiryCount >= MAX_EXPIRIES) return;
for (let i = expiryCount; i > lo; i -= 1) expiryMs[i] = expiryMs[i - 1];
expiryMs[lo] = ms;
expiryCount += 1;
}
// ── The math: the smile, the normal, the odds ──
function ivAt(price: f64): f64 { // implied volatility at any price: linear between neighbouring strikes, flat beyond the ends
if (strikeCount == 0) return NaN;
if (price <= strikePrice[0]) return strikeIv[0];
if (price >= strikePrice[strikeCount - 1]) return strikeIv[strikeCount - 1];
let lo = 0;
let hi = strikeCount - 1;
while (hi - lo > 1) {
const mid = (lo + hi) >> 1;
if (strikePrice[mid] <= price) lo = mid;
else hi = mid;
}
const share = (price - strikePrice[lo]) / (strikePrice[hi] - strikePrice[lo]);
return strikeIv[lo] + (strikeIv[hi] - strikeIv[lo]) * share;
}
function normalCdf(x: f64): f64 { // the standard normal CDF through Abramowitz-Stegun 7.1.26 (error under 2e-7)
const z = Math.abs(x) / Math.SQRT2;
const u = 1.0 / (1.0 + 0.3275911 * z);
const poly = u * (0.254829592 + u * (-0.284496736 + u * (1.421413741 + u * (-1.453152027 + u * 1.061405429))));
const erf = 1.0 - poly * Math.exp(-z * z);
return x >= 0.0 ? 0.5 * (1.0 + erf) : 0.5 * (1.0 - erf);
}
function pAbove(price: f64): f64 { // the chain's odds that price settles above this price: N(d2) with the smile's volatility at the price
if (!(price > 0.0)) return 1.0;
const iv = ivAt(price);
if (!(iv > 0.0)) return NaN;
const d2 = (Math.log(spot / price) - 0.5 * iv * iv * years) / (iv * Math.sqrt(years));
return normalCdf(d2);
}
function priceWhereAbove(target: f64): f64 { // the price with P(above) = target, by bisection over eight standard deviations
let lo = spot * Math.exp(-8.0 * sigmaT);
let hi = spot * Math.exp(8.0 * sigmaT);
for (let i = 0; i < 64; i += 1) {
const mid = 0.5 * (lo + hi);
if (pAbove(mid) > target) lo = mid;
else hi = mid;
}
return 0.5 * (lo + hi);
}
function niceStepAtMost(raw: f64): f64 { // the largest round step at or under raw: 1, 1.5, 2, 2.5, 3, 4, 5, 6, 8 times a power of ten
let mag = Math.pow(10.0, Math.floor(Math.log(raw) / Math.LN10));
if (mag > raw) mag /= 10.0; // the logarithm rounded up across a power of ten
const m = raw / mag;
if (m >= 8.0) return 8.0 * mag;
if (m >= 6.0) return 6.0 * mag;
if (m >= 5.0) return 5.0 * mag;
if (m >= 4.0) return 4.0 * mag;
if (m >= 3.0) return 3.0 * mag;
if (m >= 2.5) return 2.5 * mag;
if (m >= 2.0) return 2.0 * mag;
if (m >= 1.5) return 1.5 * mag;
return mag;
}
function priceDecimals(step: f64): i32 { // enough decimals that the grid's row prices stay evenly spaced when parsed (the docked grid is contiguous only within 0.1% of its step)
const d = i32(Math.ceil(Math.log(2000.0 / step) / Math.LN10));
return d < 2 ? 2 : d > 9 ? 9 : d;
}
// ── The chain, measured on the live bar ──
function measureChain(n: i32): bool { // n = f64 cells in the live block; false when nothing usable is listed
const cells = in_chain_view(); // the live chain in place: the first n values of the build's own buffer
nowMs = optionsAsOfMs(t * 1000.0, intervalMs); // the chain's as-of: the live bar's close time
expiryCount = 0;
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) if (optionsLiveUntilMs(cells[i + 1], zone) >= nowMs + HALF_DAY_MS) noteExpiry(cells[i + 1]); // the expiries trading at least 12 h more
if (expiryCount == 0) return false;
let best = 0;
let bestDistance = Infinity;
for (let k = 0; k < expiryCount; k += 1) { // the expiry whose distance in days is closest to the setting; ties keep the earlier
const distance = Math.abs((optionsLiveUntilMs(expiryMs[k], zone) - nowMs) / DAY_MS - targetDays);
if (distance < bestDistance) {
bestDistance = distance;
best = k;
}
}
expiry = expiryMs[best];
spot = NaN;
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) { // spot: the chain's own underlying at that expiry
if (cells[i + 1] == expiry && cells[i + 7] > 0.0) {
spot = cells[i + 7];
break;
}
}
if (!(spot > 0.0)) spot = close;
if (!(spot > 0.0)) return false;
strikeCount = 0;
for (let i = 0; i + TUPLE - 1 < n; i += TUPLE) { // one volatility per strike, from the out-of-the-money contract: puts below spot, calls at or above
if (cells[i + 1] != expiry) continue;
const strike = cells[i];
if (!(strike > 0.0)) continue;
const isCall = cells[i + 2] > 0.0;
if (isCall != (strike >= spot)) continue;
const iv = cells[i + 6] / 100.0; // mark IV rides the chain in percentage points (45.2 is 45.2%), kept as a fraction
if (!(iv > 0.0)) continue;
const slot = strikeSlot(strike);
if (slot < 0) continue;
strikeIv[slot] = iv;
}
if (strikeCount == 0) return false;
years = optionsYearsToGo(expiry, nowMs, zone);
if (!(years > 0.0)) return false;
ivAtm = ivAt(spot);
if (!(ivAtm > 0.0)) return false;
sigmaT = ivAtm * Math.sqrt(years);
q025 = priceWhereAbove(0.975);
q16 = priceWhereAbove(0.84);
q84 = priceWhereAbove(0.16);
q975 = priceWhereAbove(0.025);
pUpMove = pAbove(spot * (1.0 + MOVE)) * 100.0;
pDownMove = (1.0 - pAbove(spot * (1.0 - MOVE))) * 100.0;
// The grid follows the price scale the trader sees: the loaded bars' low..high widened by the margin on each side
// (never thinner than a tenth of a standard deviation, for a flat or one-bar window), clamped to spot times
// exp(+-3 sigma), at the largest round step that puts at least 'rows' rows across it. A 1m chart gets rows a few
// dollars apart over its few hundred dollars of range, a 1h chart the whole bell; the odds are the same.
const bandLo = spot * Math.exp(-3.0 * sigmaT);
const bandHi = spot * Math.exp(3.0 * sigmaT);
let lo = bandLo;
let hi = bandHi;
const range = loadedHigh - loadedLow;
if (range >= 0.0) { // false when no bar carried a finite high and low: the grid keeps the whole band
let seenLo = loadedLow - range * marginShare;
let seenHi = loadedHigh + range * marginShare;
const thinnest = 0.1 * spot * sigmaT;
if (seenHi - seenLo < thinnest) {
const mid = 0.5 * (seenLo + seenHi);
seenLo = mid - 0.5 * thinnest;
seenHi = mid + 0.5 * thinnest;
}
if (seenLo > lo) lo = seenLo;
if (seenHi < hi) hi = seenHi;
if (!(hi > lo)) { // the loaded range sits outside the band entirely (a far basis): keep the band
lo = bandLo;
hi = bandHi;
}
}
// The row probability is the drop in P(above) across the row, after P(above) is forced non-increasing up the grid.
gridStep = niceStepAtMost((hi - lo) / f64(rowsWanted - 1));
gridLo = Math.floor(lo / gridStep) * gridStep;
gridRows = i32(Math.ceil((hi - gridLo) / gridStep)) + 1;
while (gridRows > MAX_ROWS) { // never with the rows setting's range; kept so the frame can never overflow
gridStep *= 2.0;
gridLo = Math.floor(lo / gridStep) * gridStep;
gridRows = i32(Math.ceil((hi - gridLo) / gridStep)) + 1;
}
if (gridRows < 3) return false; // the engine needs three prices for a grid
for (let r = 0; r <= gridRows; r += 1) edgeAbove[r] = pAbove(gridLo + (f64(r) - 0.5) * gridStep);
for (let r = 1; r <= gridRows; r += 1) if (!(edgeAbove[r] <= edgeAbove[r - 1])) edgeAbove[r] = edgeAbove[r - 1];
peakRow = 0;
for (let r = 0; r < gridRows; r += 1) {
rowPrice[r] = gridLo + f64(r) * gridStep;
const p = edgeAbove[r] - edgeAbove[r + 1];
rowProb[r] = p > 0.0 ? p : 0.0;
if (rowProb[r] > rowProb[peakRow]) peakRow = r;
}
return true;
}
// ── The docked cloud ──
const HEX: String[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; // allocated at load, so a row colour never allocates per bar
function fbHexByte(v: i32): void { // two lowercase hex digits
fb_text(HEX[(v >> 4) & 0xf]);
fb_text(HEX[v & 0xf]);
}
function fbRamp(w: f64): void { // "#rrggbb": the tail ink moved toward the core ink by w (0..1), opaque
const k = w < 0.0 ? 0.0 : w > 1.0 ? 1.0 : w;
fb_text("\"#");
for (let c = 0; c < 3; c += 1) fbHexByte(i32(Math.round(f64(tailRgb[c]) + (f64(coreRgb[c]) - f64(tailRgb[c])) * k)));
fb_text("\"");
}
function readInk(packed: f64, rgb: StaticArray<i32>): void { // a colour setting arrives packed as ((r * 256 + g) * 256 + b) * 1024 + alpha thousandths
const v = Math.floor(packed / 1024.0);
const n = v >= 0.0 && v <= 16777215.0 ? i32(v) : 0;
rgb[0] = (n >> 16) & 0xff;
rgb[1] = (n >> 8) & 0xff;
rgb[2] = n & 0xff;
}
function writeCloud(): void {
const decimals = priceDecimals(gridStep);
const peak = rowProb[peakRow] > 0.0 ? rowProb[peakRow] : 1.0;
fb_clear();
fb_text("{\"prices\":[");
for (let r = 0; r < gridRows; r += 1) {
if (r > 0) fb_text(",");
fb_f64(rowPrice[r], decimals);
}
fb_text("],\"values\":[");
for (let r = 0; r < gridRows; r += 1) {
if (r > 0) fb_text(",");
fb_f64(rowProb[r] * 100.0, 4); // bar length: the row's odds in percent
}
fb_text("],\"colors\":[");
for (let r = 0; r < gridRows; r += 1) {
if (r > 0) fb_text(",");
fbRamp(rowProb[r] / peak); // the ramp by the row's share of the peak: slate tails, a sky core
}
// The point of control marks the row the tag names: on a nearly flat slice (a 1m window) several rows tie at the
// written precision and the engine's own pick could land a few rows away. No poc_label_text: the docked tag stays
// off, the tag beside the axis names the row.
fb_text("],\"poc_price\":");
fb_f64(rowPrice[peakRow], decimals);
fb_text("}");
writeFrameBuffer(cloud_rows);
}
// ── Text helpers ──
function sbK(v: f64): void { // prices as the market reads them, thousands as K: 87.9K / 2.43K / 152.33 / 0.15234
if (v >= 10000.0) {
sb_f64(v / 1000.0, 1);
sb_text("K");
} else if (v >= 1000.0) {
sb_f64(v / 1000.0, 2);
sb_text("K");
} else sb_auto(v);
}
function tag(name: String, price: f64): void { // "+1σ 87.9K" into the line buffer
sb_clear();
sb_text(name);
sb_text(" ");
sbK(price);
}
function sbRowPrice(v: f64, step: f64): void { // a grid row's price, fine enough to tell its row from the next: 85.2K on 100-dollar rows, 85.18K on 10s, the axis's own digits below that (85176)
if (v >= 1000.0 && step >= 100.0) sb_compact(v, 1);
else if (v >= 1000.0 && step >= 10.0) sb_compact(v, 2);
else sb_price(v, step);
}
function onStart(): void {
targetDays = f64(p_target_days());
rowsWanted = i32(p_rows());
marginShare = f64(p_margin()) / 100.0;
readInk(p_core_ink(), coreRgb);
readInk(p_tail_ink(), tailRgb);
zone = i32(p_market_zone());
intervalMs = p_chart_interval_sec() * 1000.0;
}
// onBar() runs once per bar: history rows carry an empty block and cost three reads (the first bar's time is kept
// for the lines, every bar's high and low widen the loaded price range the grid follows); the live bar measures the
// chain, then writes the readings as numbers, the cloud, the lines, the tags and the card's words. A live bar
// without a usable chain writes the one muted sentence instead.
function onBar(): void {
close = bar.close();
t = bar.time();
if (isNaN(firstT) && !isNaN(t)) firstT = t;
const high = bar.high();
const low = bar.low();
if (high > loadedHigh) loadedHigh = high; // NaN never widens the range
if (low < loadedLow) loadedLow = low;
if (!bar.isLast()) return;
const n = in_chain_cells();
const chainRead = n >= TUPLE && measureChain(n);
out_t_first(firstT);
out_t_last(t);
if (!chainRead) {
sb_clear();
sb_text("No options for this market");
notice.set(16, 14).text(str_notice_sb);
sb_clear();
sb_text("Options odds");
str_title_text_sb();
sb_clear();
sb_text("No expiry to read");
str_band_text_sb();
sb_clear();
sb_text("-");
str_up_text_sb();
sb_clear();
sb_text("-");
str_down_text_sb();
return;
}
notice.delete(); // a no-op when never drawn
out_p_up_move(pUpMove);
out_p_down_move(pDownMove);
out_band_low(q16);
out_band_high(q84);
out_tail_low(q025);
out_tail_high(q975);
out_most_likely(rowPrice[peakRow]);
out_iv_atm(ivAtm * 100.0);
out_days_to_expiry(years * 365.0);
writeCloud();
tag("+1σ", q84);
str_tag_band_high_sb();
tag("-1σ", q16);
str_tag_band_low_sb();
tag("+2σ", q975);
str_tag_tail_high_sb();
tag("-2σ", q025);
str_tag_tail_low_sb();
sb_clear();
sb_text("Most likely ");
sbRowPrice(rowPrice[peakRow], gridStep);
str_tag_most_likely_sb();
// The card's words: the odds and the expiry read for the title, the 68% band alone as the headline, the odds of
// a 5% move as rows.
sb_clear();
sb_text("68% likely, ");
expiryText.clear().expiry(expiry, nowMs, zone); // the expiry's trade date: 10 Oct, or 15 Jan '27 in another year
for (let i = 0; i < expiryText.length(); i += 1) sb_char(load<u8>(<usize>expiryText.ptr() + <usize>i));
sb_text(" ");
sb_time(expiry / 1000.0, "HH:mm", 0);
sb_text(" UTC");
str_title_text_sb();
sb_clear();
sbK(q16);
sb_text(" to ");
sbK(q84);
str_band_text_sb();
sb_clear();
sb_f64(pUpMove, 0);
sb_text("%");
str_up_text_sb();
sb_clear();
sb_f64(pDownMove, 0);
sb_text("%");
str_down_text_sb();
}How it works
The chain is live only. input("chain", options_chain.cells, { max_cells: 4000, venue: "auto" }) serves the chart's own option chain (the coin's listed options on crypto, OPRA on a US stock, CME on a futures chart) on the newest bar as one ten-value tuple per listed contract (strike, expiry, side, open interest, gamma, delta, the mark implied volatility, the underlying, the multiplier and vega), and every history bar carries an empty block. onBar() keeps the first bar's open time for the lines and widens the loaded price range with every bar's bar.high() and bar.low(), history included, then returns on every bar but the last, so history draws nothing; on the live bar in_chain_cells() counts the values and in_chain_view() reads the block in place. The chart's own close is the bar grid, and spot when the chain carries no underlying.
The chain's as-of, the live bar's close. The odds run from the chain's as-of, optionsAsOfMs(): the live bar's close time, bar.time() plus chart.interval_sec(), never its open. A bar of a day or longer is read at its close, so a 1D bar's as-of is the next 00:00 UTC and a 1W bar's the next week's open. Each expiry's time runs to its end on the market's clock (market.zone()): optionsLiveUntilMs() puts an OPRA expiry's end 15 minutes past its stamp (a PM expiry stamped 16:00 New York trades until 16:15) and a CME or crypto expiry's at the stamp, and optionsYearsToGo() is that time in 365-day years, the time the odds are priced over.
One expiry, one smile. measureChain() lists the expiries still trading at least 12 hours after the as-of and keeps the one whose days to its end are closest to target_days (ties keep the earlier). Spot is the chain's own underlying at that expiry, else the close. One implied volatility per strike comes from the out-of-the-money contract (puts below spot, calls at or above), the venue's percent a year turned into a fraction, and ivAt() reads the smile at any price: linear between neighbouring strikes, flat beyond the ends.
The odds are one curve. pAbove() is the chain's odds that price settles above a price, N(d2) with the smile's volatility at that price through normalCdf(). priceWhereAbove() bisects over eight standard deviations for the prices with 97.5%, 84%, 16% and 2.5% odds of settling above them (tail_low, band_low, band_high, tail_high), and p_up_move and p_down_move are the odds of settling 5% or more above or below spot (MOVE). iv_atm, days_to_expiry (from the as-of to the end of the expiry read) and most_likely ride beside them, all data-only outputs that read NaN on history bars.
The rows follow the loaded range. On the live bar measureChain() takes the loaded bars' low to high, widens it by margin percent of itself on each side, keeps it at least a tenth of a standard deviation wide (for a flat or one-bar window), and clamps it to spot times exp(plus or minus three standard deviations of the log price). niceStepAtMost() then takes the largest round step (1, 1.5, 2, 2.5, 3, 4, 5, 6 or 8 times a power of ten) at or under the span over rows - 1, so rows is a floor: the grid holds at least that many rows. A 1m chart gets rows a few dollars apart over its few hundred dollars of range, a 1h chart the whole bell, and the odds differ only by each chart's as-of; on a fine chart the visible slice of the bell is nearly flat, which is the odds, not a fault. A row's odds are the drop in P(above) across the row, after the curve is forced non-increasing up the grid.
The grid is the cloud. writeCloud() builds the frame through fb_* with prices (written to priceDecimals() of the step, so the rows stay evenly spaced when parsed), values (the odds in percent), colors (the tail ink moved toward the core ink by the row's share of the peak, so the tails read slate and the core sky) and poc_price (the most likely row), and sends it with writeFrameBuffer(cloud_rows). plot.levels docks it right at 0.1 of the pane, narrow enough that the newest candles over it stay readable: color: "@core_ink" is the level's own colour, the fallback for a row without one; gradient is the alpha profile from each bar's root to its tip (a row with its own colour keeps its hue and takes the stops' alpha); poc: true draws a 2 px point-of-control line in @peak_ink across the dock at the price the frame names, so on a nearly flat slice, where several rows tie at the written precision, the line still marks the row the tag names; hover: true opens a row's odds (format: "%", decimals: 2: a 10-dollar row holds about 0.24%). poc_label: false turns the engine's docked tag off, and the frame writes no poc_label_text, since that field alone would turn it back on. core_ink and tail_ink arrive in onStart() packed as one number each, and readInk() unpacks them to red, green and blue for the ramp.
The lines and tags are declarations. draw.line("band_high_line", { x1: "t_first", y1: "band_high", x2: "t_last", y2: "band_high", ... extend: "both" }) reads its coordinates from outputs by name on the newest bar; the 68% band's edges are solid and the 95% band's dotted, both in the muted colour, and each shows whenever the pane covers it. The tags are draw.label declarations reading string slots (tag_band_high holds "+1σ 87.0K", built by sbK() with thousands as K), plain text in the muted colour (style: "plain"), with align: "right" and sticky_right: true, so they ride beside the price axis as the chart scrolls. Each sits on its line's side nearer the price: valign: "top" on a high edge hangs the words below the line and valign: "bottom" on a low edge sets them above it, so no line runs through its tag and a tail at the pane's edge keeps its tag inside the pane.
The most likely row has its own tag. draw.label("tag_most_likely", { x: "t_last", y: "most_likely", text: "tag_most_likely", color: "theme.muted", ... sticky_right: true }) is plain text in the muted colour, right-aligned beside the price axis in the same column as the sigma tags, never on the axis. With valign: "bottom" its words sit just above the POC line, which crosses the dock at the same price, so the line never runs through them. sbRowPrice() writes the row's price at the grid's resolution: a price of 1000 or more prints compact through sb_compact (thousands as K), with one decimal on rows of 100 or more ("Most likely 85.2K") and two on rows of 10 or more ("Most likely 85.26K"); anything else prints through sb_price with the step as the tick, the axis's own digits ("Most likely 85272"). The frame's poc_price names the same row, so the POC line and the tag mark one price. The tag's colour is a theme word, not the peak ink, because a draw.label colour cannot name a setting (The Style page): a changed peak ink moves the POC line and leaves the tag muted.
The card reads slots. render.hud("odds", { position: "top_left", title: "{{title_text}}", columns: 1, width: 250, safe_area: true, tiles: [...] }) names no look, so the card draws the chart's default look: the title is the one slot title_text, written on the live bar as "68% likely, ", the kit's expiry label (TextBuilder.expiry: the expiry's trade date on the market's clock, copied in with sb_char), then sb_time(expiry / 1000.0, "HH:mm", 0) and " UTC"; tile.pill("Range at expiry", "band_text", { headline: true, font_size: 24, draw: "text" }) is the headline, the band alone at 24 px, where draw: "text" prints the words alone, with no capsule and no dot; tile.rows prints up_text and down_text, the odds rounded to whole percent. The 250 px width fits the longest band ("112.3K to 118.9K") at 24 px, and safe_area starts the card under the legend, so it covers the oldest candles on screen, never the newest ones or the cloud.
What the settings do
- Days to expiry: Which expiry to read: the one closest to this many days out, at least 12 hours away.
- Price steps: The fewest price steps the cloud splits into: more steps draw a finer cloud.
- Margin, percent: How far the cloud reaches past the loaded candles' high and low, in percent of that range.
- Cloud core: The colour of the cloud's likely middle.
- Cloud tails: The colour of the cloud's unlikely ends.
- Most likely price: The colour of the line that marks the most likely price.
- Range at expiry: The middle 68% of outcomes at the expiry, from its low price to its high price.
- Up 5% or more: The odds price ends 5% or more above today's price at the expiry.
- Down 5% or more: The odds price ends 5% or more below today's price at the expiry.
Where it runs
It works on coins with listed options, on any exchange and any interval. Examples are BTCUSDT on Binance Futures at 1m, 15m and 1h, and ETHUSDT on Binance spot at 15m and 1h. It reads the coin's options, from Deribit (a crypto options exchange) for the coins it lists. A copy you run from the editor (the code panel beside the chart) reads them too. On a US stock chart it reads that stock's US listed options. The data is 15 minutes behind unless you have real-time US options data. On a CME (Chicago futures exchange) futures chart it reads the options on that future, 10 minutes behind unless you have real-time CME data. A copy you run from the editor reads them too, once you accept the CME market data terms. The chart interval changes the odds only through the time they are read, the live candle's close. It does change how much price range the cloud covers. At 1m it is a fine, nearly flat wall over the whole pane. At 15m it is a hump, and at 1h the whole bell. The pane's own range decides what you see. On a 15m chart the +2σ and -2σ lines can sit outside the pane. Sometimes one edge of the 68% range does too, while a 1h pane shows the whole bell. A longer horizon on a fine chart needs the price axis zoomed out. The cloud never widens the price pane. The cloud shows as its own layer, so the legend lists two indicators for one file. The legend names the cloud "Odds by price". The card's title names the expiry by its date on the market's clock and its time in UTC. On a market with no options the run stops before the first candle. The legend then shows an error chip naming the market, and nothing draws.
When data is missing
When the options cannot be read, a muted note shows at the top right of the pane. It reads "No options for this market". That happens with no options at all, or no expiry still trading at least 12 hours ahead. It also happens when no strike has an implied volatility. The card's title then reads "Options odds", its headline "No expiry to read" and both odds a dash. No cloud draws, and the band lines and tags draw nothing. Older candles draw nothing: their readings are empty, and their highs and lows only set the range the cloud covers. The band lines cross the whole pane whatever history is loaded, while the cloud follows the loaded range. With no usable candle high and low, the cloud covers the whole bell out to 3σ (three standard deviations). It does the same when the range sits wholly outside the bell. A flat or one-candle window still spans a tenth of a standard deviation.
Customize it
- A longer horizon.
target_days(2, from 1 to 90) picks the expiry read: the listed expiry still trading at least 12 hours after the as-of whose days to its end are closest to it. A higher timeframe wants a longer horizon, and a long horizon on a fine chart puts the band outside the pane until the price axis is zoomed out. - A finer cloud.
rows(90, from 60 to 160) is the fewest rows the grid puts across the loaded range and its margin: the step is the largest round price at or under the span overrows - 1, so the cloud holds at least that many rows and a higher setting gives a finer step. - A wider reach.
margin(25, from 0 to 100) is how far the cloud reaches past the loaded bars' high and low, percent of that range on each side: 0 keeps the rows to the loaded range, and no margin takes them past spot times exp(plus or minus three standard deviations). - Other inks.
core_ink(sky),tail_ink(slate) andpeak_ink(teal) under the Look section: the ramp runs from the tail ink to the core ink by each row's share of the peak, and the point-of-control line takes the peak ink. The band lines, their tags and the Most likely tag keeptheme.muted, since adraw.*colour takes a literal, not a setting: change them in the source to match new inks. - Another move.
MOVE(0.05) is the move the card prices; the rows' labels are literals, so change "Up 5% or more" and "Down 5% or more" with it (p_up_moveandp_down_movecarry the same odds for the Console and watches). - A look of its own. The card names no
look, so it draws the chart's default look. When it should stand apart from the chart, addlook:with any of the twelve shipped looks (Looks); a word declared beside it still wins, and the Look row on the indicator's Style page switches the look without code (The Style page). Bindinglookto aparam.choiceover looks as"@name"makes it a setting, whose row then stands in for the Look row.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Options Odds Cloud under Beyond the time axis.
- Press Run on a chart of a coin with listed options, such as BTCUSDT on Binance Futures at 15m: the cloud docks on the right of the price pane with its Most likely tag beside the price axis, the band lines cross the chart with their tags in the same column, and the card appears at the top left, under the legend. Rest the pointer on a cloud row to read its odds. Switch to 1m for rows a few dollars apart over the whole pane, or to 1h for the whole bell.
- At the editor's Console prompt, type
last 20 p_up_moveto read the odds of a 5% rise on the last 20 bars: a number on the newest bar only, since the chain is live only.
Concepts used
- Options kit for
options_chain.cells, the ten-value tuple,venueand reading the chain underbar.isLast(), and the chain's as-of foroptionsAsOfMs,optionsLiveUntilMsandoptionsYearsToGo - Docked profiles for
plot.levels, the frame'scolorsandpoc_price,gradient,pocwithpoc_label: false,decimalsandhover - Frames, panels and compact widgets for
frame(), thefb_*builders andwriteFrameBuffer - Run-level drawings for declared
draw.lineanddraw.label, their output-name coordinates,extend,sticky_rightand thestyleword - Handles for the
handles.labelnotice - HUD cards for
render.hud,width,offsetandsafe_area - The default look for what a card with no
lookdraws, and Looks for the twelve it can name, a word besidelookwinning over it andlookbound to aparam.choice - Blocks and tiles for the headline
tile.pillwithdraw: "text"andtile.rows - The Style page for the Look row,
param.colorbound by"@name"and the literal adraw.*colour keeps - Strings and text for
sb_time,sb_compact,sb_price,sb_autoandsb_f64, and A second builder forTextBuilder.expiry