Migration

kScript v1 vs v2 — Key Differences

Major improvements and design changes between kScript v1 and v2. Learn what's new in the latest version.

This document highlights the major improvements and design changes between kScript v1 and kScript v2. The goal of v2 is to make scripting more intuitive, powerful, and performant for indicator developers.

1. Execution Model

  • 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

2. Keyword Arguments (kwargs)

Functions accepted only positional arguments, making scripts harder to read and maintain.

v1 Positional Arguments
plotLine(rsiTs, 3, ["red", "green"])

3. Compiler Improvements

  • Most errors surfaced only at runtime
  • Developers had to debug by trial and error

4. Data Subscriptions

All data sources handled via the generic source(...) function.

5. Technical Indicator Functions

  • Functions like rsi, ema returned a full timeseries
  • Developers often misunderstood how to work with them, leading to redundant or incorrect code

6. Field Accessors

Accessing fields from data was clunky and inconsistent.

7. Reverse Index Access

  • Forward-style indexing only (oldest first)
  • Hard to get the latest values directly

8. Function Definitions

No support for custom functions.

9. Loops

No support for looping constructs.

10. Plot Functions

Limited plotting functions (plotLine, plotBar).

11. Standard Library

Minimal helper set.

Summary

kScript v2 delivers major improvements over v1:

Per-bar execution
Eliminates manual time alignment—the engine advances bar-by-bar for you.
Keyword arguments
Functions read clearly with named parameters instead of brittle positional-only calls.
Compile-time checking
Syntax, scope, and many type issues surface before you run against live data.
Dedicated subscriptions
Use ohlcv(...), trades(...), and orderbook(...) instead of a generic source(...) catch-all.
Scalar indicators
Built-in indicators return values for the current bar—no whole-series juggling for typical plots.
Field accessors
OHLCV fields like ohlcvTs.close are first-class paths instead of ad-hoc structures.
Reverse indexing
series[0] reads the latest bar; older bars use higher indexes—matching how traders think.
Functions and loops
Author reusable helpers with func and constrained for/while loops.
Plots and standard library
Candles, shapes, more kwargs—and a wider math/indicator/debug toolkit out of the box.

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