Appearance

Personalize your experience

Mode
Accent Color
Direction
All Docs/QuaScript//
QuaScript logo

QuaScript Documentation

Language guide, engine API, 601 builtins and the preset library · v3.0.0-phase1

Functions

QuaScriptengine result
Loading the engine result…
functions.qs
analysis "Bands" { overlay = true }

/// A band around any average: (mid, upper, lower).
fn band(src: series, len: int = 20, mult: float = 2.0, avg: fn(series, int) -> series = ta.sma) -> (series, series, series) {
    mid = avg(src, len)
    dev = stat.stdev(src, len) * mult
    return (mid, mid + dev, mid - dev)
}

(mid, up, dn) = band(close)
(_, up2, dn2) = band(bar.typical, 50, mult = 2.5, avg = ta.ema)

render.line(mid, "Mid")
pu = render.line(up, "Upper")
pd = render.line(dn, "Lower")
render.band(pu, pd, opacity = 0.1)
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

Parameters and arguments

  • Parameters may declare a kind (src: series, len: int) and a default (len: int = 20).
  • Calls pass arguments by position, by name (mult = 2.5) or both; positional ones come first.
  • Kinds: float int bool color text series id plot, collection kinds (list<float>, map<text, float>, array, grid, table), struct and enum names, and function kinds fn(series, int) -> series.
  • Only series parameters can be indexed with history (src[1]).
  • A function-kind parameter takes the name of a function: a builtin (ta.ema), your own fn or a library function. Lambdas do not exist.

Returning several values

return (a, b, c) returns a tuple; the caller destructures it with (x, y, z) = f(...), using _ for values it does not need. Every return of a function returns the same number of values.

State belongs to the call site

A function is expanded at each call, so every call has its own state:

QuaScriptengine result
Loading the engine result…
call_sites.qs
analysis "Call sites" { overlay = true }

fn smooth(x: series, n: int) -> series { return ta.ema(x, n) }

a = smooth(close, 10)     // its own ema state
b = smooth(close, 30)     // a separate ema state
render.line(a, "Fast")
render.line(b, "Slow")
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

This costs nothing at run time: the result is exactly what you would get by writing the calculation out by hand. Recursion is not allowed (E_RECURSION).

Generics

QuaScriptengine result
Loading the engine result…
generics.qs
analysis "Generics" { overlay = true }

fn pick<T>(a: T, b: T, cond: bool) -> T {
    if cond { return a }
    return b
}

tone = pick(color.emerald.500, color.rose.500, close > open)
render.line(close, "Close", color = tone)
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

A type parameter is bound by the arguments at each call; each distinct binding is compiled separately.

Nested helpers

A function may define helper functions inside its body. They see the variables of the enclosing function as they are when the helper is called.


© 2026 Quatick Technologies. All rights reserved.