Greek flow

View as MarkdownOpen the editor

A line under the chart sums net share delta from this symbol's options trades, bought minus sold, each session.

Share delta is how much stock dealers (the market makers who hedge options) must hold to hedge those trades. Rising delta means bullish bets lead, and falling delta means bearish bets lead. A pane below shows net vega (how much options gain as swings grow): above zero, traders bet on bigger swings. Use it to spot options bets against the price's move, on crypto, CME (Chicago futures exchange) or US stock charts.

Under the hood: the recipe reads four options_flow fields, the share delta and vega at the ask and at the bid (Data sources). Four more sit under moneyness: "otm" behind a setting gate. It draws the vega line in a named pane (Plotting) and puts up a render.label that says why when there is nothing to draw (Plotting). It is also the greek-flow template, the Greek Flow card under Order flow in the editor's starter list, and it compiles as written.

The wrun indicator

// Greek Flow: a line under the chart sums net share delta from this symbol's options trades, bought minus sold, each
// session. Share delta is how much stock dealers (the market makers who hedge options) must hold to hedge those trades.
// Rising delta means bullish bets lead, and falling delta means bearish bets lead. A pane below shows net vega (how
// much options gain as swings grow): above zero, traders bet on bigger swings. Use it to spot options bets against the
// price's move, on crypto, CME (Chicago futures exchange) or US stock charts.
//
// Technical notes: the delta and the vega the options tape traded on the chart's underlying are signed by side and
// summed through the session (each trade date starts again). Each print's share delta is its size times its delta in
// the underlying's units (contracts times 100 shares on a US stock, coins on crypto, futures on CME), calls up and puts
// down; a print bought at the ask counts as it is and one sold at the bid counts against, so the directional delta is
// the share delta bought at the ask minus that sold at the bid: the pressure the tape puts on the underlying, close to
// what the dealers on the other side end up hedging. The directional vega is the vega bought at the ask minus the vega
// sold at the bid, in USD per IV point: above zero the tape is net buying volatility. Prints at the mid or with no
// quote carry no side and count in neither line. The delta line sits under the chart (shares on a US stock, the chart's
// own size unit elsewhere) and the vega line in a pane below it. Out of the money only reads the out-of-the-money
// contracts alone (a second read, fetched only while it is on). 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 adds nothing, and the
// regular-session bars that had none are counted, the sums a floor while that count is above 0.

param.bool("otm", false, { label: "Out of the money only", description: "Reads only out-of-the-money options: calls whose strike (price level) is above the price, puts whose strike is below. It loads that extra data only while this is on." });
input("close", ohlcv.close); // the chart's own candles: the bar grid
input("trade_date", time.trade_date); // the bar's trade date: the sums start again on each
input("session", time.session); // 1 in the regular session: the bars a missing row is counted on
input("delta_ask", options_flow.share_delta_ask, { missing: "nan", description: "Share delta (how many shares dealers hedge) bought at the ask in this bar. Each trade adds its size times its delta, with 100 shares per contract on a US stock." }); // NaN on a bar the class serves no row for
input("delta_bid", options_flow.share_delta_bid, { missing: "nan", description: "Share delta sold at the bid in this bar." });
input("vega_ask", options_flow.vega_ask, { missing: "nan", description: "Vega (how much options gain as swings grow) bought at the ask in this bar, in dollars per volatility point." });
input("vega_bid", options_flow.vega_bid, { missing: "nan", description: "Vega sold at the bid in this bar, in dollars per volatility point." });
input("otm_delta_ask", options_flow.share_delta_ask, { moneyness: "otm", when: "otm", missing: "nan", description: "Share delta bought at the ask, out-of-the-money options only." });
input("otm_delta_bid", options_flow.share_delta_bid, { moneyness: "otm", when: "otm", missing: "nan", description: "Share delta sold at the bid, out-of-the-money options only." });
input("otm_vega_ask", options_flow.vega_ask, { moneyness: "otm", when: "otm", missing: "nan", description: "Vega bought at the ask, out-of-the-money options only." });
input("otm_vega_bid", options_flow.vega_bid, { moneyness: "otm", when: "otm", missing: "nan", description: "Vega sold at the bid, out-of-the-money options only." });
pane("vega", { title: "Vega bought minus sold", height_frac: 0.16, format: "usd" });
output("delta_flow", line, lower, { color: "theme.text", width: 2, label: "Net share delta", format: "si", unit: " sh", visible_by: { size_unit: [2] }, description: "Share delta (how many shares dealers hedge) bought at the ask minus sold at the bid since the session opened. In shares on a US stock chart. Rising means bullish bets lead, falling means bearish bets lead." });
output("delta_units", line, lower, { color: "theme.text", width: 2, label: "Net share delta", format: "si", visible_by: { size_unit: [0, 1, 3] }, description: "The same net share delta on every other chart, in that market's own unit. That is coins on crypto, futures contracts on CME and shares on an option contract's chart." });
output("delta_zero", line, lower, { color: "theme.muted", width: 1, legend: false, description: "The zero line: above it bullish bets lead, below it bearish bets lead." });
output("vega_flow", line, lower, { pane: "vega", color: "theme.text", width: 2, label: "Net vega", format: "usd", description: "Net vega (how much options gain as swings grow) since the session opened, in dollars per volatility point. It is vega bought at the ask minus vega sold at the bid. Above zero traders bet on bigger swings, below zero on calmer ones." });
output("vega_zero", line, lower, { pane: "vega", color: "theme.muted", width: 1, legend: false, description: "The zero line: above it traders bet on bigger swings, below it on calmer ones." });
// The readings, data-only: the Console reads them.
output("delta_bar", none, lower, { description: "This bar's net share delta, empty on a bar with no options data." });
output("vega_bar", none, lower, { description: "This bar's net vega in dollars per volatility point, empty on a bar with no options data." });
output("delta_sided", none, lower, { description: "This bar's share delta at the ask plus at the bid: every trade with a clear side, either way." });
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." });
string("note", { max_bytes: 64 }); // the one line while there is nothing to draw
render.label("note_label", { position: "top_center", text: "note", color: "theme.muted", style: "plain", offset: [0, 8] });

