Reference
Comprehensive reference for all kScript functions, variables, and data types. Build powerful trading algorithms with our extensive library of technical indicators and utilities.
Variables & Constants
Core variables, data types, and constants available in kScript for market data access and styling.
Core Data Variables
8 itemscurrentSymbol
stringThe current trading symbol (e.g., 'BTCUSDT')
currentExchange
stringThe current exchange being used for trading (e.g., 'BINANCE', 'COINBASE')
currentCoin
stringThe current trading coin (e.g., "BTC")
barIndex
numberCurrent bar index in the timeseries during the per-bar loop. Represents the position in the data array, starting from 0. Useful for indicator warm-up periods and conditional logic based on bar position.
isLastBar
booleanTrue when processing the last bar in the dataset (most recent bar). Useful for one-time calculations, alerts, or actions that should only occur on the most recent data point.
isLiveUpdate
booleanTrue during live data updates with new market data. Distinguishes between initial script run and live trading updates. Note that the script can run multiple times on the same last bar during live updates.
Color Constants
17 itemsyellow
colorYellow color (#FFFF00)
orange
colorOrange color (#FFA500)
purple
colorPurple color (#800080)
gray
colorGray color (#808080)
black
colorBlack color (#000000)
white
colorWhite color (#FFFFFF)
Data Types
3 itemstimeseries
TimeSeriesThis represents time-aligned numerical data. Only timeseries data can be passed into plot().
ShapeType
ShapeTypeDefines the type of shape to render when using plotShape function. Currently supports 'circle' with more shapes potentially available.
static
staticVariable that gets declared once and its value persists across bar iterations.
Data Sources
18 itemsbinance_treasury_balance
DataSourceValue of asset held by Binance. Updated monthly. Available for BTC, ETH, SOL, USDT & USDC
buy_sell_volume
DataSourceBuy/sell volume from trade data
cme_oi
DataSourceOpen Interest for crypto futures contracts on the Chicago Mercantile Exchange, Only available for BTC and ETH
deribit_implied_volatility
DataSourceImplied volatility of ticker on Deribit. Available to only BTC and ETH coins. Returns tenors of 1W, 1M and 3M
deribit_volatility_index
DataSourceMeasure of implied or historical price volatility for a specific asset on Deribit. Limited to ETH and BTC coins. Returns OHLC data
etf_flow
DataSourceNet inflow or outflow of capital into an ETF. Only available on 1D intervals
Function Categories
Explore technical indicators, mathematical functions, and utilities organized by category.
Moving Averages
2 functionsTrend-following indicators that smooth price data
Oscillators
3 functionsMomentum indicators that fluctuate between bounded values
Volume Indicators
2 functionsIndicators that incorporate volume data in their calculations
Trend Indicators
4 functionsIndicators that help identify trend direction and strength
Utility Functions
10 functionsHelper functions for statistical calculations and data manipulation
Plotting & Visualization
5 functionsFunctions for rendering data on charts
Script Definition
5 functionsFunctions for defining script metadata and input parameters
Color Functions
6 functionsFunctions for manipulating and transforming colors
Orderbook Functions
6 functionsFunctions for working with orderbook data
Popular Functions
Commonly used functions for quick access and reference.
sma
Moving AveragesSimple Moving Average calculation
sma(source, period, priceIndex?)
ema
Moving AveragesExponential Moving Average calculation
ema(source, period, priceIndex?)
rsi
OscillatorsRelative Strength Index oscillator
rsi(source, period, priceIndex?)
plot
Plotting & VisualizationUniversal plotting function for all visualization types. The primary way to display your calculated data on charts.
plot(value, plotType?, width?, colors?, colorIndex?, fill?, smooth?, showPriceDisplay?, label?, desc?)