Returns the absolute value of a number: its distance from zero, never negative.
math.abs turns a negative number into its positive counterpart and leaves other numbers alone. An int stays an int, and a float stays a float.
It is the usual way to measure the size of a move regardless of direction, for example math.abs(close - open) for the candle body.
Syntax
math.abs(number: simple int) -> simple int
math.abs(number: input int) -> input int
math.abs(number: const int) -> const int
math.abs(number: series int) -> series int
math.abs(number: simple int/float) -> simple float
math.abs(number: input int/float) -> input float
math.abs(number: const int/float) -> const float
math.abs(number: series int/float) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| number | simple int or input int or const int or series int or simple int/ | required | The number to take the absolute value of. |
Returns
simple int or input int or const int or series int or simple float or input float or const float or series float: the number without its sign; na if the input is na.
Remarks
math.abs(0)is 0.
Example
//@version=6
indicator("Body size")
body = math.abs(close - open)
plot(body, "Body", color = color.purple, style = plot.style_columns)
plot(ta.sma(body, 20), "Average body", color = color.orange)See also
Runs on Sidechair