Skip to content
Algo Trade Analytics Docs
Pine library page — review pending. This page is preserved for compatibility but is not part of the reviewed search index. Check the official Pine Script v6 reference before relying on its explanation, signature, or example.

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=6
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)