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.
getter size() => 42
// Access as a variable — no parentheses:
value = size // 42
// Calling with parentheses is an ERROR:
value = size() // error: function `size` not definedGetters cannot have parameters:
getter value(int a) => a + 1 // error: getter functions cannot have parametersWhy 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
// 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() => #2962FFstaticmethod — 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.
type AB
int a
staticmethod(AB) int add(int a, int b) => a + b
// Call on the type name:
result = AB.add(20, 5) // 25Static methods can only be defined for object types (declared with type):
staticmethod(int) add(int a, int b) => a + b
// error: static methods can only be defined for object typesExamples from the Standard Library
// 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.
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:
type MyInt => int
MyInt a = 10 // accepts the underlying type's valuesNewtypes can be layered:
type MyInt => int
type SpecialInt => MyInt
SpecialInt x = 42 // OKThis is used extensively in the standard library to create distinct types for drawing objects, plot styles, and other domain-specific values:
// 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 => intvoid Return Type
Functions that produce no meaningful return value can be declared with void:
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:
string greet(string name) => "Hello, " + name
[int, bool] getInfo() => [42, true]This works with all function forms — regular functions, methods, and multi-line bodies:
float average(float a, float b) =>
(a + b) / 2.0
method bool isPositive(float self) =>
self > 0Generic Functions
OpenPine allows type parameters declared with <...> after the function name:
identity<T>(T value) => value
first<T>(array<T> arr) => array.get(arr, 0)
method abc<T>(T self) => selfVariadic Parameters
OpenPine allows the last parameter to be variadic with ...:
sum(int first, int rest...) => first + restThe variadic parameter must be the last one in the parameter list.
Next Steps
- Language Basics — Pine Script v6 syntax
- Standard Library — built-in functions and modules
- Integration — embed the engine in Rust