Skip to content

library() - Pine Script Function

Use library() at the top of a script to publish reusable functions, constants, or variables. Library scripts cannot plot or trade; they only expose exports for other scripts to import.

library(title, overlay, dynamic_requests) → void
NameTypeDescription
titleconst stringIdentifier used in import. Must be unique and contain no spaces. Required.
overlayconst boolHistorical flag for compatibility; has no effect in libraries.
dynamic_requestsconst boolAllow the library to use dynamic request.* calls (Pine v5).
  • Functions, variables, or constants must be prefixed with export to be visible to consumers.
  • Library scripts cannot call order or plot functions (no visual output). Use indicators/strategies to display results.
  • Import syntax: import authorid/libraryname/1 (where 1 is the version number).
//@version=5
// @description Utility math library
library("math_utils", overlay=false)
export hypotenuse(float a, float b) => math.sqrt(a * a + b * b)
export double(float x) => x * 2

Usage in another script:

//@version=5
import authorid/math_utils/1 as mu
indicator("Library consumer", overlay=false)
plot(mu.hypotenuse(close, open))