Options volume

View as MarkdownOpen the editor

On crypto, CME (Chicago futures exchange) or US stock charts, columns under the chart show options contracts traded each bar.

Calls (bets on a rise) stack above zero and puts (bets on a fall) below. Columns split into bought at the ask (the seller's price), sold at the bid (the buyer's price), or neither. Big call buying leans bullish and big put buying leans bearish. Use the card's put/call ratio (puts traded per call) to judge the session.

Under the hood: the recipe reads eight options_flow fields, the contracts by side for calls and puts (Data sources). It draws ten bar columns that share one stack, so positives pile up above zero and negatives below in the order they are declared (Plotting). A render.hud card with no look word sits over them (HUD cards, The default look). It is also the options-volume template, the Options Volume card under Order flow in the editor's starter list, and it compiles as written.

The wrun indicator

// Options Volume: on crypto, CME (Chicago futures exchange) or US stock charts, columns under the chart show options
// contracts traded each bar. Calls (bets on a rise) stack above zero and puts (bets on a fall) below. Columns split
// into bought at the ask (the seller's price), sold at the bid (the buyer's price), or neither. Big call buying leans
// bullish and big put buying leans bearish. Use the card's put/call ratio (puts traded per call) to judge the session.
//
// Technical notes: the option contracts traded on the chart's underlying in every bar, calls stacked above zero and
// puts below, each column split by where its prints traded against the quote. By side (the default): calls bought at
// the ask in the up colour, sold at the bid in a paler up and at the mid or with no quote muted; puts the same in the
// down colour under zero. Bullish and bearish: calls bought at the ask and puts sold at the bid stack above zero as
// bullish, puts bought at the ask and calls sold at the bid below zero as bearish, and the prints at the mid or with no
// quote split evenly into a muted band on each side, since they carry no side. A card at the top right reads the
// session (each trade date starts again): the call and put contracts, the put/call ratio and the bullish share of the
// sided contracts. The rows come from options_flow, one per bar: 1-minute rows reach back 7 days and 5-minute rows 30
// days, so older bars carry none; a bar without a row draws no column, and the card counts the regular-session bars
// that had none, the sums being a floor while that count is above 0.

param.choice("split", ["By side", "Bullish and bearish"], "By side", { label: "Split", description: "By side splits each column into trades at the ask, at the bid, and with no clear side. Bullish and bearish puts calls bought and puts sold above zero, and puts bought and calls sold below. Trades with no clear side split evenly between the two." });
input("close", ohlcv.close); // the chart's own candles: the bar grid
input("trade_date", time.trade_date); // the bar's trade date: the card's sums start again on each
input("session", time.session); // 1 in the regular session: the bars a missing row is counted on
input("call_ask", options_flow.call_contracts_ask, { missing: "nan", description: "Call contracts bought at the ask (the seller's price) in this bar." }); // NaN on a bar the class serves no row for
input("call_bid", options_flow.call_contracts_bid, { missing: "nan", description: "Call contracts sold at the bid (the buyer's price) in this bar." });
input("call_mid", options_flow.call_contracts_mid, { missing: "nan", description: "Call contracts traded at the mid, halfway between the bid and the ask, in this bar." });
input("call_none", options_flow.call_contracts_none, { missing: "nan", description: "Call contracts traded with no quote to tell their side, in this bar." });
input("put_ask", options_flow.put_contracts_ask, { missing: "nan", description: "Put contracts bought at the ask in this bar." });
input("put_bid", options_flow.put_contracts_bid, { missing: "nan", description: "Put contracts sold at the bid in this bar." });
input("put_mid", options_flow.put_contracts_mid, { missing: "nan", description: "Put contracts traded at the mid in this bar." });
input("put_none", options_flow.put_contracts_none, { missing: "nan", description: "Put contracts traded with no quote to tell their side, in this bar." });
// The columns: one stack, the calls (or the bullish side) above zero and the puts (or the bearish side) below, in
// declaration order. Each split writes its own columns; the other split's read NaN and draw nothing.
output("calls_ask", bar, lower, { color: "theme.up", width: 0.8, stack: "contracts", label: "Calls bought at the ask", format: "si", description: "Calls (bets on a rise) bought at the ask, the seller's price. Shown in the By side split." });
output("calls_bid", bar, lower, { color: "theme.up", opacity: 0.55, width: 0.8, stack: "contracts", label: "Calls sold at the bid", format: "si", description: "Calls sold at the bid, the buyer's price. Shown in the By side split." });
output("calls_other", bar, lower, { color: "theme.muted", width: 0.8, stack: "contracts", label: "Calls, no clear side", format: "si", description: "Calls traded at the mid or with no quote, so with no clear side. Shown in the By side split." });
output("puts_ask", bar, lower, { color: "theme.down", width: 0.8, stack: "contracts", label: "Puts bought at the ask", format: "si", description: "Puts (bets on a fall) bought at the ask, drawn below zero. Shown in the By side split." });
output("puts_bid", bar, lower, { color: "theme.down", opacity: 0.55, width: 0.8, stack: "contracts", label: "Puts sold at the bid", format: "si", description: "Puts sold at the bid, drawn below zero. Shown in the By side split." });
output("puts_other", bar, lower, { color: "theme.muted", width: 0.8, stack: "contracts", label: "Puts, no clear side", format: "si", description: "Puts traded at the mid or with no quote, drawn below zero. Shown in the By side split." });
output("bullish", bar, lower, { color: "theme.up", width: 0.8, stack: "contracts", label: "Bullish", format: "si", description: "Calls bought at the ask plus puts sold at the bid: bets on a rise. Shown in the Bullish and bearish split." });
output("neutral_up", bar, lower, { color: "theme.muted", width: 0.8, stack: "contracts", label: "Neutral", format: "si", description: "Half the contracts with no clear side, drawn above zero. Shown in the Bullish and bearish split." });
output("neutral_down", bar, lower, { color: "theme.muted", width: 0.8, stack: "contracts", label: "Neutral, below", legend: false, format: "si", description: "The other half, drawn below zero. Shown in the Bullish and bearish split." });
output("bearish", bar, lower, { color: "theme.down", width: 0.8, stack: "contracts", label: "Bearish", format: "si", description: "Puts bought at the ask plus calls sold at the bid: bets on a fall, drawn below zero. Shown in the Bullish and bearish split." });
// The readings, data-only: the card reads them and the Console can too.
output("session_calls", none, lower, { description: "Call contracts traded this session." });
output("session_puts", none, lower, { description: "Put contracts traded this session." });
output("put_call", none, lower, { description: "The session's put/call ratio: put contracts per call contract. Above 1, more puts traded than calls." });
output("bull_share", none, lower, { description: "Bullish contracts as a percent of bullish plus bearish, trades with a clear side only. Above 50, bullish trades lead." });
output("missing_bars", none, lower, { description: "Regular-session bars this session with no options data. Above 0, read the sums as at least what they show." });
output("tone", none, lower, { description: "Which side traded more: 0 puts, 1 even or no reading, 2 calls." });
string("read", { max_bytes: 48 }); // the headline

