Skip to content
AlertaChartAlertaScript / docs
AlertaScript / user-type-instances
On this pageSignatureParametersReturnsExample

Utilities / Reference

user-type-instances

Pine v5/v6 user-defined types. `Type.new(...)` takes positional arguments in field-declaration order AND named ones for any field, in the same call — the two forms mix freely, and a field nobody names keeps its declared default. A `method` declared on the type dispatches on the RECEIVER's type, so several types may each declare their own `update` — and the same choice is made when the method is called in its function form, `update(x)`, by the type of its first argument. A method also dispatches on an instance read back out of a collection, directly (`arr.get(i).close()`) or through a variable (`Sess s = ss.get(i)` then `s.reset()`), and on a handle type — `method push_bar(float[] self, …)` is reached as `buf.push_bar(…)` wherever `buf` lives, including a field of another type.

user-type-instances Name <type> field = <default> method name(Name self, …) => <body> Name.new(<positional…>, field = <value>) → instance of the type

Parameters

NameTypeRequiredDefaultDescription
positionalanyNo—Fills fields in declaration order, left to right.
field = valueanyNo—Fills that field by name, in any position. Fields left unset keep their declared default.

Returns

instance of the type

Example

user-type-instances
type Sess    float hi   = 0.0    float lo   = 0.0    bool  live = true method widen(Sess self, float px) =>    self.hi := math.max(self.hi, px)    self.lo := math.min(self.lo, px)    self var array<Sess> all = array.new<Sess>()if bar_index == 0    all.push(Sess.new(high, live = false)) if all.size() > 0    Sess s = all.get(0)    s.widen(close)plot(all.size() > 0 ? all.get(0).hi : na, { title: "Session high" })

Names and aliases

Guides and navigation are localized. Built-in reference descriptions and code examples are maintained in English.

AlertaScript

No results found.

Search by name, alias, or keyword.