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
7 itemscurrentSymbolstringThe current trading symbol (e.g., 'BTCUSDT')
currentExchangestringThe current exchange being used for trading (e.g., 'BINANCE', 'COINBASE')
currentCoinstringThe current trading coin (e.g., "BTC")
barIndexnumberCurrent 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.
isLastBarbooleanTrue 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.
isLiveUpdatebooleanTrue 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 itemsyellowcolorYellow color (#FFFF00)
orangecolorOrange color (#FFA500)
purplecolorPurple color (#800080)
graycolorGray color (#808080)
blackcolorBlack color (#000000)
whitecolorWhite color (#FFFFFF)
Data Types
3 itemstimeseriesTimeSeriesThis represents time-aligned numerical data. Only timeseries data can be passed into plot().
ShapeTypeShapeTypeDefines the type of shape to render when using plotShape function. Currently supports 'circle' with more shapes potentially available.
staticstaticVariable that gets declared once and its value persists across bar iterations.
Data Sources
18 itemsbinance_treasury_balanceDataSourceValue of asset held by Binance. Updated monthly. Available for BTC, ETH, SOL, USDT & USDC
buy_sell_volumeDataSourceBuy/sell volume from trade data
cme_oiDataSourceOpen Interest for crypto futures contracts on the Chicago Mercantile Exchange, Only available for BTC and ETH
deribit_implied_volatilityDataSourceImplied volatility of ticker on Deribit. Available to only BTC and ETH coins. Returns tenors of 1W, 1M and 3M
deribit_volatility_indexDataSourceMeasure of implied or historical price volatility for a specific asset on Deribit. Limited to ETH and BTC coins. Returns OHLC data
etf_flowDataSourceNet 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
9 functionsFunctions for rendering data on charts
Script Definition
5 functionsFunctions for defining script metadata and input parameters
Color Functions
7 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.
smaMoving AveragesSimple Moving Average calculation
sma(source, period, priceIndex?)emaMoving AveragesExponential Moving Average calculation
ema(source, period, priceIndex?)rsiOscillatorsRelative Strength Index oscillator
rsi(source, period, priceIndex?)plotPlotting & 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?)