Marks a function, method, type or enum in a library so that scripts importing the library can use it.
A library publishes code for other scripts. Put export before a function, method, type or enum declaration and it becomes part of the library's public face; anything without export stays private to the library. Exported functions need typed parameters. Exported code cannot read variables from the script level of the library; it can call built-in functions and other libraries it imports.
A script uses the library with import. Libraries are written with the library() declaration instead of indicator(), draw nothing and are published before they can be imported. Exported functions may only use arguments and what they declare themselves, never script-level variables.
Remarks
- Document exports with the @function, @param and @returns annotations; they appear in the library's page and in tooltips.
- On Sidechair: libraries are not supported yet. A script that says library() stops with a message asking for an indicator, and export is ignored in a script that is not a library.
Example
//@version=6
indicator("Export-ready", overlay = true)
// In a library, write "export" in front of the function name.
clampedAverage(float src, int len, float lo, float hi) =>
math.min(math.max(ta.sma(src, len), lo), hi)
plot(clampedAverage(close, 20, ta.lowest(close, 50), ta.highest(close, 50)), "Clamped SMA", color.blue, 2)See also
Runs on Sidechair