Script SDK Reference
Complete API reference for @chartlabs/script-sdk.
Script Base Class
OHLCV Data
| Property | Type | Description |
|---|---|---|
this.open | number | Open price of the current bar |
this.high | number | High price |
this.low | number | Low price |
this.close | number | Close price |
this.volume | number | Volume |
Historical Access
this.get(series, barsAgo)-- Get a data series value N bars agothis.getPlot(plotName, barsAgo)-- Get a previously plotted value N bars ago
Bar Metadata
| Property | Description |
|---|---|
this.bar | Current bar index (0-based) |
this.isFirstBar | True if bar === 0 |
this.isLastBar | True if this is the most recent bar |
this.barCount | Total number of bars |
State Storage
this.setState(key, value)-- Store a value that persists across barsthis.getState(key, defaultValue?)-- Retrieve a stored value
Debug
this.log(...args)-- Print to script console (only on last bar)
Built-in Functions
Moving Averages
sma, ema, wma, rma, linreg
Oscillators
rsi
Volatility
atr, stdev
Range
highest, lowest, sum
Crossovers
crossOver, crossUnder
Math
abs, max, min, round
Input Declarations
input.number(label, default, {min?, max?, step?})input.source(label, default?)-- 'close', 'open', 'high', 'low', 'hl2', 'hlc3', 'ohlc4'input.boolean(label, default?)input.color(label, default?)input.string(label, default?, {options?})
Plot Functions
plot(name, value, {color?, width?, style?, overlay?})plotHistogram(name, value, {color?, baseValue?})plotColor(name, value, colors[], colorIndex, {width?, style?})hline(name, level, {color?, width?, style?})
Color Constants
color.red, color.green, color.blue, color.white, color.black, color.yellow, color.orange, color.purple, color.cyan, color.magenta, color.lime, color.pink, color.teal, color.gray, color.silver, color.gold, color.navy, color.maroon, color.aqua, color.olive

