Sidechair

array.standardize()

Browse the reference

Returns a new array where each number is expressed as its distance from the mean in standard deviations.

Try it in the editor

Every item becomes (item - mean) / stdev, using the population standard deviation. The result has mean 0 and a spread of 1, so series on different scales can be compared.

na items stay na in the output. If every item is equal the deviation is zero and every result is na.

Syntax

Pine Script
array.standardize(id: array<int/float>) -> array<float>
array.standardize(id: array<int>) -> array<int>
array.standardize() -> array<float>
array.standardize() -> array<int>

Arguments

NameTypeDefaultDescription
idarray<int/float> or array<int>requiredThe numeric array to rescale. na items stay na; the result is a new array.

Returns

  • array<float>: A new array<float> of z-scores.
  • array<int>: A new array holding one z-score per item.
  • array<float>: A new array<float> of z-scores.
  • array<int>: A new array holding one z-score per item.

Example

Pine ScriptZ-score of the latest closeOpen in editor
//@version=6
indicator("array.standardize: z-score", overlay = false)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 30
    array.shift(win)
z = array.standardize(win)
plot(array.last(z), "Latest z-score")
hline(0)

See also

Runs on Sidechair