API Quick Reference
Single-page cheat sheet. Every function, input type, plot type, and color constant at a glance.
Data Access
this.open this.high this.low this.close this.volume
this.get(series, barsAgo) // series: 'open'|'high'|'low'|'close'|'volume'
this.getPlot(plotName, barsAgo) // access previously plotted valuesBar Info
this.bar // 0-based index
this.isFirstBar // bar === 0
this.isLastBar // most recent bar
this.barCount // total barsState
this.setState(key, value)
this.getState(key, defaultValue?)Moving Averages
this.sma(source, period) // Simple
this.ema(source, period) // Exponential
this.wma(source, period) // Weighted
this.rma(source, period) // Running/Wilder's
this.smma(source, period) // Smoothed (= rma)
this.dema(source, period) // Double EMA
this.tema(source, period) // Triple EMA
this.hma(source, period) // Hull MA
this.vwma(source, period) // Volume-Weighted
this.linreg(source, period) // Linear RegressionCompound Indicators
this.macd(source, fast, slow, signal) → { macd, signal, histogram }
this.bbands(source, period, mult) → { upper, middle, lower }
this.stoch(kPeriod, kSmooth, dSmooth) → { k, d }
this.supertrend(period, factor) → { value, direction }Single-Value Indicators
this.rsi(source, period) // 0-100
this.atr(period) // uses H/L/C
this.cci(source, period) // CCI
this.adx(period) // 0-100 trend strength
this.mfi(period) // 0-100 volume-weighted RSI
this.obv() // cumulative volume
this.stdev(source, period) // standard deviationRange & Volatility
this.highest(source, period)
this.lowest(source, period)
this.sum(source, period)
this.trueRange() // max(H-L, |H-prevC|, |L-prevC|)
this.change(source, length?) // current - N bars ago
this.roc(source, period) // % rate of change
this.percentRank(source, period) // 0-100 percentileUtility
this.crossOver(currA, currB, prevA, prevB) // 4 args!
this.crossUnder(currA, currB, prevA, prevB) // 4 args!
this.barsSince(condition) // bars since true (-1 if never)
this.valuewhen(condition, source) // value when last true
this.rising(source, length) // rising N bars?
this.falling(source, length) // falling N bars?Math
this.abs(v) this.max(a,b) this.min(a,b) this.round(v, decimals?)
this.log(...args) // prints on last bar onlyInputs
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?: string[] })Plot Functions
plot(name, value, { color?, width?, style?, overlay? })
plotHistogram(name, value, { color?, baseValue? })
plotColor(name, value, colors[], colorIndex, { width? })
hline(name, level, { color?, style? })
plotShape(name, condition, { shape?, location?, color?, size?, text? })
plotArrow(name, condition, { direction?, color?, size? })
plotArea(plot1Name, plot2Name, { colorAbove?, colorBelow? })
bgcolor(color, { opacity? })
barcolor(color)Shape Options
shape: 'triangleup' | 'triangledown' | 'circle' | 'cross' | 'diamond'
location: 'abovebar' | 'belowbar' | 'top' | 'bottom'
size: 'tiny' | 'small' | 'normal' | 'large'
style: 'solid' | 'dashed' | 'dotted'Colors
color.red #ef4444 color.green #22c55e color.blue #3b82f6
color.yellow #eab308 color.orange #f97316 color.purple #a855f7
color.cyan #06b6d4 color.magenta #ec4899 color.lime #84cc16
color.pink #f472b6 color.teal #14b8a6 color.gray #6b7280
color.silver #9ca3af color.gold #d97706 color.navy #1e3a5f
color.maroon #7f1d1d color.aqua #67e8f9 color.olive #65a30d
color.white #ffffff color.black #000000Or any hex string: '#ff6600'
Strategy (extends Strategy)
this.position.isLong / isShort / isFlat / size / entryPrice
this.strategy.entry(signal, 'long'|'short', { qty? })
this.strategy.exit(signal, fromDirection?)
this.strategy.close(comment?)Minimal Template
typescript
import { Script, input, plot, color } from '@chartlabs/script-sdk';
export default class MyIndicator extends Script {
length = input.number('Period', 14, { min: 1, max: 200 });
calculate() {
const val = this.sma('close', this.length);
plot('Value', val, { color: color.blue, width: 2 });
}
}
