# Objects and enums

> Define your own types with fields, create and change objects, and use enums for a fixed set of options.

## User-defined types

`type` groups related values. Create one with `.new()`, read and change fields with a dot.

```pine
//@version=6
indicator("Swing tracker", overlay = true)
type Swing
    float price
    int bar
var Swing last = Swing.new(high, bar_index)
if high > last.price
    last.price := high
    last.bar := bar_index
plot(last.price, "Highest so far", color = color.teal, style = plot.style_stepline)
```

Fields can have defaults (`float price = na`). Objects are references: assigning one to another variable does not copy it.

## Enums

An enum is a fixed list of named options, useful for a dropdown that cannot be mistyped.

```pine
enum Mode
    fast = "Fast"
    slow = "Slow"
mode = input.enum(Mode.fast, "Mode")
len = mode == Mode.fast ? 10 : 30
```

## How far these go here

User-defined types and enums are supported. Methods on your own types and some object features are marked as in progress upstream in PineTS, so test a type-heavy script in the editor before relying on it. See [Coverage](/docs/coverage).
