Returns -1 for a negative number, 1 for a positive number and 0 for zero.
math.sign reduces a number to its direction. It is how ta.obv decides whether to add or subtract volume.
Multiply it with a magnitude to keep one and replace the other, for example math.sign(change) * volume.
Syntax
math.sign(number: simple int/float) -> simple float
math.sign(number: input int/float) -> input float
math.sign(number: const int/float) -> const float
math.sign(number: series int/float) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| number | const/ | required | The number to classify. A positive value gives 1, a negative gives -1 and 0 gives 0. |
Returns
const/input/simple/series float: -1, 0 or 1, or na if the input is na.
Remarks
math.sign(na)is na.
Example
//@version=6
indicator("Signed volume")
signed = math.sign(close - open) * volume
plot(signed, "Signed volume", color = signed >= 0 ? color.teal : color.maroon, style = plot.style_columns)See also
Runs on Sidechair