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

Language basics

Bars and series

A script is executed once per bar. On each execution, open, high, low, close, volume and time hold the values of that bar, and every variable you compute is a series: one value per bar. x[1] is the value of x one bar ago, x[n] n bars ago.

QuaScriptengine result
Loading the engine result…
history.qs
analysis "Momentum" { overlay = false }

change = close - close[10]
render.histogram(change, "10-bar change", color = change >= 0 ? color.teal.500 : color.rose.500)
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)

Before a value exists (the first bars, or x[n] with n larger than the bars seen) it is na, the missing value. Arithmetic with na gives na; comparisons with na are false. Use math.is_na(x) to test for it and math.coalesce(x, 0) to replace it.

Values

KindExamples
number1, 2.5, -0.01, na
booltrue, false, close > open
colorcolor.blue.500, #ff8800, color.translucent(color.red.500, 80)
text"hello", str.format("{:.2f}", close)
collections[1, 2, 3], list.create(float), map.create(text, float) (see Collections)
structs and enumsZone(top = high, bottom = low), Mode.fast (see Structs, enums and traits)

Variables

QuaScriptengine result
Loading the engine result…
variables.qs
analysis "Variables" { overlay = false }

x = close - open          // declares x
x := x * 2                // assigns an existing variable (a typo becomes a compile error)
persist count = 0         // initialised once, keeps its value from bar to bar
count += 1
render.line(count, "Bars seen")
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 plain variable is recomputed on every bar.
  • persist initialises once and carries its value to the next bar: counters, last pivots, lists of zones.
  • live behaves like persist, and additionally keeps its value across the repeated executions of the forming (live) bar; see Execution model.

Operators

OperatorsMeaning
+ - * / %arithmetic (/ and % by zero give na); + also joins text
== != < <= > >=comparisons
and or notlogic
c ? a : bchoice
+= -= *= /=update in place

Control flow

QuaScriptengine result
Loading the engine result…
control.qs
analysis "Control flow" { overlay = false }

avg = ta.sma(close, 50)
trend = 0
if close > avg {
    trend := 1
} else if close < avg {
    trend := -1
}

bucket = match trend {
    case 1 { "up" }
    case -1 { "down" }
    else { "flat" }
}
render.line(trend, "Trend")
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)

Blocks always use braces. match works on numbers, text and enum members; as an expression its arms end with the value. Without else, a match over an enum must cover every member.

Loops

QuaScriptengine result
Loading the engine result…
loops.qs
analysis "Loops" { overlay = true }

// constant lists and ranges (up to 64 items) are unrolled: each copy has its own state
for len in [10, 20, 50] {
    render.line(ta.ema(close, len), str.format("EMA {}", len))
}

// runtime loops: bounds known only while running
acc = 0.0
for i in 0..10 { acc := acc + close[i] }      // 0 .. 9; use 0..=10 to include 10
render.line(acc / 10, "Mean of last 10")

n = 0
while n < 3 { n := n + 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)
  • a..b excludes b, a..=b includes it, step s changes the increment.
  • for x in some_list iterates a list.
  • break and continue work in every loop.
  • A stateful call inside a runtime loop is an error (E_STATE_IN_LOOP): one call site cannot hold a separate state per iteration. Use a constant list or range so the loop is unrolled.
  • Each bar has a loop budget (one million iterations by default) so a runaway loop stops with an error instead of hanging the chart.

Comments

// starts a comment. /// before a function, struct or enum is a doc comment shown by the editor on hover.


© 2026 Quatick Technologies. All rights reserved.