Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

Language

Objects and enums

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

View as MarkdownOpen in ClaudeOpen in ChatGPT

User-defined types#

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

RunnableSwing tracker
1//@version=62indicator("Swing tracker", overlay = true)3type Swing4 float price5 int bar6var Swing last = Swing.new(high, bar_index)7if high > last.price8 last.price := high9 last.bar := bar_index10plot(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
1enum Mode2 fast = "Fast"3 slow = "Slow"4mode = input.enum(Mode.fast, "Mode")5len = 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.

PreviousFunctions and methodsNext Arrays, matrices and maps

On this page

  • User-defined types
  • Enums
  • How far these go here

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT