1) Execution Model

v1
  • Execution was line-by-line and evaluated expressions directly.
  • Developers had to manually assemble time-aligned series using:
    • buildTimeseries(...)
    • mergeTimeseries(...)
    • matchTimestamp(...)
    • timeseries(...) constructor
  • This was unintuitive and often led to performance bottlenecks when misunderstood.
v2
  • Introduces per-bar execution model, similar to Pine Script.
  • Script phases:
    1. Initialization → definitions, inputs, data subscriptions
    2. Calculation → runs once per bar
    3. Plotting → render output
  • No need for manual alignment; the engine handles timeseries iteration automatically.

2) Keyword Arguments (kwargs)

v1
  • Functions accepted only positional arguments.
  • Harder to read and maintain scripts.
v2
  • All functions now support keyword arguments (kwargs).
  • More readable and order-independent.

3) Compiler Improvements

v1
  • Most errors surfaced only at runtime.
  • Developers had to debug by trial and error.
v2
  • Strong compile-time analysis.
  • Detects syntax errors, scope violations, and type mismatches before execution.
  • Safer and faster iteration for script developers.

4) Data Subscriptions

v1
  • All data sources handled via the generic source(...).
v2
  • Dedicated functions for specific data types:
    • ohlcv(symbol, exchange)
    • trades(symbol, exchange)
    • orderbook(symbol, exchange)
  • Improves readability and ensures correct schema handling.

5) Technical Indicator Functions

v1
  • Functions like rsi, ema returned a full timeseries.
  • Developers often misunderstood how to work with them, leading to redundant or incorrect code.
v2
  • Each technical function returns a scalar value per bar.
  • Much simpler to use directly in expressions and plots.

6) Field Accessors

v1
  • Accessing fields from data was clunky and inconsistent.
v2
  • Clean accessors for multi-field series like OHLCV.
  • Example: ohlcvTs.close, ohlcvTs.open, ohlcvTs.high, ohlcvTs.low, ohlcvTs.volume.

7) Reverse Index Access

v1
  • Forward-style indexing only (oldest first).
  • Hard to get the latest values directly.
v2
  • Reverse indexing: ts[0] → latest bar, ts[1] → one bar before last, etc.

8) Function Definitions

v1
  • No support for custom functions.
v2
  • User-defined functions via func.
  • Enables modular, reusable code.

9) Loops

v1
  • No support for looping constructs.
v2
  • Full support for for and while loops (restricted to var variables).

10) Plot Functions

v1
  • Limited plotting functions (plotLine, plotBar).
v2
  • Extended plotting options:
    • plotLine(...)
    • plotBar(...)
    • plotCandle(...)
    • plotShape(...)
  • All support kwargs and flexible styling.

11) Standard Library

v1
  • Minimal helper set.
v2
  • Extended standard library with math, indicators, and utility helpers:
    • Indicators: rsi, ema, sma, stoch, ma, …
    • Helpers: abs, round, max, min, …
    • Debugging: print, printTimeSeries

Summary

kScript v2 delivers major improvements over v1:

  • Per-bar execution eliminates manual time alignment.
  • Keyword arguments make functions clear and self-documenting.
  • Compile-time checking prevents most runtime surprises.
  • Dedicated subscription functions improve clarity.
  • Technical indicators return scalars per bar instead of entire timeseries.
  • Field accessors make OHLCV data ergonomic.
  • Reverse indexing gives direct access to the latest data.
  • Functions and loops enable modular and expressive code.
  • Extended plot functions and library unlock richer visualization and analysis.

Overall, v2 is more intuitive, safer, and expressive — while maintaining performance for real-time charting.

📖
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