Notice!
This is documentation for kScript v1.0, which may not include the latest features. For up-to-date documentation, see the latest version.

Basic Data Types

kScript provides several fundamental data types that form the building blocks of your trading algorithms.

numberPrimitive

Represents numerical values including integers and floating-point numbers.

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

Text data used for labels, symbols, and configuration values.

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

True/false values used for conditional logic and flags.

Examples:let isUptrend = true;
let showSignals = false;
colorVisual

Color values for chart visualization and plotting.

Examples:let lineColor = "#FF6B35";
let fillColor = "#008080";
ShapeTypeVisual

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

Values:"circle" - Circular markers
Additional shapes may be available

Complex Data Types

Advanced types for handling time-series data and market information.

TimeSeriesCore

The fundamental data structure for time-aligned market data. All price data and indicators are TimeSeries.

Examples:timeseries ohlcv = source("ohlcv", currentSymbol, currentExchange);
timeseries sma20 = sma(ohlcv, 20, 4);

Structure:

  • Timestamp - Unix timestamp for each data point
  • Values - Array of numerical data (OHLCV)
  • Indexing - Access individual price components
DataSourceInput

Identifiers for different types of market data available in the platform.

Examples:"ohlcv" - Price and volume data
"funding_rate" - Futures funding rates
"liquidations" - Liquidation events
PositionConfiguration

Determines where your indicator appears on the chart interface.

Values:"onchart" - On the main price chart
"offchart" - In a separate panel below

Array Types

kScript supports arrays for handling multiple values of the same type.

Color Arrays

Used for multi-line plots with different colors.

Number Arrays

For storing multiple numerical values or calculations.

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 close_prices = timeseries(ohlcv, 4);

Minimize Type Conversions

Work with native TimeSeries types when possible for better performance.

// Good: Direct TimeSeries operations
timeseries ma = sma(ohlcv, 20, 4);
🎯

Use Appropriate Types

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

// Use boolean for flags
boolean showMA = input("showMA", true);
📖
Introduction
Overview of kScript language
🚀
Quick Start
Get started with kScript basics
📋
Function Reference
Complete API reference guide
🔧
Core Concepts
Variables, data types & data sources
🔗
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
🏠
Go Home
Return to main landing page