Black Friday 30% off Basic and ProBlack Friday −30%Ends in––d––h––m––sSee the deal

Allowed Python

The Python you need to calculate, with Python’s rules where they matter.

Constructs

def, return, if/elif/else, for, while, break, continue, pass, multiple and augmented assignments (a, b = b, a, x += 1), x if c else y, list and dictionary comprehensions, indexes and slices, chained comparisons (0 < x <= 10), and, or, not, in, is None, raise ValueError(…) and simple f-strings.

Built-in functions

abs, all, any, bool, dict, enumerate, float, int, len, list, max, min, pow, print, range, reversed, round, sorted, str, sum, tuple, zip. They can be passed as values, for example sorted(x, key=abs).

Lists and dictionaries have their methods, like append, pop and get: they are in the reference. There are no sets.

Simple classes

They keep together the data of one thing, like a zone or a level. They have only __init__ and normal methods, and all fields are assigned in __init__: a wrong name is a compile error. Objects are passed by reference and == compares identity.

Python
class Zone:
    def __init__(self, top, bottom, start):
        self.top = top
        self.bottom = bottom
        self.start = start
        self.end = None

    def contains(self, price):
        return self.bottom <= price <= self.top

There is no inheritance, no operators or other __ methods, no class variables, decorators, @dataclass, isinstance or type.

Not allowed

lambda, with, try, yield, async, global, nonlocal, del, sets, mutable default values in your functions, other decorators and imports, and names starting with __ (except __init__). The compiler flags them with the line.

As in Python

Where a result would change, Python rules:

Result
TruthinessAn empty list is false, nan is true
Floor division and remainder-7 // 2 is −4, -7 % 2 is 1
roundround(2.5) is 2: ties go to even
Errors1 / 0 is a ZeroDivisionError, an index out of the list an IndexError, always with the line
DictionariesThey keep insertion order
VariablesThe for variable remains after the loop

Where only the way a number is written would change, the browser rules instead:

  • integers and decimals are the same number, and beyond ±2⁵³ integers lose precision;
  • exp, log, pow and trigonometry may differ from Python in the last digit;
  • in texts with emoji, length and indexes count UTF-16 units: len("😀") is 2.

Read-only values

Candles, price levels, news and module constants can’t be modified: changing them is an error. This way no calculation changes the next one. To work on a list, make a copy: list(bars.close) or list(news).