Skip to content

map() - Pine Script Function

map() performs a linear interpolation that translates value expressed in the [from_min, from_max] range into a number that lies proportionally inside [to_min, to_max]. It is widely used to normalize indicators, convert booleans into numeric levels, or scale price moves to oscillator bounds.

map(value, from_min, from_max, to_min, to_max) → series float
NameTypeDescription
valueseries int/floatThe value to convert.
from_minseries int/floatLower bound of the input range.
from_maxseries int/floatUpper bound of the input range. Must differ from from_min.
to_minseries int/floatLower bound of the target range.
to_maxseries int/floatUpper bound of the target range.

series float — The proportional value within [to_min, to_max].

  • When from_max == from_min, the function returns na (division by zero).
  • If value falls outside the source range, the result can extrapolate beyond [to_min, to_max]. Clamp manually when you need strict bounds.
  • Combine with math.min/math.max to enforce bounds after the mapping.
//@version=5
indicator("map() oscillator scaling", overlay=false)
rsiLen = input.int(21, "RSI length")
rsiValue = ta.rsi(close, rsiLen)
normalized = map(rsiValue, 0, 100, -1, 1)
plot(normalized, "Mapped RSI", color=color.teal)
hline(0.0, "Midline", color=color.gray)
bgcolor(math.abs(normalized) > 0.5 ? color.new(color.orange, 85) : na)