// The card: which side traded more leads.
render.hud("volume_card", {
  position: "top_right",
  safe_area: true,
  title: "Options volume, this session",
  columns: 2,
  tiles: [
    tile.pill("Session", "read", { headline: true }),
    tile.value("Calls", "session_calls", { format: "si" }),
    tile.value("Puts", "session_puts", { format: "si" }),
    tile.value("Put/call", "put_call", { format: "0.00" }),
    tile.value("Bullish share", "bull_share", { format: "%" }),
    tile.rows([["Bars with no options data", "missing_bars", "int"]]),
  ],
});

let bySide = true; // setting, read in onStart()
let day: f64 = NaN; // the trade date the card's sums run over
let calls = 0.0; // the session's sums
let puts = 0.0;
let bull = 0.0;
let bear = 0.0;
let rows = 0; // bars of this session that carried a flow row
let missing = 0; // regular-session bars of this session without one
let runRows = 0; // flow rows over the whole run

function onStart(): void {
  bySide = p_split() == 0.0;
}

function writeRead(): void {
  sb_clear();
  if (runRows == 0) sb_text("No options flow on this chart yet");
  else if (rows == 0) sb_text("No options flow yet this session");
  else if (calls > puts) sb_text("More calls than puts");
  else if (puts > calls) sb_text("More puts than calls");
  else sb_text("Calls and puts even");
  str_read_sb();
}

