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) | const float | 12.5 | Fixed stop offset or parameter distance |
| math.abs(close - open) | series float | Non-negative 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(float(na)) | float with a missing value | na | Retain missing data unless a specific fallback is justified |