Dark pool prints
Dark pool prints draws a US stock's large off-exchange trades on the chart, a grey diamond at each one's price and time, bigger for more dollars.
An off-exchange trade is one a bank or a private venue reported after it was done, instead of showing it on an exchange first. Prints of $10M or more also get a flag above the candles that reads their dollar amount, with a thin line down to the diamond. Use it on a US stock or ETF to see where large hidden buying or selling happened, and whether the price comes back to those levels.
Under the hood: a celled dark_pool.cells input carries each bar's off-exchange prints of $1M and up, the rule the Tape's Dark pool section applies (Data sources), cut to each bar's 32 largest with overflow: "largest". A plot.marks section in look 4, the diamond, sizes each print by the log law from a size unit bound to a setting (Marks). A plot.flags section raises the bar's biggest prints as chips above the candles, and the chart places at most five in view, the biggest first (Flags). A render.bgcolor wash covers a bar that shows some of its prints but not all of them, through the data-only shown_in_part output, never a bar that shows none (tints). This is also the dark-pool-prints template: the Dark pool prints card under Order flow in the editor's starter list, and it compiles as written.
The wrun indicator
// Dark pool prints: the large trades in this stock that happened away from the exchanges, drawn on the chart where
// and when they printed. A dark pool print is a trade a bank or a private venue reported after it was done, instead of
// showing it on an exchange first. Each grey diamond is one print of $1M or more, at its price and its own time inside
// the bar, and a bigger diamond means more dollars. Prints of $10M or more also get a flag above the candles that reads
// their dollar amount, with a thin line down to the diamond; the chart shows the biggest five flags in view. Use it to
// see where large hidden buying or selling happened, and whether the price comes back to those levels.
//
// These are the prints the Tape's Dark pool section lists: off-exchange trades of $1M and up, late reports left out,
// so the chart and the Tape agree. The chart keeps about 90 days of them, loads at most 15,000 a chart window, newest
// first, and each bar's 32 largest. A bar older than those, a day with more prints than the chart loads, or a bar with
// more than 32 prints reads partial 1. A faint wash covers only a bar that shows some of its prints, not all.
section("Prints");
param.number("min_usd", 1000000, { min: 1000000, max: 1000000000, step: 100000, label: "Smallest print, USD", description: "Prints worth less than this draw no diamond. The chart loads prints from $1M up." });
param.number("flag_usd", 10000000, { min: 1000000, max: 10000000000, step: 1000000, label: "Smallest flag, USD", description: "Prints worth this much or more also get a flag above the candles. The chart shows the biggest five flags in view." });
input("close", ohlcv.close); // the chart's own candles: the grid the prints land on
input("prints", dark_pool.cells, { max_cells: 32, overflow: "largest", description: "This stock's off-exchange prints of $1M and up, as the Tape lists them. It loads each bar's 32 largest, about 90 days back and at most 15,000 a chart window, newest first." }); // [offset_ms, price, size, usd, side, present] per print
// The readings, data-only: the Console reads them. NaN on a bar the chart served no block for.
output("printed", none, overlay, { description: "Prints in this bar at or above the smallest print." });
output("print_usd", none, overlay, { format: "usd", description: "Dollars of this bar's prints at or above the smallest print." });
output("partial", none, overlay, { description: "1 on a bar the chart loaded only in part: older than the 90 days of prints it keeps or than the window's 15,000 newest, a day with more prints than it loads, or a bar with more than its 32 largest." });
output("shown_in_part", none, overlay, { description: "1 on a bar that shows some of its prints but not all of them. The faint wash covers these bars." });
// A grey diamond per print at its price and time, from 5 px at the smallest print to 12 px at 100 times it; a flag for
// each of the bar's four biggest prints at or above the smallest flag.
plot.marks({ name: "prints", slots: 32, look: 4, size: { law: "log", unit: "@min_usd", min_px: 5, max_px: 12 }, x: 1, text: { mode: 0 }, colors: ["theme.muted", "theme.muted"], tooltip: "{{qty:usd}} at {{price}}", label: "Diamonds", color_labels: ["Diamond", "Diamond"] });
plot.flags({ name: "flags", slots: 4, words: ["{{qty:usd}}"], icons: ["none"], max_in_view: 5, size: { law: "log", unit: "@min_usd", min_px: 5, max_px: 12 }, tooltip: "{{qty:usd}} at {{price}}", label: "Size flags", color_labels: ["Fill", "Edge", "Text"] });
render.bgcolor("served_in_part", { where: "shown_in_part", color: "#64748b14", label: "Bars with missing prints" }); // a faint wash over a bar that shows part of its prints, never one that shows none
const PRINT = 6; // f64s per print: [offset_ms, price, size, usd, side, present]
const PRINTS = 32; // the prints a bar loads, and the diamonds' slots
const FLAGS = 4; // the flags' slots
const flags = new StaticArray<i32>(FLAGS); // the bar's biggest prints at or above the smallest flag, as offsets into the block, biggest first
let minUsd = 1000000.0; // settings, read in onStart()
let flagUsd = 10000000.0;
function onStart(): void {
minUsd = p_min_usd();
flagUsd = p_flag_usd();
}
// A print's time inside its bar in whole ms, held to 0..2^30 (the most a mark holds).
function offsetOf(offset: f64): i32 {
return !(offset > 0.0) ? 0 : offset >= 1073741824.0 ? 1073741824 : i32(offset);
}
// Slides the print at offset at into the bar's flags, biggest first; returns the list's new length.
function offer(cells: StaticArray<f64>, at: i32, kept: i32): i32 {
const usd = cells[at + 3];
if (kept == FLAGS && usd <= cells[flags[kept - 1] + 3]) return kept; // smaller than every flag kept
let i = kept < FLAGS ? kept : kept - 1; // the slot that opens: the end, or the smallest kept
for (; i > 0 && cells[flags[i - 1] + 3] < usd; i -= 1) flags[i] = flags[i - 1];
flags[i] = at;
return kept < FLAGS ? kept + 1 : kept;
}
// onBar() runs once per bar: a diamond per print at or above the smallest print, a flag for each of the four biggest
// at or above the smallest flag, and the bar's readings. A tuple whose size is 0 is the chart's marker for a bar served
// in part, never a print.
function onBar(): void {
const n = in_prints_cells();
if (n < 0) { // no block on this bar: before the history the chart serves
out_printed(NaN);
out_print_usd(NaN);
out_partial(NaN);
out_shown_in_part(NaN);
return;
}
const cells = in_prints_view();
let count = 0;
let total = 0.0;
let marked = false; // bit 14 on a tuple: the chart served the bar in part
let kept = 0;
for (let i = 0; i + PRINT - 1 < n; i += PRINT) {
if (isPartial(cells[i + 5])) marked = true;
if (!(cells[i + 2] > 0.0)) continue; // the marker tuple
const usd = cells[i + 3];
if (!(usd >= minUsd) || count >= PRINTS) continue; // under the smallest print
out_prints_mark(count, cells[i + 1], usd, 0, 1, offsetOf(cells[i]));
count += 1;
total += usd;
if (usd >= flagUsd) kept = offer(cells, i, kept);
}
for (let k = 0; k < kept; k += 1) {
const at = flags[k];
out_flags_flag(k, cells[at + 1], cells[at + 3], 0, 1, offsetOf(cells[at]));
}
out_printed(f64(count));
out_print_usd(total);
out_partial(marked ? 1.0 : 0.0); // a bar cut to its 32 largest is one too: its readings count those 32 alone
out_shown_in_part(marked && count > 0 ? 1.0 : 0.0); // the wash: a bar served in part that draws a print, never the marker alone
}What the settings do
- Smallest print, USD: Hides prints worth less than this, from $1M up.
- Smallest flag, USD: Prints worth this much or more also get a flag above the candles. At most five flags show at once, the biggest first.
Where it runs
On a US stock or ETF chart, in your browser: the chart reads the same off-exchange prints its Tape lists, so a diamond and a Dark pool row of the Tape never disagree. The prints are real time if you have real-time US stock trades, and delayed otherwise. Every other chart (a coin, a CME future, an option contract) shows a chip on the legend that names the data the chart does not serve there. Alerts and Protected indicators (published ones that run on OpenMarket's servers) cannot read these prints.
When data is missing
- No data yet. A bar before the window the chart loads has no data. Every reading stays blank, and it draws nothing.
- A quiet bar. A bar with no print at your smallest print draws no diamond. In the Console (the editor's prompt that shows a reading by its name),
printedandprint_usdread 0. - A bar cut to its largest prints. The chart loads each bar's 32 largest prints. A bar that held more draws those 32 and counts only them, and a faint shade covers it, since its readings are not the whole bar. In the Console,
partialandshown_in_partread 1. - A bar older than the loaded prints. The chart keeps about 90 days of off-exchange prints and loads at most 15,000 of them for a chart window, newest first: the three newest trade days whole, then older days while the 15,000 last. A bar on a day the chart did not load arrives as one empty marker, which never counts as a print. It shows no print, so no shade covers it. In the Console,
partialreads 1 andshown_in_partreads 0. A day the 15,000 reached only in part readspartial1 on its bars too, and a bar there that shows some prints gets the faint shade.
Customize it
- Only the biggest. Raise Smallest print to 5,000,000: the diamonds start at $5M, and the size scale starts there too.
- More flags. Lower Smallest flag to 5,000,000: more of each bar's prints get a chip, and the chart still shows the biggest five in view.
Run it
- In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Dark pool prints under Order flow.
- Press Run on a US stock chart such as SPY on 5 minutes: the diamonds sit on the candles and the flags above them.
- At the editor's Console prompt, type
print_usdto read the newest bar's off-exchange dollars.
Concepts used
- Data sources for the
dark_poolcelled class, its tuple and its knobs, and The present mask and partial bars forisPartialand bit 14 - Marks for
plot.marks, the diamond look, the log size law andx: 1 - Flags for
plot.flags, its words, icons andmax_in_view - Plotting for
render.bgcolor