Appearance
Pair ratio scan
How do you find which pairs of coins have drifted furthest from their usual ratio? Run a z-score on every pair's ratio with request.pairs, then hand the matrix and a per-coin summary to the Screener with report.*.
ameno
indicator("Pair ratio scan")
array<string> m = request.universe(10, exclude_tags = "stablecoin")
int len = input.int(30, "Z-score window", minval = 5)
// Inside request.pairs, close is the row coin's close over the column's
matrix<float> z = request.pairs(m,
(close - ta.sma(close, len)) / ta.stdev(close, len))
report.matrix("ratio z", m, z)
report.column("sum of z", m, cs.row_sum(z))
plot(array.size(m), "Members")Run it from the Screener: choose it in the script picker and press Run. The report shows a row per coin with its summed z-score, and the Matrix section shows every pair. request.pairs and report.* are AmenoScript additions, so the script is AmenoScript and runs leak-safe.
How it works
exclude_tags = "stablecoin"leaves out coins pegged to the dollar. The ratio of two of them barely moves, so its z-score would be noise.request.pairs(m, expr)runsexpron every ordered pair of the ten coins, 90 of them. Row i, column j is coin i over coin j.- The z-score is how many standard deviations the ratio sits from its 30-day mean. A large positive cell says the row coin is rich against the column coin.
- Each pair keeps its own
ta.smaandta.stdev, from the first day both coins have a price. report.matrixhands on the whole matrix, and its history, for the Screener's Matrix section.cs.row_sum(z)sums each row: how rich a coin is against all the others at once.plot(array.size(m))gives the chart something to draw. A script that only writes a report says so on the chart.
Traps
- The matrix is antisymmetric only roughly. The ratio j over i is 1 over i over j, so its z-score is close to, not equal to, minus the other cell.
- A pair is only a close.
high,low,openandvolumeare errors insiderequest.pairs, and so ista.atr.