Syntax and behavior of math.abs() in Pine Script v6
The math.abs() function operates on both simple scalars and dynamic series values. It is widely applied in technical indicators to measure divergence width, bar range size, and stop distances where the direction of the price offset is irrelevant.
| Input expression | Returned type | Output value | Practical application |
|---|---|---|---|
| math.abs(-12.5) | simple float | 12.5 | Fixed stop offset or parameter distance |
| math.abs(close - open) | series float | Positive candle body height | Candlestick pattern sizing and filter rules |
| math.abs(close - ta.sma(close, 20)) | series float | Distance from 20 SMA | Mean reversion bands and stretch oscillators |
| math.abs(na) | series float / int | na | Must be guarded with nz() during early chart bars |