Skip to content

Standard Library

OpenPine ships with a standard library implemented in Pine Script itself. These modules are automatically available in every script.

Modules Overview

ModuleDescription
taTechnical analysis — SMA, EMA, RSI, MACD, Bollinger Bands, etc.
mathMathematical functions — abs, round, max, min, pow, log, etc.
strString manipulation — tostring, contains, replace, split, etc.
arrayDynamic array operations — push, pop, get, set, sort, etc.
mapKey-value map operations — put, get, contains, keys, values, etc.
matrix2D matrix operations — get, set, rows, columns, transpose, etc.
colorColor functions — new, r, g, b, from_gradient
inputUser inputs — int, float, bool, string, source, color, timeframe
labelChart label objects — new, set_text, set_xy, delete
lineChart line objects — new, set_xy1, set_xy2, delete
boxChart box objects — new, set_lefttop, set_rightbottom, delete
tableChart table objects — new, cell, merge_cells, delete
strategyStrategy functions — entry, close, exit, order
runtimeRuntime info — error
logLogging — info, warning, error
timeframeTimeframe utilities
syminfoSymbol information
barstateBar state — isfirst, islast, isconfirmed, isrealtime

Technical Analysis (ta)

pine
// Moving Averages
sma20 = ta.sma(close, 20)
ema12 = ta.ema(close, 12)
wma10 = ta.wma(close, 10)
vwma20 = ta.vwma(close, 20)

// Oscillators
rsi = ta.rsi(close, 14)
[macdLine, signalLine, histogram] = ta.macd(close, 12, 26, 9)
[k, d] = ta.stoch(close, high, low, 14)

// Volatility
atr = ta.atr(14)
[middle, upper, lower] = ta.bb(close, 20, 2.0)

// Trend
[diPlus, diMinus, adx] = ta.dmi(14, 14)
supertrend = ta.supertrend(3.0, 10)

// Price Action
highest = ta.highest(high, 20)
lowest = ta.lowest(low, 20)
change = ta.change(close)
crossover = ta.crossover(ema12, sma20)
crossunder = ta.crossunder(ema12, sma20)

Math (math)

pine
rounded = math.round(3.14159, 2)    // 3.14
absolute = math.abs(-42)             // 42
maximum = math.max(open, close)      // Larger of two
power = math.pow(2, 10)             // 1024
squareRoot = math.sqrt(144)         // 12
logarithm = math.log(100)           // Natural log

String (str)

pine
text = str.tostring(close, "#.##")
combined = str.format("{0}: {1}", "Price", close)
hasWord = str.contains("hello world", "world")    // true
upper = str.upper("hello")                         // "HELLO"
replaced = str.replace("foo bar", "foo", "baz")    // "baz bar"
length = str.length("hello")                        // 5

Arrays

pine
var prices = array.new<float>(0)
array.push(prices, close)

size = array.size(prices)
first = array.get(prices, 0)
last = array.get(prices, size - 1)

avg = array.avg(prices)
maxPrice = array.max(prices)
minPrice = array.min(prices)

// Create from values
var levels = array.from(100.0, 110.0, 120.0)

Inputs

pine
length = input.int(14, "Length", minval = 1, maxval = 200)
factor = input.float(2.0, "Factor", step = 0.1)
useEMA = input.bool(true, "Use EMA")
src = input.source(close, "Source")
maColor = input.color(color.blue, "MA Color")
tf = input.timeframe("D", "Timeframe")

Next Steps

  • Integration — run scripts programmatically from Rust
  • C/C++ API — embed OpenPine in C++ applications

Released under the MIT License.