None
values
Indie is a subset of Python syntax constructs, namely:
supported features in Indie:
if
, for
, while
int
, float
, bool
, str
@indicator
, @algorithm
and others)raise
-ing exceptionslist
, tuple
. Indie requires explicit typing of
the contained itemsnot (yet) supported in Indie v3:
try
..except
constructwith
..as
constructlist
and tuple
are implemented partially. The other ones e.g. dict
and set
are not yet
implementedContext.calc_on
actually accepts a function as one of it's arguments... But you cannot
write your own custom functions that do the same thingIndie 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(self, price: Series[float], length: int) -> Series[float]:
# ...
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
None
valuesIn 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.
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:
Main
function which transforms into a Main
class inherited from indie.MainContext
.@algorithm
(more info here) which transform into classes inherited from indie.Algorithm
.Algorithm.new()
static method (e.g. indie.algorithms.Sma.new()
).MutSeries[T].new()
static method.@sec_context
decorator which transform into classes (similar to Main
) inherited from indie.SecContext
.More information about this in How Indie's syntactic sugar works section
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:
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:
indie
,
like indicator
, algorithm
, sec_context
, Series[T]
, etc.indie.algorithms
,
like Sma
, Ema
, Highest
, Lowest
, etc.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.
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()
.
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.