Lipi Reference
Lipi

Keywords

type

Declares an object type of your own: a name, then a braced block with one typed field per line. A field may carry a default value, and at least one field is required. A data type in a field may carry type arguments in angle brackets. Which types accept them is not documented, so no example is offered.

Syntax

                type <type_name> {
	<data_type> <field_name> [= <default_value>]
	...
}
              

Example


          //@lipi=2
indicator("type Example", overlay=true)
// An object type with two typed fields, one with a default
type Swing {
    float price
    int barIndex = 0
}
static Swing lastHigh = Swing.new(high, bar_index)
if high > lastHigh.price {
    lastHigh := Swing.new(high, bar_index)
}
plot(lastHigh.price, title="Highest High So Far", color=color.green)