Skip to main content
Comprehensive reference for all kScript functions, variables, and data types. Use this page as a quick lookup for available features in kScript.

Variables & Constants

Core Data Variables

Variables automatically available in your script context.
VariableTypeDescription
currentSymbolstringCurrent trading symbol (e.g., “BTCUSDT”)
currentExchangestringCurrent exchange (e.g., “BINANCE”)
currentCoinstringCurrent trading coin (e.g., “BTC”)
barIndexnumberCurrent bar index in the timeseries (starts at 0)
isLastBarbooleanTrue when processing the most recent bar
isLiveUpdatebooleanTrue during live data updates
nanumberRepresents a null/missing value

Color Constants

Pre-defined color values for plotting.
ColorHex Value
red#FF0000
green#008000
blue#0000FF
yellow#FFFF00
orange#FFA500
purple#800080
white#FFFFFF
black#000000
gray#808080
silver#C0C0C0
lime#00FF00
aqua#00FFFF
teal#008080
navy#000080
maroon#800000
olive#808000
fuchsia#FF00FF

Data Types

TypeDescription
timeseriesTime-aligned numerical data for plotting and calculations
varRegular variable for dynamic values per bar
staticPersistent variable that maintains value across bars
ShapeTypeShape type for plotShape() (e.g., “circle”, “triangle”)

Function Categories

Trend-following indicators that smooth price data.
FunctionSignatureDescription
smasma(source, period)Simple Moving Average
emaema(source, period)Exponential Moving Average
wmawma(source, period)Weighted Moving Average
vwmavwma(source, volume, period)Volume Weighted Moving Average
demadema(source, period)Double Exponential Moving Average
tematema(source, period)Triple Exponential Moving Average
hmahma(source, period)Hull Moving Average
Full documentation →
Momentum indicators that fluctuate between bounded values.
FunctionSignatureDescription
rsirsi(source, period)Relative Strength Index
stochstoch(high, low, close, kPeriod, dPeriod, smooth)Stochastic Oscillator
ccicci(source, period)Commodity Channel Index
willrwillr(high, low, close, period)Williams %R
mfimfi(high, low, close, volume, period)Money Flow Index
rocroc(source, period)Rate of Change
Full documentation →
Indicators that help identify trend direction and strength.
FunctionSignatureDescription
macdmacd(source, fastPeriod, slowPeriod, signalPeriod)Moving Average Convergence Divergence
adxadx(high, low, close, period)Average Directional Index
psarpsar(high, low, start, increment, max)Parabolic SAR
supertrendsupertrend(high, low, close, period, multiplier)Supertrend
aroonaroon(high, low, period)Aroon Indicator
Full documentation →
Indicators that incorporate volume data in their calculations.
FunctionSignatureDescription
obvobv(close, volume)On-Balance Volume
vwapvwap(high, low, close, volume)Volume Weighted Average Price
adad(high, low, close, volume)Accumulation/Distribution
cmfcmf(high, low, close, volume, period)Chaikin Money Flow
cvdcvd(buyVolume, sellVolume)Cumulative Volume Delta
Full documentation →
Functions for rendering data on charts.
FunctionDescription
plotLine(value, width, colors, colorIndex, label, desc)Plot a line chart
plotBar(value, width, colors, colorIndex, label, desc)Plot a bar/histogram chart
plotCandle(open, high, low, close, colors, label, desc)Plot candlestick chart
plotShape(value, shape, colors, width, filled, label, desc)Plot shapes at specific points
Full documentation →
Mathematical and statistical functions.
FunctionDescription
abs(x)Absolute value
round(x)Round to nearest integer
floor(x)Round down
ceil(x)Round up
sqrt(x)Square root
pow(base, exp)Power/exponent
log(x)Natural logarithm
log10(x)Base-10 logarithm
exp(x)Exponential (e^x)
min(a, b)Minimum of two values
max(a, b)Maximum of two values
Full documentation →
Helper functions for data manipulation.
FunctionDescription
highest(source, period)Highest value over period
lowest(source, period)Lowest value over period
sum(source, period)Sum over period
change(source, period)Change from n bars ago
crossover(a, b)True when a crosses above b
crossunder(a, b)True when a crosses below b
isNaN(value)Check if value is NaN
nz(value, replacement)Replace NaN with value
Full documentation →
Functions for string manipulation.
FunctionDescription
concat(str1, str2)Concatenate two strings
toUpper(str)Convert to uppercase
toLower(str)Convert to lowercase
toString(value)Convert value to string
Full documentation →
Functions for color manipulation.
FunctionDescription
rgb(r, g, b)Create color from RGB values
rgba(r, g, b, a)Create color with alpha
colorFromHex(hex)Create color from hex string
Full documentation →
Functions for orderbook data analysis.
FunctionDescription
orderbook(symbol, exchange)Subscribe to orderbook data
orderbookImbalance(bids, asks)Calculate bid/ask imbalance
Full documentation →

Data Sources

Core Data Functions

FunctionDescription
ohlcv(symbol, exchange)OHLCV price data
trades(symbol, exchange)Trade data stream
orderbook(symbol, exchange)Orderbook depth data

Market Data Sources

SourceDescription
funding_rateFunding rate from derivatives markets
liquidationsLiquidation data from derivatives markets
buy_sell_volumeBuy/sell volume from trade data
open_interestOpen interest aggregation data

Alternative Data Sources

SourceDescription
etf_flowETF capital flow data
etf_holdingETF asset holdings
etf_premium_rateETF premium/discount vs NAV
cme_oiCME futures open interest
deribit_volatility_indexDeribit volatility index
deribit_implied_volatilityDeribit implied volatility
binance_treasury_balanceBinance treasury holdings
ethena_positionsEthena protocol positions
Full documentation →

Script Definition

define() Parameters

ParameterTypeDescription
titlestringScript title displayed in UI
positionstring”onchart” or “offchart”
axisbooleanShow dedicated price axis
precisionnumberDecimal precision for values

input() Parameters

ParameterTypeDescription
namestringInput variable name
typestring”number”, “string”, “boolean”
defaultValueanyDefault value
labelstringDisplay label in UI
optionsarrayDropdown options (optional)
Full documentation →

Quick Examples

A simple RSI indicator with standard settings:
//@version=2
define(title="RSI", position="offchart", axis=true);

timeseries data = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var rsiValue = rsi(source=data.close, period=14);

plotLine(value=rsiValue, width=2, colors=["blue"], label=["RSI"], desc=["14-period RSI"]);