Operators

PyneCore supports all Pine Script v6 operators. Since PyneCore scripts are compiled Python, operators behave identically to their Pine Script counterparts.

Arithmetic Operators

OperatorDescriptionExampleResult Type
+Addition / string concata + bint/float/str
-Subtraction / negationa - b or -aint/float
*Multiplicationa * bint/float
/Divisiona / bfloat
%Moduloa % bint/float

When applied to Series values, operators work element-wise on the current bar’s value.

Comparison Operators

OperatorDescriptionExampleResult Type
==Equala == bbool
!=Not equala != bbool
<Less thana < bbool
<=Less than or equala <= bbool
>Greater thana > bbool
>=Greater than or equala >= bbool

Comparison with na always returns na.

Logical Operators

OperatorDescriptionExample
andLogical ANDcond1 and cond2
orLogical ORcond1 or cond2
notLogical NOTnot cond

Assignment Operators

OperatorDescriptionExample
=Assignmenta = 1
:=Reassignmenta := 2
+=Addition assignmenta += 1
-=Subtraction assignmenta -= 1
*=Multiplication assignmenta *= 2
/=Division assignmenta /= 2
%=Modulo assignmenta %= 3

PyneCore note

In Pine Script, = declares a new variable and := reassigns an existing one. In compiled PyneCore code, both map to Python’s = assignment. The PyneComp compiler enforces the declaration/reassignment distinction at compile time.

Special Operators

OperatorDescriptionExample
?:Ternary conditionalcond ? a : b
[]History referenceclose[1]
=>Function body / switchf(x) => x + 1

History reference operator []

The [] operator accesses historical values of a Series. close[1] returns the previous bar’s close price, close[2] the one before that, and so on. close[0] is equivalent to close.

In PyneCore, this compiles to Python’s subscript operator on Series objects.

Ternary operator ?:

Pine Script’s cond ? valueA : valueB compiles to Python’s valueA if cond else valueB.