Sidechair

array.abs()

Browse the reference

Returns a new array holding the absolute value of every item in a numeric array.

Try it in the editor

Each negative number is flipped to positive; zero and positive numbers are copied unchanged. The source array is not modified.

The result is always an array of floats, even when the input holds integers.

Syntax

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

Arguments

NameTypeDefaultDescription
idarray<int/float> or array<int>requiredThe numeric array to take absolute values from. It is left as it is; the result is a new array.

Returns

  • array<float>: A new array<float> with the absolute values.
  • array<int>: A new array<int> with the absolute value of each item.
  • array<float>: A new array<float> with the absolute values.
  • array<int>: A new array<int> with the absolute value of each item.

Example

Pine ScriptAverage size of recent movesOpen in editor
//@version=6
indicator("array.abs: mean move", overlay = false)
var moves = array.new_float()
array.push(moves, close - close[1])
if array.size(moves) > 10
    array.shift(moves)
plot(array.avg(array.abs(moves)), "Mean absolute move")

See also

Runs on Sidechair