TakeProfit logo CommunityPlatform


Syntactic constructs of Indie

Indie is a subset of Python syntax constructs, namely:

  • supported features in Indie:

    • function definitions (at top level only)
    • basic control statements: if, for, while
    • variable declarations and standard arithmetics
    • basic data types are: int, float, bool, str
    • decorators from the Indie's standard library (like @indicator, @func and others)
    • raise-ing exceptions
    • (NOTE: this is a work in progress) container data types: list, dict, set. Indie requires explicit typing of the contained items
    • ...
  • not (yet) supported in Indie:

    • nested function definitions
    • class definitions
    • lambdas
    • generator expressions
    • try..except construct
    • with..as construct
    • containers list, dict, set cannot contain elements of various types
    • f-strings
    • functions as first class objects (ability to pass function as an argument to another function call). There is an exception here - function ctx.calc_on actually accepts a function as one of it's arguments... But you cannot write your own custom functions that do the same thing.
    • ...

Explicit typing

Indie requires to explicitly declare types of all variables, function parameters and function return values, except for the cases when Indie compiler is able to infer types from the context around. Luckily, in most cases it is able to do so. For example:

a = 25  # No need to declare type of `a`, because it is initialized with an int literal. So type of `a` is int
b = a + 5  # No need to declare type of `b`, it's type is inferred as int too

Another example:

hist_color: Optional[Color] = None  # We have to declare type of `hist_color` here explicitly
                                    # otherwise `hist_color = None` tells compiler nothing about the type of
                                    # `hist_color` variable
if hist[1] < hist[0]:
    hist_color = color.NAVY
else:
    hist_color = color.BLUE

Example of a function signature with typing:

def sma(price: Series, length: int) -> Series:
    # ...

Scopes of variables

In Python, variables declared in if-statements, for-loop blocks, and while-loop blocks are not local variables, and stay in scope outside of the block. Indie, on the other hand, has 'block-level' scoping which is very similar to such languages like C/C++, Java, Go. For example, in Python it's normal to write (but will fail to compile in Indie):

def some_func(cond: bool) -> int:
    if cond:
        res = 42
    else:
        res = 0
    return res

In Indie, variable res will not exist after the if..else statements. Moreover res of the if block is a different variable than the res from the else block. So this example in Indie should be rewritten into:

def some_func(cond: bool) -> int:
    res: int
    if cond:
        res = 42
    else:
        res = 0
    return res

'Magic' constructs

There are a few language constructs in Indie, which behave weird from the point of view of a standard Python. We jokinly call them 'magic' language elements. They are nothing more but a syntactic sugar for stuff and they make writing technical analysis indicators simpler. They are:

Libraries to import from

You may think, 'Indie is a Python-like language... so... I will import numpy, pandas, yfinance, matplotlib, talib and a lot more cool and very helpful stuff into my TakeProfit indicators right now and have some fun!' but... unfortunately you cannot do this. Well, at least right now.

There are number of reasons why. Here are some of them:

  • Those libraries are not compatible with Indie's runtime design and internal data types.
  • Many of those libraries run on CPython, we in TakeProfit cannot use it effectively as our backend runtime. We are looking forward to WebAssembly/machine code to reach higher perfomance. We simply cannot run these libraries' code on those.
  • There are a lot of stuff in those libraries which is not allowed to run on our servers due to our 'sandbox'-related policies.
  • We in TakeProfit are too busy to work on integration of our runtime engine with those libraries at the moment, because there are a lot of stuff yet to do to make Indie a great tool for technical analysis.

So, in other words, the fact that Indie is a Python-like language gives it an additional point of growth here. But this is a very complicated task, and it is hard to give any promises/estimates right now about it.

Now, what you can import into Indie right now, is:

  • Core stuff from the standard library package indie, like indicator, func, ctx_func, Series, etc.
  • Classic tech analysis algorithms from the standard library package indie.algorithm, like sma, ema, highest, lowest, etc.
  • Some bits and pieces of the Python standard core libraries:
    • math.pow
    • math.sqrt
    • math.nan
    • math.isnan
    • statistics.mean
    • statistics.fmean
    • statistics.median

The list of items to be imported will definitely be expanded... Please, be patient.

Python built-ins

Standard Python has many built-ins. Indie has only these: None, NoneType, False, True, abs(), bool(), dict(), float(), int(), len(), list(), min(), max(), range(), round(), str(), sum(), tuple().

Indie code runs in a sandbox

We run Indie code on our servers, that is why for the obvious reasons Indie's runtime is sandboxed. It means that it is very restricted in terms of what is allowed to do with the host system where code is being executed. For example file and socket I/O is not allowed, execution time and memory are limited too.