Net flow
Two lines under the chart sum the premium (money paid for options) in this symbol's options each session.
The up-colour line is calls (bets on a rise) and the down-colour line is puts (bets on a fall). Each line is net: bought at the ask (the seller's price) minus sold at the bid (the buyer's price). Rising calls or falling puts lean bullish, the reverse bearish, and the card at the top right names the leader. Use it to see which way options traders bet today, on crypto, CME (Chicago futures exchange) or US stock charts.
Under the hood: the recipe reads the options_flow net premium and contract fields with missing: "nan". It reads this symbol by default, and scope: "market" behind the Whole market setting (Data sources). It takes the trade date and session from the time source (Data sources). It draws a render.hud card in the chart's default look from data-only readings and two string texts (HUD cards, The default look). It is also the net-flow template, the Net Flow card under Order flow in the editor's starter list, and it compiles as written.
The wrun indicator
// Net Flow: two lines under the chart sum the premium (money paid for options) in this symbol's options each session.
// The up-colour line is calls (bets on a rise) and the down-colour line is puts (bets on a fall). Each line is net:
// bought at the ask (the seller's price) minus sold at the bid (the buyer's price). Rising calls or falling puts lean
// bullish, the reverse bearish, and the card at the top right names the leader. Use it to see which way options traders
// bet today, on crypto, CME (Chicago futures exchange) or US stock charts.
//
// Technical notes: the net call premium is the call premium bought at the ask minus the call premium sold at the bid;
// the net put premium is the same on puts. Both run from the session's first bar (each trade date starts again). Prints
// at the mid or with no quote count in neither line (on crypto and CME each print has the taker's side). The Whole
// market setting draws the same two lines over the whole market instead (every US listed underlying, the coin on every
// crypto venue or CME's market: a second read, fetched only while it is on), and Cap each trade counts each print's
// premium up to 2,000,000, so one block cannot swamp a session. The card reads the session: which side the flow leans
// to (bullish: calls bought and puts sold; bearish: puts bought and calls sold), the two sums, their difference and the
// net contracts (coins on crypto), bought at the ask minus sold at the bid, calls minus puts. 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 card counts the regular-session bars that had none: while that count is above 0
// the sums are a floor. Every print takes a side, cross trades and late prints too: the card says so above that count,
// and the lines' and sums' hover too.
section("What it counts");
param.bool("market", false, { label: "Whole market", description: "Draws the whole options market instead: all US options, the coin on every crypto exchange, or all CME options. It loads that extra data only while this is on." });
param.bool("capped", false, { label: "Cap each trade", description: "Counts at most $2,000,000 of premium (money paid for options) per trade, so one huge trade cannot swamp the session." });
input("close", ohlcv.close); // the chart's own candles: the bar grid
input("trade_date", time.trade_date); // the bar's trade date, the New York date on a US stock: the sums start again on each
input("session", time.session); // 1 in the regular session: the bars a missing row is counted on
input("call_net", options_flow.net_call_prem, { missing: "nan", description: "This bar's net call premium (money paid for calls) in dollars: bought at the ask minus sold at the bid." }); // NaN on a bar the class serves no row for
input("put_net", options_flow.net_put_prem, { missing: "nan", description: "This bar's net put premium (money paid for puts) in dollars: bought at the ask minus sold at the bid." });
input("call_net_capped", options_flow.net_call_prem_capped, { missing: "nan", description: "This bar's net call premium with each trade capped at $2,000,000." });
input("put_net_capped", options_flow.net_put_prem_capped, { missing: "nan", description: "This bar's net put premium with each trade capped at $2,000,000." });
input("call_ask", options_flow.call_contracts_ask, { missing: "nan", description: "Call contracts bought at the ask (the seller's price) in this bar." });
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("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." });
// The whole market's rows, the same fields under scope "market": fetched only while Whole market is on.
input("mkt_call_net", options_flow.net_call_prem, { scope: "market", when: "market", missing: "nan", description: "The whole market's net call premium in dollars, on crypto the coin on every exchange." });
input("mkt_put_net", options_flow.net_put_prem, { scope: "market", when: "market", missing: "nan", description: "The whole market's net put premium in dollars, on crypto the coin on every exchange." });
input("mkt_call_net_capped", options_flow.net_call_prem_capped, { scope: "market", when: "market", missing: "nan", description: "The whole market's net call premium, each trade capped at $2,000,000." });
input("mkt_put_net_capped", options_flow.net_put_prem_capped, { scope: "market", when: "market", missing: "nan", description: "The whole market's net put premium, each trade capped at $2,000,000." });
input("mkt_call_ask", options_flow.call_contracts_ask, { scope: "market", when: "market", missing: "nan", description: "The whole market's call contracts bought at the ask." });
input("mkt_call_bid", options_flow.call_contracts_bid, { scope: "market", when: "market", missing: "nan", description: "The whole market's call contracts sold at the bid." });
input("mkt_put_ask", options_flow.put_contracts_ask, { scope: "market", when: "market", missing: "nan", description: "The whole market's put contracts bought at the ask." });
input("mkt_put_bid", options_flow.put_contracts_bid, { scope: "market", when: "market", missing: "nan", description: "The whole market's put contracts sold at the bid." });
market.zone(); // the market's clock: on crypto (zone 0) the whole market is the coin on every venue
output("ncp", line, lower, { color: "theme.up", width: 2, label: "Net call premium", format: "usd", hint: "Includes cross and late trades", description: "Net call premium since the session opened, in dollars: money paid for calls (bets on a rise). Calls bought at the ask lift it, and calls sold at the bid lower it. Empty until the session's first options data." });
output("npp", line, lower, { color: "theme.down", width: 2, label: "Net put premium", format: "usd", hint: "Includes cross and late trades", description: "Net put premium since the session opened, in dollars: money paid for puts (bets on a fall). Puts bought at the ask lift it, and puts sold at the bid lower it." });
output("zero", line, lower, { color: "theme.muted", width: 1, line_style: "dashed", legend: false, description: "The zero line: above it more premium was bought than sold, below it more was sold." }); // keeps zero inside the pane's scale
// The readings, data-only: the card reads them and the Console can too.
output("net_premium", none, lower, { description: "Net call premium minus net put premium this session, in dollars. Above zero the flow leans bullish, below zero bearish. Includes cross and late trades." });
output("net_contracts", none, lower, { description: "Contracts bought at the ask minus sold at the bid this session, calls minus puts, in coins on crypto." });
output("bar_call_net", none, lower, { description: "This bar's net call premium in dollars, empty on a bar with no options data." });
output("bar_put_net", none, lower, { description: "This bar's net put premium in dollars, empty on a bar with no options data." });
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: "The session's lean: 0 bearish, 1 even or no reading, 2 bullish." });
string("read", { max_bytes: 48 }); // the headline: the session's lean, or why there is no reading
string("title", { max_bytes: 48 }); // the card's title: the scope and the cap
// The card: the session's lean leads as the headline, then the two sums, their difference, the net contracts and the
// bars with no flow row, under the line that the sums include cross and late trades.
render.hud("flow_card", {
position: "top_right",
safe_area: true,
title: "{{title}}",
columns: 2,
tiles: [
tile.pill("Session", "read", { headline: true }),
tile.value("Net call premium", "ncp", { format: "usd", hint: "Includes cross and late trades" }),
tile.value("Net put premium", "npp", { format: "usd", hint: "Includes cross and late trades" }),
tile.value("Calls minus puts", "net_premium", { format: "usd", hint: "Includes cross and late trades" }),
tile.value("Net contracts", "net_contracts", { format: "si" }),
tile.rows("Includes cross and late trades", [["Bars with no options data", "missing_bars", "int"]]),
],
});
let wholeMarket = false; // settings, read in onStart()
let capped = false;
let zone = 0; // the market's clock, read in onStart()
let day: f64 = NaN; // the trade date the sums run over
let ncp = 0.0; // the session's sums
let npp = 0.0;
let netContracts = 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 {
wholeMarket = pb_market();
capped = pb_capped();
zone = i32(p_market_zone());
}
// The card's words, on the live bar.
function writeCard(net: f64): 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 (net > 0.0) sb_text("Bullish flow leads");
else if (net < 0.0) sb_text("Bearish flow leads");
else sb_text("Calls and puts even");
str_read_sb();
sb_clear();
sb_text(!wholeMarket ? "Net flow, this symbol" : zone == 0 ? "Net flow, every exchange" : "Net flow, whole market");
if (capped) sb_text(", capped");
str_title_sb();
}
// onBar() runs once per bar: a new trade date starts the sums again; this bar's row, from the scope the settings
// pick, adds to them, or counts as missing on a regular-session bar; then the lines, the readings and, on the live
// bar, the card's words.
function onBar(): void {
const date = in_trade_date();
if (!isNaN(date) && date != day) {
day = date;
ncp = 0.0;
npp = 0.0;
netContracts = 0.0;
rows = 0;
missing = 0;
}
// The market inputs read NaN while Whole market is off: their lane is never fetched.
const callNet = wholeMarket ? (capped ? in_mkt_call_net_capped() : in_mkt_call_net()) : capped ? in_call_net_capped() : in_call_net();
const putNet = wholeMarket ? (capped ? in_mkt_put_net_capped() : in_mkt_put_net()) : capped ? in_put_net_capped() : in_put_net();
const served = !isNaN(callNet) && !isNaN(putNet);
if (served) {
ncp += callNet;
npp += putNet;
rows += 1;
runRows += 1;
const contracts = wholeMarket ? in_mkt_call_ask() - in_mkt_call_bid() - (in_mkt_put_ask() - in_mkt_put_bid()) : in_call_ask() - in_call_bid() - (in_put_ask() - in_put_bid());
if (!isNaN(contracts)) netContracts += contracts;
} else if (in_session() == 1.0) missing += 1;
const reading = rows > 0;
const net = ncp - npp;
out_ncp(reading ? ncp : NaN);
out_npp(reading ? npp : NaN);
out_zero(0.0);
out_net_premium(reading ? net : NaN);
out_net_contracts(reading ? netContracts : NaN);
out_bar_call_net(served ? callNet : NaN);
out_bar_put_net(served ? putNet : NaN);
out_missing_bars(f64(missing));
out_tone(reading ? (net > 0.0 ? 2.0 : net < 0.0 ? 0.0 : 1.0) : 1.0);
if (bar.isLast()) writeCard(net);
}How it works
One row a bar. options_flow serves one row of sums per bar: the premium and the contracts of every print, split by where the print traded against the quote (at the ask, at the bid, at the mid, or with no quote to side it) and by calls and puts. net_call_prem is the call premium at the ask minus the call premium at the bid, and net_put_prem the same on puts, so a print at the mid or with no quote counts in neither. On crypto and CME every print carries the taker's side: bought at the ask or sold at the bid. A bar the class serves no row for reads NaN, because every input declares missing: "nan": the package can tell a bar with no row from a bar whose flow summed to zero.
Sums by session. time.trade_date changes on the first bar of each trade date on the market's clock (the New York date on a US stock, the UTC day on crypto, the CME trade date that opens at 17:00 Chicago), and the sums start again there: the call line is the net call premium since the session's first bar, the put line the net put premium. A bar without a row adds nothing. On a regular-session bar (time.session reads 1) it also counts in missing_bars, and the card prints that count: while it is above 0 the sums are a floor, the flow of those bars being unknown. A pre-market bar without a row counts as nothing.
The lean and the contracts. net_premium is the net call premium minus the net put premium: bullish flow (calls bought, puts sold) above zero and bearish flow (puts bought, calls sold) below. The card leads with it in words, Bullish flow leads or Bearish flow leads. net_contracts is the same idea in contracts (coins on a crypto chain): calls bought at the ask minus sold at the bid, minus the puts'.
The market's lines. Whole market reads the same fields under scope: "market": every US listed underlying at once on a US stock, the chart's coin on every crypto venue on crypto (the card's title then reads "Net flow, every venue"), the exchange's market on CME. Those inputs carry when: "market", so the chart fetches their rows only while the setting is on; off, they read their fill (NaN) and the package draws the chart's own underlying. Cap each trade reads the _capped twins, where each print's premium counts up to 2,000,000.
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 line over the card's count of bars with no flow row, the hover of the two lines and of the card's three premium values, and the description of net_premium.
What the settings do
- Whole market: Draws the whole options market instead: all US options, the coin on every crypto exchange, or all CME options.
- Cap each trade: Counts at most $2,000,000 of premium per trade, so one huge trade cannot swamp the session.
- Session: Names the side that leads this session, bullish when calls are bought or puts sold, bearish the reverse.
- Net call premium: Calls bought at the ask minus calls sold at the bid this session, in dollars.
- Net put premium: Puts bought at the ask minus puts sold at the bid this session, in dollars.
- Calls minus puts: Net call premium minus net put premium, where above zero leans bullish and below zero bearish.
- Net contracts: Net call contracts minus net put contracts this session, in coins on crypto.
- Bars with no options data: Regular-session bars this session without data, so above 0 read the sums 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. On a 1-minute chart, older sessions stay blank. Alerts and Protected indicators (published ones that run on OpenMarket's servers) cannot read it. They say which data they lack.
When data is missing
The card says why instead of going blank. It reads "No options flow on this chart yet" while no bar on the chart has options data. It reads "No options flow yet this session" while the newest session has none. The lines stay empty until that session's first options data. Bars with no options data counts this session's regular-session bars without data. Above 0, read the sums as at least what they show. If the chart cannot load a data source, the legend shows a chip with the reason.
Customize it
- The market's tide. Turn on Whole market to read the whole market (every US listed underlying, or the coin on every crypto venue), the call and put lines then summing its sided premium.
- Blocks capped. Turn on Cap each trade when a single block trade would otherwise decide the session.
- 0DTE only. Add
dte: "0dte"to the inputs to read the contracts expiring on the print's own trade date, ormoneyness: "otm"for the out-of-the-money contracts; each new set of knobs is one more read.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Net Flow under Order flow.
- Press Run on a BTC chart or a US stock chart: the two lines 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.
- At the editor's Console prompt, type
ncp,nppandnet_premiumto read the session's sums on the live bar, ormissing_barsto see how many bars carried no row.
Concepts used
- Data sources for the
options_flowclass, its fields and thescope,dteandmoneynessknobs - Data sources for
time.trade_dateandtime.session - HUD cards and Blocks and tiles for the card, its pill and values
- Limitations for the US options rule