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

Structs, enums and traits

Structs

QuaScriptengine result
Loading the engine result…
zone.qs
analysis "Zones" { overlay = true }

struct Zone {
    top: float = na
    bottom: float = na
    born: int = 0
    hits: int = 0

    fn width(self) -> float { return self.top - self.bottom }
    fn contains(self, price: float) -> bool { return price <= self.top and price >= self.bottom }
    fn touch(mut self) { self.hits := self.hits + 1 }

    /// A zone of half an ATR around a price (a static factory: no `self`).
    fn around(p: float, atr: float) -> Zone {
        return Zone(top = p + atr / 2, bottom = p - atr / 2, born = bar.index)
    }
}

z = Zone.around(close, ta.atr(14))
if z.contains(high) { z.touch() }
render.line(z.width(), "Width")
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)
  • Fields have a kind and an optional default. Construct with named fields: Zone(top = 1).
  • Methods take self; a method that changes fields takes mut self.
  • A function without self is a static factory: Zone.around(...).
  • Assignment copies all fields: b = a gives an independent copy.
  • Structs are stored as plain series slots, so they cost the same as separate variables.

Inheritance and composition

QuaScriptengine result
Loading the engine result…
inheritance.qs
analysis "Blocks" { overlay = true }

struct Zone {
    top: float = na
    bottom: float = na
    fn width(self) -> float { return self.top - self.bottom }
}
struct OrderBlock extends Zone {
    bullish: bool = true
    fn width(self) -> float { return super.width() * (self.bullish ? 1 : -1) }
}
struct Gap {
    zone: Zone
    filled: bool = false
}

ob = OrderBlock(top = high, bottom = low, bullish = close > open)
g = Gap(zone = Zone(top = high, bottom = low[2]))
render.line(ob.width(), "Signed width")
render.line(g.zone.width(), "Gap width")
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)

extends inherits fields and methods (one parent); super.method() calls the parent's version. A struct field of struct kind composes them.

Lists of structs

QuaScriptengine result
Loading the engine result…
zone_list.qs
analysis "Zone list" { overlay = true }

struct Zone {
    top: float = na
    bottom: float = na
    fn mid(self) -> float { return (self.top + self.bottom) / 2 }
}

persist zones = list.create(Zone)
if bar.index % 50 == 0 { list.push(zones, Zone(top = high, bottom = low)) }
if list.size(zones) > 5 { list.shift(zones) }
newest = list.size(zones) > 0 ? list.last(zones).mid() : na
render.line(newest, "Newest zone mid")
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)

Enums

QuaScriptengine result
Loading the engine result…
enums.qs
analysis "Regimes" { overlay = false }

enum Regime(color: color, weight: float = 1.0) {
    trend(title = "Trending", color = color.emerald.500)
    range(title = "Ranging", color = color.slate.500, weight = 0.5)
    shock(title = "Shock", color = color.rose.500, weight = 0.0)

    fn score(self) -> float { return self.weight * 100 }
    fn classify(h: float) -> Regime { return h > 0.55 ? Regime.trend : Regime.range }
}

mode = param.choice(Regime.trend, title = "Bias")
r = Regime.classify(stat.hurst(close, 100))
render.line(r.score(), "Score", color = r.color)
for m in Regime.members { render.level(m.score(), m.title, color = m.color) }
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)
  • Members may carry fields (declared after the enum name) and a title shown in settings.
  • Enum.members iterates the members; the loop is unrolled, so titles and colors are constants.
  • param.choice(Enum.member) turns an enum into a dropdown setting.
  • Enum.from_text("trend") converts text to a member.

Traits

QuaScriptengine result
Loading the engine result…
traits.qs
analysis "Traits" { overlay = false }

trait Shape { fn area(self) -> float }

struct Box {
    w: float = 0
    h: float = 0
}
impl Shape for Box { fn area(self) -> float { return self.w * self.h } }

fn total<T: Shape>(a: T, b: T) -> float { return a.area() + b.area() }

render.line(total(Box(w = high - low, h = 1), Box(w = 1, h = 2)), "Area")
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 trait lists method signatures; impl Trait for Type provides them. A generic parameter bound by a trait (T: Shape) only allows the trait's methods.


© 2026 Quatick Technologies. All rights reserved.