Skip to content

OpenPine Extensions

The following features are OpenPine extensions not present in standard TradingView Pine Script v6. They allow OpenPine's standard library and prelude to be written entirely in Pine Script source files.

getter — Zero-Parameter Property Functions

The getter keyword declares a function that cannot have parameters and is called without parentheses, making it look like a variable or property access.

pine
getter size() => 42

// Access as a variable — no parentheses:
value = size           // 42

// Calling with parentheses is an ERROR:
value = size()         // error: function `size` not defined

Getters cannot have parameters:

pine
getter value(int a) => a + 1   // error: getter functions cannot have parameters

Why it exists: In standard TradingView Pine, built-in values like close, open, math.pi, and color.red are exposed as variables by the runtime. OpenPine uses getter to implement these same values in pure Pine source files.

Examples from the Standard Library

pine
// Candlestick data (prelude/candlestick.1.pine)
export getter series float open() => @native.candlestick(1)
export getter series float close() => @native.candlestick(4)
export getter series float volume() => @native.candlestick(5)
export getter series float hl2() => (high + low) / 2

// Constants (stdlib/math.1.pine)
export getter const float pi() => 3.1415926535897932
export getter const float e() => 2.7182818284590452

// Color constants (stdlib/color.1.pine)
export getter const color red() => #F23645
export getter const color blue() => #2962FF

staticmethod — Static Methods on Types

The staticmethod keyword defines a static method associated with a specific object type. Static methods are called on the type itself, not on an instance.

pine
type AB
    int a

staticmethod(AB) int add(int a, int b) => a + b

// Call on the type name:
result = AB.add(20, 5)      // 25

Static methods can only be defined for object types (declared with type):

pine
staticmethod(int) add(int a, int b) => a + b
// error: static methods can only be defined for object types

Examples from the Standard Library

pine
// Factory methods for chart.point (stdlib/chart.1.pine)
export type point
    int index
    int time
    float price

export staticmethod(point) point now(float price = close) =>
    point.new(bar_index, timenow, price)

export staticmethod(point) point from_time(int time, float price) =>
    point.new(na, time, price)

These are called as chart.point.now() and chart.point.from_time(time, price).

operator — Operator Overloading

The operator keyword defines custom behavior for arithmetic operators on user-defined types.

pine
type Vec2
    float x
    float y

Vec2 operator+(Vec2 a, Vec2 b) =>
    Vec2.new(a.x + b.x, a.y + b.y)

Vec2 operator-(Vec2 a, Vec2 b) =>
    Vec2.new(a.x - b.x, a.y - b.y)

Vec2 a = Vec2.new(1, 2)
Vec2 b = Vec2.new(3, 4)
Vec2 c = a + b          // Vec2.new(4, 6)

Supported operators: +, -, *, / (no space between operator and the symbol). Multiple overloads for different operand types are allowed.

Newtype Declarations

OpenPine adds the type Name => underlying_type syntax to create a distinct type backed by an existing type:

pine
type MyInt => int
MyInt a = 10             // accepts the underlying type's values

Newtypes can be layered:

pine
type MyInt => int
type SpecialInt => MyInt
SpecialInt x = 42        // OK

This is used extensively in the standard library to create distinct types for drawing objects, plot styles, and other domain-specific values:

pine
// prelude/draw.1.pine
export type plot_style => int
export type hline => int
export type label => int
export type line => int
export type box => int
export type table => int

void Return Type

Functions that produce no meaningful return value can be declared with void:

pine
void log(string message) =>
    label.new(bar_index, high, message)

Explicit Return Types

OpenPine supports annotating a return type before the function name for stricter type checking:

pine
string greet(string name) => "Hello, " + name
[int, bool] getInfo() => [42, true]

This works with all function forms — regular functions, methods, and multi-line bodies:

pine
float average(float a, float b) =>
    (a + b) / 2.0

method bool isPositive(float self) =>
    self > 0

Generic Functions

OpenPine allows type parameters declared with <...> after the function name:

pine
identity<T>(T value) => value
first<T>(array<T> arr) => array.get(arr, 0)
method abc<T>(T self) => self

Variadic Parameters

OpenPine allows the last parameter to be variadic with ...:

pine
sum(int first, int rest...) => first + rest

The variadic parameter must be the last one in the parameter list.

Next Steps

Released under the MIT License.