User types
## User types
`type Name` at the top level, then one indented line per field: `<type> <name>` or `<type> <name> = <constant>`.
Field types: int, float, bool, string, color, line, box, label, table, arrays (`array<float>`) and user types
(also the type itself). A field without a default is na (bool: false).
- Create with `Level.new(price, time)` (fields in order) or `Level.new(price = close)` (by name); missing fields
get their defaults. Read with `l.price`, change with `l.price := x` or `l.hits += 1`, also on expressions
(`levels.get(0).price`, `levels.last().hits += 1`). `l.copy()` / `Level.copy(l)` is a shallow copy.
- An object is a handle like an array: `b = l` shares the object, `==` compares handles, `Level l = na` and
`na(l)` mean no object. Reading or writing a field of na stops the script with a runtime error.
- Arrays of objects: `array<Level>` (or `Level[]`), `array.new<Level>()`, `array.from(a, b)`, `for l in levels`.
`array.new<float>(size, initial_value)` also works for builtin element types.
- Lifetime: like arrays, objects only outlive their bar when a `var` variable reaches them (directly, through an
array or through fields). Not allowed: history of an object (`l[1]`; `l.price[1]` works), objects in ta.*
functions or nz, objects in request.security.
```lynt
indicator("Session levels", overlay=true)
type Session
float hi
float lo
var sessions = array.new<Session>()
if session.isfirstbar or sessions.size() == 0
sessions.push(Session.new(high, low))
if sessions.size() > 3
sessions.shift()
cur = sessions.last()
cur.hi := math.max(cur.hi, high)
cur.lo := math.min(cur.lo, low)
prev = sessions.size() > 1 ? sessions.get(-2) : na
plot(na(prev) ? na : prev.hi, "Previous high", color=color.amber, style=plot.style_stepline)
plot(na(prev) ? na : prev.lo, "Previous low", color=color.slate, style=plot.style_stepline)
```