Ranking Tools
Ranking Tools is a library of reusable functions and constants for other scripts.
functions and typesstatistics and matrices
1
library "Ranking Tools"2
3
type Scored:4
symbol: symbol5
score: number6
7
fn top_n(items: list<Scored>, n: int) -> list<Scored>:8
return items.sort_by(item => item.score).keep_last(n)9
10
fn normalize(value: number, low: number, high: number) -> number:11
if high == low:12
return 013
return clamp((value - low) / (high - low), 0, 1)14
15
fn percentile_band(source: series<number> = close, length: int = 100) -> number:16
return 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.