Primitive Data Types

The fundamental data types that form the building blocks of kScript. These are the basic values you'll work with in your trading algorithms.

numberPrimitive

Represents numerical values including integers and floating-point numbers. Used for prices, volumes, calculations, and mathematical operations.

Examples:var price = 45000.50;
var volume = 1000;
stringPrimitive

Text data used for labels, symbols, exchange names, and configuration values. Essential for identifying assets and displaying information.

Examples:var symbol = "BTCUSDT";
var exchange = "BINANCE";
booleanPrimitive

True/false values used for conditional logic, flags, and decision making. Critical for implementing trading conditions and control flow.

Examples:var isUptrend = true;
var showSignals = false;
naSpecial

Represents "not a number" or missing values. When used in plots, those data points won't be rendered, creating gaps in the visualization. Perfect for conditional indicators.

Usage:plotLine(value=(condition ? value : na), width=2, colors=["red"], label=["Conditional"], desc=["Conditional Value"])

Core kScript Types

Essential types specific to kScript's trading-focused architecture. These handle time-series data and market information.

TimeSeriesCore

The fundamental data structure for time-aligned market data. All price data and indicators are TimeSeries. This is how kScript handles historical data with indexing support.

Examples:timeseries ohlcvData = ohlcv(currentSymbol, currentExchange);
timeseries rsiData = rsi(source=ohlcvData.close, period=14);

Key Features:

  • Historical Access: Use ts[0], ts[1], ts[n] for current and past values
  • Multi-field Data: OHLCV exposes .open, .high, .low, .close, .volume
  • Immutable: Values cannot be changed once set
  • Global Scope: Must be declared at the top level

Input & Configuration Types

Types used for user inputs and script configuration. These help create customizable indicators with user-friendly interfaces.

selectInput

Dropdown selection type for input parameters with predefined choices. Used with input() function to create user-friendly dropdown menus for configuration options.

Examples:var plotType = input(name="mode", type="select", options=["Line", "Bar"], defaultValue="Bar", label="Plot Type")
DataSourceInput

String identifiers for different types of market data available in the platform. Used with source() function to specify what data to fetch.

Examples:"ohlcv" - Price and volume data
"funding_rate" - Funding rates
"liquidations" - Liquidation data
PositionConfiguration

Determines where your indicator appears on the chart interface. Used in the define() function to control indicator placement.

Values:"onchart" - Plotted on the main price chart
"offchart" - Plotted in a separate panel below

Visual & Plotting Types

Types specifically for chart visualization and plotting functions. These control the appearance and style of your indicators.

colorVisual

Color values for chart visualization and plotting. Supports hex codes, named colors, and RGB values for styling your indicators.

Examples:var lineColor = "#FF6B35";
var fillColor = "#008080";
var colors = ["red", "green", "blue"];
ShapeTypeVisual

Defines the type of shape to render when using plotShape function for marking signals and annotations on the chart.

Values:"circle" - Round markers for signals

Practical Examples

Real-world examples showing how different data types work together in kScript to create useful trading indicators and visualizations.

Color Arrays for Multi-Line Plots

Use color arrays to style multiple data series with different colors. Essential for creating multi-timeframe or multi-asset indicators.

Conditional Plotting with na

Combine boolean conditions with na to create indicators that only show when specific market conditions are met, reducing visual noise.

Type Conversion & Indexing

How to work with different data types and extract values from TimeSeries.

TimeSeries Indexing

Access specific price components from OHLCV data:

0Timestamp
1Open
2High
3Low
4Close
5Volume

Creating TimeSeries

Extract specific data from multi-dimensional TimeSeries:

Best Practices

Use Descriptive Names

Choose clear variable names that indicate the data type and purpose.

timeseries trade = ohlcv(currentSymbol, currentExchange);
var close = trade.close;
🎯

Use Appropriate Types

Choose the right data type for your use case to ensure type safety.

var showMA = input("showMA", "boolean", true);
📖
Introduction
Overview of kScript language
🔍
Overview
Complete technical documentation
🚀
Quick Start
Get started with kScript basics
📋
Function Reference
Complete API reference guide
📚
Type System
Understanding kScript data types
General FAQ
Frequently asked questions about kScript
Best Practices
Guidelines for writing efficient kScript code
⚠️
Limitations
Known constraints and workarounds
🆕
Updates
v1 vs v2 differences and improvements
🔧
Core Concepts
Variables, data types & data sources
⚙️
Execution Model
Per-bar execution lifecycle and phases
🏷️
Keyword Arguments
Named parameters for clear function calls
🔗
Field Accessors
Dot notation for timeseries field access
🛠️
User-Defined Functions
Create custom reusable functions
🔗
Script Definition
Defining inputs and metadata
TimeSeries Management
Working with time-aligned data
🎯
Utility Functions
Helper functions and calculations
📈
Moving Averages
SMA, EMA and trend-following indicators
📊
Oscillators
RSI, Stochastic and momentum indicators
📈
Trend Indicators
Trend direction and strength analysis
📉
Volume Indicators
Volume-based analysis tools
📦
Orderbook Functions
Market depth analysis tools
🎨
Plotting & Visualization
Chart rendering and styling
🌈
Color Functions
Color manipulation and styling
📊
Data Subscriptions
Subscribe to OHLCV, trades, and orderbook data
🔄
Loops
For loops and while loops for iteration
🧮
Math Functions
Mathematical functions and constants
🏠
Go Home
Return to main landing page