Standard Library
OpenPine ships with a standard library implemented in Pine Script itself. These modules are automatically available in every script.
Modules Overview
| Module | Description |
|---|---|
ta | Technical analysis — SMA, EMA, RSI, MACD, Bollinger Bands, etc. |
math | Mathematical functions — abs, round, max, min, pow, log, etc. |
str | String manipulation — tostring, contains, replace, split, etc. |
array | Dynamic array operations — push, pop, get, set, sort, etc. |
map | Key-value map operations — put, get, contains, keys, values, etc. |
matrix | 2D matrix operations — get, set, rows, columns, transpose, etc. |
color | Color functions — new, r, g, b, from_gradient |
input | User inputs — int, float, bool, string, source, color, timeframe |
label | Chart label objects — new, set_text, set_xy, delete |
line | Chart line objects — new, set_xy1, set_xy2, delete |
box | Chart box objects — new, set_lefttop, set_rightbottom, delete |
table | Chart table objects — new, cell, merge_cells, delete |
strategy | Strategy functions — entry, close, exit, order |
runtime | Runtime info — error |
log | Logging — info, warning, error |
timeframe | Timeframe utilities |
syminfo | Symbol information |
barstate | Bar 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 logString (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") // 5Arrays
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