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,@algorithmand others) raise-ing exceptions- (NOTE: this is a work in progress) container data types:
list,tuple. Indie requires explicit typing of the contained items - some limited (yet) support of classes and OOP
- …
-
not (yet) supported in Indie v3:
- nested function definitions
- lambdas
- generator expressions
try..exceptconstructwith..asconstruct- containers
listandtupleare implemented partially. The other ones e.g.dictandsetare not yet implemented - f-strings
- functions as first class objects (ability to pass function as an argument to another function call). There is an
exception here — function
Context.calc_onactually accepts a function as one of its arguments… But you cannot write your own custom functions that do the same thing - …
Integer precision
In Python, integers have arbitrary precision and can be of any size limited only by available memory. In Indie, integers are 32-bit signed integers (int32), which means they can only hold values in the range from -2,147,483,648 to 2,147,483,647.
int32 range, you can sometimes use float instead, which provides 64-bit double precision and can handle much larger values (though with potential precision loss for very large integers).
Explicit typing
Indie requires you 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:Scopes of variables
In Python, variables declared inif-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 similar to
languages such as C/C++, Java, Go. For example, in Python it’s normal to write (but will fail to compile in Indie):
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:
Assignments of None values
In Indie it is not allowed to assign None value to a variable of any arbitrary type (e.g. basic data types). But it is
allowed to do so with the help of indie.Optional[T] class. Read more about this
here.
Syntactic sugar constructs
There are a few language constructs in Indie, which behave weird from the point of view of a standard Python. They are nothing more but a syntactic sugar for somewhat complicated things thus they make writing technical analysis indicators simpler. They are:Mainfunction which transforms into aMainclass inherited fromindie.MainContext.- Functions decorated with
@algorithm(more info here) which transform into classes inherited fromindie.Algorithm. Algorithm.new()static method (e.g.indie.algorithms.Sma.new()).MutSeries[T].new()static method.- Functions decorated with
@sec_contextdecorator which transform into classes (similar toMain) inherited fromindie.SecContext.
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 performance. We simply cannot run these libraries’ code on those.
- Many components within these libraries are restricted by our server-side security and sandbox-related protocols.
- Our development roadmap is currently prioritized toward core Indie functionality and specialized technical analysis features over external library integration.
- Core stuff from the standard library package
indie, likeindicator,algorithm,sec_context,Series[T], etc. - Classic tech analysis algorithms from the standard library package
indie.algorithms, likeSma,Ema,Highest,Lowest, etc. - Some bits and pieces of the Python standard core libraries:
math.powmath.sqrtmath.nanmath.isnanstatistics.meanstatistics.fmeanstatistics.median
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().