Ranking Tools

Ranking Tools is a library of reusable functions and constants for other scripts.

functions and typesstatistics and matrices

ranking-tools.abx
1library "Ranking Tools"
2
3type Scored:
4symbol: symbol
5score: number
6
7fn top_n(items: list<Scored>, n: int) -> list<Scored>:
8return items.sort_by(item => item.score).keep_last(n)
9
10fn normalize(value: number, low: number, high: number) -> number:
11if high == low:
12return 0
13return clamp((value - low) / (high - low), 0, 1)
14
15fn percentile_band(source: series<number> = close, length: int = 100) -> number:
16return percentile(source, length, percent: 90%) - percentile(source, length, percent: 10%)
What this script says

Ranking Tools is a library of reusable functions and constants for other scripts.

It defines top_n(items, n), which returns list<Scored>, normalize(value, low, high), which returns a number and percentile_band(source, length), which returns a number.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account