Skip to content

Script SDK Reference

Complete API reference for @chartlabs/script-sdk.

Script Base Class

OHLCV Data

PropertyTypeDescription
this.opennumberOpen price of the current bar
this.highnumberHigh price
this.lownumberLow price
this.closenumberClose price
this.volumenumberVolume

Historical Access

  • this.get(series, barsAgo) -- Get a data series value N bars ago
  • this.getPlot(plotName, barsAgo) -- Get a previously plotted value N bars ago

Bar Metadata

PropertyDescription
this.barCurrent bar index (0-based)
this.isFirstBarTrue if bar === 0
this.isLastBarTrue if this is the most recent bar
this.barCountTotal number of bars

State Storage

  • this.setState(key, value) -- Store a value that persists across bars
  • this.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

ChartLabs Documentation