Your own functions
name(a, b) = formula; longer ones indent their lines.
For AI tools: this page as Markdown · the whole language in one file
1spread(src, n) = highest(src, n) - lowest(src, n)2 3plot(spread(close, 20), "Spread")A longer function indents its lines; the last line is the result:
1zscore(src, n) =2 m = sma(src, n)3 (src - m) / stdev(src, n)4 5plot(zscore(close, 20), "Z")6level(2, 0, -2)- Functions can use other functions, but not themselves.
- They take named values like the built-ins:
zscore(n = 50, src = close). - Calling one twice with the same inputs costs nothing extra.
- There are no loops;
loop_scorecovers the common for-loop score, and the window functions (highest,sum,count, ...) cover the rest.
See also: loop_score