// onBar() runs once per bar: a new trade date starts the card's sums again; the bar's row draws its column in the
// split the setting picks and adds to the sums, or counts as missing on a regular-session bar.
function onBar(): void {
  const date = in_trade_date();
  if (!isNaN(date) && date != day) {
    day = date;
    calls = 0.0;
    puts = 0.0;
    bull = 0.0;
    bear = 0.0;
    rows = 0;
    missing = 0;
  }
  const callAsk = in_call_ask();
  const callBid = in_call_bid();
  const callOther = in_call_mid() + in_call_none();
  const putAsk = in_put_ask();
  const putBid = in_put_bid();
  const putOther = in_put_mid() + in_put_none();
  const served = !isNaN(callAsk) && !isNaN(callBid) && !isNaN(callOther) && !isNaN(putAsk) && !isNaN(putBid) && !isNaN(putOther);
  if (served) {
    calls += callAsk + callBid + callOther;
    puts += putAsk + putBid + putOther;
    bull += callAsk + putBid;
    bear += putAsk + callBid;
    rows += 1;
    runRows += 1;
  } else if (in_session() == 1.0) missing += 1;
  const side = served && bySide;
  const sentiment = served && !bySide;
  out_calls_ask(side ? callAsk : NaN);
  out_calls_bid(side ? callBid : NaN);
  out_calls_other(side ? callOther : NaN);
  out_puts_ask(side ? -putAsk : NaN);
  out_puts_bid(side ? -putBid : NaN);
  out_puts_other(side ? -putOther : NaN);
  const neutral = callOther + putOther;
  out_bullish(sentiment ? callAsk + putBid : NaN);
  out_neutral_up(sentiment ? neutral * 0.5 : NaN);
  out_neutral_down(sentiment ? -neutral * 0.5 : NaN);
  out_bearish(sentiment ? -(putAsk + callBid) : NaN);
  const reading = rows > 0;
  out_session_calls(reading ? calls : NaN);
  out_session_puts(reading ? puts : NaN);
  out_put_call(reading && calls > 0.0 ? puts / calls : NaN);
  out_bull_share(reading && bull + bear > 0.0 ? (100.0 * bull) / (bull + bear) : NaN);
  out_missing_bars(f64(missing));
  out_tone(reading ? (calls > puts ? 2.0 : puts > calls ? 0.0 : 1.0) : 1.0);
  if (bar.isLast()) writeRead();
}

How it works

The four sides. Each options_flow row splits its contracts by the quote at the print: at the ask, at the bid, at the mid, and with no quote to side it, for calls and for puts. The package reads the eight fields and adds the mid and the no-quote contracts into one muted segment, since neither carries a side. On crypto and CME every print carries the taker's side, so the mid and no-quote contracts read 0 there and the muted segment stays empty.

Two splits, one stack. All ten columns share the stack contracts, so the chart piles each bar's positive columns above zero and its negative ones below, in the order they are declared. By side writes the six side columns (the puts negated) and leaves the four sentiment columns NaN; Bullish and bearish does the opposite, so a column never draws in the split you did not pick. Each stack adds up to the bar's own totals: the calls' three segments to call_contracts_total and the puts' to put_contracts_total.

The session's numbers. The card sums each session from its first bar (time.trade_date starts it again): the calls, the puts, their ratio (puts over calls) and the bullish share, bullish over bullish plus bearish contracts, the sided prints only. Its headline says which side traded more.

What the settings do

  • Split: By side splits columns by ask, bid and no side, and Bullish and bearish sorts trades by their bet.
  • Session: Says whether more calls or more puts traded this session.
  • Calls: Call contracts traded this session.
  • Puts: Put contracts traded this session.
  • Put/call: The put/call ratio, put contracts per call contract, where above 1 more puts traded.
  • Bullish share: Bullish contracts as a percent of all trades with a clear side, where above 50 bulls lead.
  • Bars with no options data: Regular-session bars this session without data, so above 0 read the numbers as at least what they show.

Where it runs

It works on three kinds of charts. On a coin with listed options, it reads that coin's own options on its exchange. 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 it. The same goes for the charts of that stock's option contracts. On a CME futures chart, every indicator in your browser can read it too, once you accept the CME market data terms (Limitations). US options data runs 15 minutes behind unless you have real-time US options data. CME data runs 10 minutes behind unless you have real-time CME data. The legend shows which delay you get. It shows the last 7 days on 1-minute charts and the last 30 days on 5-minute charts. Older bars draw no column.

When data is missing

A bar with no options data draws no column at all, never a zero. On crypto and CME, a bar with no trades inside the stored history reads as zeros instead. That bar draws no column and does not count as a gap. The card's headline reads "No options flow on this chart yet" while no bar has options data. It reads "No options flow yet this session" while the newest session has none. Bars with no options data counts this session's regular-session bars without data. Above 0, read the session's numbers as at least what they show.

Customize it

  • Premium instead of contracts. Read the _prem_ fields (call_prem_ask, ...) in place of the _contracts_ ones and format the columns as usd.
  • One expiry bucket. Add dte: "0dte" or dte: "week" to the eight inputs to stack only those contracts; the knob is one read for all eight.
  • Out of the money. Add moneyness: "otm" to the inputs to count the out-of-the-money contracts alone.

Run it

  1. In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Options Volume under Order flow.
  2. Press Run on a BTC chart or a US stock chart: the columns draw under the chart and the card at the top right. On a US stock or a CME future the copy reads the flow at your own tier, and the legend names the tier. On a CME future, accept the CME market data terms first.
  3. At the editor's Console prompt, type put_call and bull_share to read the session on the live bar, or last 20 calls_ask for the calls bought at the ask on the last 20 bars.

Concepts used