HELPER_FUNCTION_DEFINITIONS
, DECORATED_HELPER_FUNCTION_DEFINITIONS
, CLASS_DEFINITIONS
and MAIN_FUNCTION_OR_CLASS_DEFINITION
can go in any order.import
statements. Every import
statement tells Indie runtime to import
(or connect) one or more symbols from libraries. After that these symbols may
be used in the indicator code.
from
form you are allowed to use lists of symbols, for example:
foobar_func()
afterwards, it is unclear which one of the two
imported functions should be called. Such code cannot be run and produces an error.
Same example with a name clash resolved:
pass
is about that) and returns nothing (None
) looks like this:
minimal_helper_func
, it’s just an example.
Here is a more realistic example of a function that calculates a maximum of given two integers:
Main
function and @sec_context
-decorated functions). Read more about typing in the
Data types in Indie chapter.
@algorithm
and @sec_context
. Both of them are
syntactic sugar decorators which help a lot in making indicator code compact and readable.
The @algorithm
decorator is a syntactic sugar for making your own
series processing algorithm like indie.algorithms.Sma
.
@sec_context
decorator is a syntactic sugar for making an extra entry point function (like a secondary Main
) for
additional instrument that indicator may request. This function should be used in combination with a Context.calc_on
function. Read more about it in Request additional instruments.
class
keyword that lets to declare classes,
just like in Python.
For example the Main
entry point could be declared not as a function, but as a class, like this:
__init__
method) could be optionally added too. It is very useful because it is a good place for some
initialization code that must be executed only once. For example:
@sec_context
decorator on a func) in a similar way,
for example:
@algorithm
decorator on a func) can be declared as classes too, for example:
Main
entry point of the whole indicator is mandatory. It is called every time the indicator receives a candle data
update and it should return an indicator result for that piece of data. It must have at least one parameter self
which
is a reference to object of Main
class (inherited from MainContext
type).
Function or class Main
must also be decorated with a @indicator
decorator. But
also other decorators could be added here, for example:
@plot.line
@plot.fill
, @level
and @band
@param.*
for declaring input parameters of an indicator