ScriptingWriting LipiCustom types and enums

Custom types and enums

A script can declare two kinds of name of its own: an object type, with type, and an enum, with enum. Both are written as a braced block with one entry per line.

Read this page when you have a group of values that belong together, not as a first step.

type

A type declaration gives the type a name and lists its fields. Each field is a data type and a field name. A field may carry a default value, and may leave it out.

type Band {
    float upper = 0.0
    float lower = 0.0
    color shade
}

At least one field is required.

enum

An enum declaration lists its members. A member may carry a title after =. Note what that is: a title, not a value.

enum Trend {
    Up = "Rising"
    Down = "Falling"
    Flat
}

Type arguments

A data type can carry type arguments in angle brackets, separated by commas, in the position where a data type is written.

No example is given here. Which data types take type arguments is not documented, and a guessed example would be worse than none.

What this page states

This page covers how a type and an enum are declared. It does not state how an instance of a custom type is created, or how one of its fields is read or written. That material is not documented, and it is left out rather than guessed at.

A complete script

indicator("Bands", "bands", true)
type Band {
    float upper = 0.0
    float lower = 0.0
}
enum Trend {
    Up = "Rising"
    Down = "Falling"
}
plot(close)
Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade