
BTC on 1-hour bars in the 0xArchive Terminal, 2026-10-25.
Open on a chart
Load it on BTC 1h in the terminal, then change its settings or open it in the script editor.
How it works
input.markets holds the basket, editable in the settings, and markets.map((m) => bars({ market: m })) opens a stream per market. On each closed bar ml.pca takes every market’s log return and, over the last Window bars, finds the Components moves they share; the first is usually the whole market rising and falling together. residualZ(0) is what is left of the chart’s own return, over its usual size.
PCA waits until every market in the basket has a full window of bars, so a newly listed market holds the whole basket back until it has the history. Take it out of the basket to start sooner.
The script
basket-residual.ts