Basic Data Types
kScript provides several fundamental data types that form the building blocks of your trading algorithms.
numberPrimitiveRepresents numerical values including integers and floating-point numbers.
let price = 45000.50;let volume = 1000;stringPrimitiveText data used for labels, symbols, and configuration values.
let symbol = "BTCUSDT";let exchange = "BINANCE";booleanPrimitiveTrue/false values used for conditional logic and flags.
let isUptrend = true;let showSignals = false;colorVisualColor values for chart visualization and plotting.
let lineColor = "#FF6B35";let fillColor = "#008080";ShapeTypeVisualDefines the type of shape to render when using plotShape function for marking signals and annotations.
"circle" - Circular markersAdditional shapes may be available
Complex Data Types
Advanced types for handling time-series data and market information.
TimeSeriesCoreThe fundamental data structure for time-aligned market data. All price data and indicators are TimeSeries.
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
DataSourceInputIdentifiers for different types of market data available in the platform.
"ohlcv" - Price and volume data"funding_rate" - Futures funding rates"liquidations" - Liquidation events PositionConfigurationDetermines where your indicator appears on the chart interface.
"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:
0Timestamp1Open2High3Low4Close5VolumeCreating 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);