let otm = false; // setting, read in onStart()
let day: f64 = NaN; // the trade date the sums run over
let delta = 0.0; // the session's sums
let vega = 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 {
  otm = pb_otm();
}

// onBar() runs once per bar: a new trade date starts the sums again; this bar's row adds its directional delta and
// vega, or counts as missing on a regular-session bar; then the lines and the readings.
function onBar(): void {
  const date = in_trade_date();
  if (!isNaN(date) && date != day) {
    day = date;
    delta = 0.0;
    vega = 0.0;
    rows = 0;
    missing = 0;
  }
  // The out-of-the-money inputs read NaN while the setting is off: their lane is never fetched.
  const deltaAsk = otm ? in_otm_delta_ask() : in_delta_ask();
  const deltaBid = otm ? in_otm_delta_bid() : in_delta_bid();
  const vegaAsk = otm ? in_otm_vega_ask() : in_vega_ask();
  const vegaBid = otm ? in_otm_vega_bid() : in_vega_bid();
  const served = !isNaN(deltaAsk) && !isNaN(deltaBid) && !isNaN(vegaAsk) && !isNaN(vegaBid);
  if (served) {
    delta += deltaAsk - deltaBid;
    vega += vegaAsk - vegaBid;
    rows += 1;
    runRows += 1;
  } else if (in_session() == 1.0) missing += 1;
  const reading = rows > 0;
  out_delta_flow(reading ? delta : NaN);
  out_delta_units(reading ? delta : NaN); // one of the two shows, by the market's size unit
  out_delta_zero(0.0);
  out_vega_flow(reading ? vega : NaN);
  out_vega_zero(0.0);
  out_delta_bar(served ? deltaAsk - deltaBid : NaN);
  out_vega_bar(served ? vegaAsk - vegaBid : NaN);
  out_delta_sided(served ? deltaAsk + deltaBid : NaN);
  out_missing_bars(f64(missing));
  if (bar.isLast()) str_note(runRows == 0 ? "No options flow on this chart yet" : rows == 0 ? "No options flow yet this session" : ""); // an empty text draws no label
}

How it works

The model sums. Each options_flow row carries share_delta_ask and share_delta_bid, the sum of size times delta over the bar's priced prints at the ask and at the bid, in the underlying's units (shares on a US stock, contracts times 100; coins on crypto; futures contracts on CME), and vega_ask and vega_bid, the vega of the same prints in USD per IV point. A print the data plane could not price has no greeks and adds to neither; n_priced counts the ones it could.

Signed by side. delta_flow adds the bar's share delta at the ask minus at the bid, so call buying and put selling push it up, put buying and call selling down. vega_flow does the same with vega. Prints at the mid or with no quote carry no side and count in neither. delta_sided, a data-only reading, is the bar's share delta at the ask plus at the bid: the sided prints' delta whichever way they traded. On crypto and CME every print carries the taker's side.

One line a market. The delta line is a pair: delta_flow carries the unit sh and shows on a US stock (visible_by: { size_unit: [2] }), and delta_units, the same value without a unit, shows on every other chart, where the delta counts coins on crypto and futures contracts on CME (Size units). The chart mounts the one that fits its market; the Console reads both.

Sums by session. Both lines start again on each trade date (time.trade_date). A bar without a row adds nothing, and a regular-session bar without one counts in missing_bars: while it is above 0 the sums are a floor.

Out of the money. The setting reads the same four fields under moneyness: "otm", the out-of-the-money contracts alone (a strike within 0.5% of the underlying counts as out of the money). Those inputs carry when: "otm", so their rows load only while it is on.

What the settings do

  • Out of the money only: Reads only out-of-the-money options, calls with a strike (price level) above the price and puts below it.

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.

When data is missing

A line with nothing to draw stays empty instead of flat at zero. A session with no options data draws no line. A label at the top says "No options flow on this chart yet" while no bar has options data. It says "No options flow yet this session" while the newest session has none. The Console (the editor's panel that prints values) can also count this session's regular-session bars without data (see Run it).

Customize it

  • Per bar instead of the session. Draw delta_bar as a histogram in place of delta_flow to see each bar's pressure on its own.
  • Dollar delta. Multiply the bar's delta by bar.close() for the notional the tape moved; notional() adds a CME future's point value.
  • One expiry bucket. Add dte: "0dte" to the inputs to follow the same-day contracts, whose delta moves fastest.

Run it

  1. In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Greek Flow under Order flow.
  2. Press Run on a BTC chart or a US stock chart: the delta line draws under the chart and the vega line below it. 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 delta_flow and vega_flow for the session's sums, delta_sided for the last bar's delta on both sides, or missing_bars for this session's regular-session bars without data.

Concepts used