indie
Color.__call__()
Context.calc_on()
Fill.__init__()
IndieError.__init__()
MutSeries.__getitem__()
MutSeries.__len__()
MutSeries.__setitem__()
MutSeries.get()
MutSeries.request_size()
Optional[T].value()
Optional[T].value_or()
Plot.__init__()
PlotDisplayOptions.__init__()
Series.__getitem__()
Series.__len__()
Series.__setitem__()
Series.get()
Series.request_size()
TimeFrame.to_minutes()
mut_series()
series()
tf()
Context.bar_count
Context.bar_index
Context.close
Context.high
Context.hl2
Context.hlc3
Context.info
Context.is_last_bar
Context.is_last_history_bar
Context.is_realtime
Context.low
Context.ohlc4
Context.open
Context.time
Context.time_frame
Context.volume
SymbolInfo.exchange_aliases
SymbolInfo.exchange_code
SymbolInfo.marketdata_timezone
SymbolInfo.price_precision
SymbolInfo.tick_size
SymbolInfo.ticker
format.INHERITED
format.PRICE
format.VOLUME
line_style.DASHED
line_style.DOTTED
line_style.SOLID
plot_style.COLUMNS
plot_style.HISTOGRAM
plot_style.LINE
plot_style.STEPS
source.CLOSE
source.HIGH
source.HL2
source.HLC3
source.LOW
source.OHLC4
source.OPEN
source.VOLUME
indie.algorithm
indie.color
math
statistics
datetime
indie
Main package of indie language.
algorithm
@band()
Color
color
Context
@ctx_func()
@fill()
Fill
format
@func()
@indicator()
IndieError
@level()
line_style
mut_series()
MutSeries
Optional
param
@param_ref()
@plot()
Plot
plot_style
PlotDisplayOptions
Series
series()
source
SymbolInfo
tf()
TimeFrame
Color
type
Data type to represent color.
Context
type
Data type that represents an instrument with OHLCV series values and other related information. A ctx: Context
object is the first required parameter of the main()
function of any indicator.
bar_count
bar_index
calc_on()
close
high
hl2
hlc3
info
is_last_bar
is_last_history_bar
is_realtime
low
ohlc4
open
time
time_frame
volume
Fill
type
Class-container for a fill object.
IndieError
type
Data type for Indie errors.
MutSeries
type
Data type that represents read-write series of numeric values like prices of some instrument.
__getitem__()
__len__()
__setitem__()
get()
request_size()
Optional[T]
type
Builtin Indie type (similar to Python typing.Optional
).
Plot
type
Class-container for a plot object.
PlotDisplayOptions
type
Data type to represent the ways to display plot data.
Series
type
Data type that represents read only series of numeric values like prices of some instrument.
__getitem__()
__len__()
__setitem__()
get()
request_size()
SymbolInfo
type
Data type to represent information about the context's instrument.
exchange_aliases
exchange_code
marketdata_timezone
price_precision
tick_size
ticker
TimeFrame
type
Data type to represent time frame.
Use tf()
to create TimeFrame instances.
format
type
Class-container for indicator values formatting ways.
line_style
type
Class-container for builtin line rendering ways.
param
type
Class-container for decorators for indicator input parameters.
@bool()
@float()
@int()
@source()
@string()
@time_frame()
plot_style
type
Class-container for builtin plot rendering ways.
source
type
Class-container for builtin series got from ctx
used to initialize source input parameter.
CLOSE
HIGH
HL2
HLC3
LOW
OHLC4
OPEN
VOLUME
@band()
decorator
Creates a band (two horizontal lines usually with a semi-transparent fill in between them). Declares common attributes.
@band(
value1: float,
value2: float,
title: indie.Optional[str] = None,
fill_color: indie.Color = indie.color.GREEN(0.05),
line_color: indie.Color = indie.color.GRAY(0.5),
line_style: int = indie.line_style.DASHED,
line_width: int = 1
) -> NoneType
PARAMETERS
value1
— Value of the first horizontal line of a band on a vertical scale of an indicator.
value2
— Value of the second horizontal line of a band on a vertical scale of an indicator.
title
— Human readable title which is visible in the indicator's Settings panel.
fill_color
— Color of the background.
line_color
— Color of the line.
line_style
— Style of the line. It is represented as enum value of type line_style
.
line_width
— Width of the line.
EXAMPLE
@indicator('Band example')
@band(145, 155, line_color=color.RED, line_width=4)
def main(ctx):
return ctx.close[0]
@ctx_func()
decorator
Decorates a function, making it a secondary main()
function for additional instrument of an indicator. Additional instruments are requested with the help of ctx.calc_on()
function and this decorator.
@ctx_func() -> NoneType
from indie import indicator, ctx_func, param
@ctx_func
def main2(ctx):
return ctx.high[0], ctx.low[0]
@indicator('Minimal calc_on example', overlay_main_pane=True)
@param.time_frame('sec_time_frame', default='1D')
def main(ctx, sec_time_frame):
sec_high, sec_low = ctx.calc_on(time_frame=sec_time_frame, ctx_func=main2)
return sec_high[0], sec_low[0]
More info on this topic you can find in Request additional instruments chapter.
@indicator()
Context
Context.calc_on()
@fill()
decorator
Declares attributes of a fill between some two plots of an indicator. Could be applied only to the main()
function of the indicator. Example of an indicator with a single colored fill is Bollinger Bands (BB), of a multicolored fill — Ichimoku Cloud. When applied, it must match with the result of the main()
indicator function.
@fill(
id1: str,
id2: str,
id: indie.Optional[str] = None,
title: indie.Optional[str] = None,
color: indie.Optional[indie.Color] = None
) -> NoneType
PARAMETERS
id1
— Identifier of the first plot to which the fill is applied.
id2
— Identifier of the second plot to which the fill is applied.
id
— Identifier of the fill (auto generated).
title
— Human readable title which is visible in the indicator's Settings panel.
color
— Color of the fill on a chart. This color can be overwritten if the fill is a multicolored one.
EXAMPLE
@plot('one')
@plot('two')
@fill('one', 'two', color=color.GREEN)
def main(ctx):
return ctx.high[0], ctx.low[0], Fill()
More info about fills (for example about multicolored ones) could be found in Fills, levels and bands chapter.
@func()
decorator
Decorates a function, making it a series processor function. Series processor functions are specifically designed to process series of data (it is allowed for them to work with Series
and Context
objects), like close prices of an instrument on a candle chart.
@func() -> NoneType
Most of the functions in the indie.algorithm
package are decorated with @func()
decorator. Read more about it in Series processors chapter.
@indicator()
decorator
Main decorator for an indicator. Should decorate main()
function. Declares common attributes.
@indicator(
abbrev_title: str,
overlay_main_pane: bool = False,
format: int = indie.format.INHERITED,
precision: indie.Optional[int] = None
) -> NoneType
PARAMETERS
abbrev_title
— Abbreviated title of the indicator.
overlay_main_pane
— Whether or not to overlay the indicator over the main pane of the chart. The main pane of a chart is the one with the main instrument on it.
format
— Formatting style of indicator output values represented as enum value of type format
.
precision
— Number of digits after floating point for indicator output values.
@level()
decorator
Creates a level (horizontal line). Declares common attributes.
@level(
value: float,
title: indie.Optional[str] = None,
line_color: indie.Color = indie.color.GRAY(0.5),
line_style: int = indie.line_style.DASHED,
line_width: int = 1
) -> NoneType
PARAMETERS
value
— Value of the level on a vertical scale of an indicator.
title
— Human readable title which is visible in the indicator's Settings panel.
line_color
— Color of the line.
line_style
— Style of the line. It is represented as enum value of type line_style
.
line_width
— Width of the line.
EXAMPLE
@indicator('Level example')
@level(150, line_color=color.RED, line_width=4)
def main(ctx):
return ctx.close[0]
@param.bool()
decorator
Declares a bool input parameter of indicator. Input parameters could be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in main()
function definition.
@bool(
id: str,
default: bool,
title: indie.Optional[str] = None
) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.
default
— Default value for the parameter in settings pane.
title
— Human readable title which is visible in the indicator's Settings panel.
EXAMPLE
@param.bool('is_something_enabled', default=False)
def main(ctx, is_something_enabled):
# Use is_something_enabled variable...
@param.float()
decorator
Declares a float input parameter of indicator. Input parameters could be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in main()
function definition.
@float(
id: str,
default: float,
min: float = -1000000.0,
max: float = 1000000.0,
step: float = 0.1,
title: indie.Optional[str] = None
) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.
default
— Default value for the parameter in settings pane.
min
— Minimum value of the parameter.
max
— Maximum value of the parameter.
step
— Step between values of the parameter.
title
— Human readable title which is visible in the indicator's Settings panel.
EXAMPLE
@param.float('speed_of_light', default=299_792.458)
def main(ctx, speed_of_light):
# Use speed_of_light variable...
@param.int()
decorator
Declares an integer input parameter of indicator. Input parameters could be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in main()
function definition.
@int(
id: str,
default: int,
min: int = -1000000,
max: int = 1000000,
step: int = 1,
title: indie.Optional[str] = None
) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.
default
— Default value for the parameter in settings pane.
min
— Minimum value of the parameter.
max
— Maximum value of the parameter.
step
— Step between values of the parameter.
title
— Human readable title which is visible in the indicator's Settings panel.
EXAMPLE
@param.int('meaning_of_life', default=42)
def main(ctx, meaning_of_life):
# Use meaning_of_life variable...
@param.source()
decorator
Declares a source input parameter of indicator. Input parameters could be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in main()
function definition.
@source(
id: str,
default: int = source.CLOSE,
options: indie.Optional[list[int]] = None,
title: indie.Optional[str] = None
) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.
default
— Default value for the parameter in settings pane.
options
— List of the possible values of the parameter.
title
— Human readable title which is visible in the indicator's Settings panel.
EXAMPLE
@param.source('src', default=source.CLOSE, options=[source.CLOSE, source.HL2, source.HLC3, source.OHLC4])
def main(ctx, src):
# Use src variable...
Even if options
parameter is not used then in Settings panel nevertheless there will be a combobox widget with all possible values from the source
enum.
@param.string()
decorator
Declares a string input parameter of indicator. Input parameters could be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in main()
function definition.
@string(
id: str,
default: str,
options: indie.Optional[list[str]] = None,
title: indie.Optional[str] = None
) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.
default
— Default value for the parameter in settings pane.
options
— List of the possible values of the parameter.
title
— Human readable title which is visible in the indicator's Settings panel.
EXAMPLE
@param.string('name', default='Bart', options=['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie'])
def main(ctx, name):
# Use name variable...
If options
parameter is used then in Settings panel there will be a combobox widget for changing value of this input.
@param.time_frame()
decorator
Declares a time frame input parameter of indicator. Input parameters could be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in main()
function definition.
@time_frame(
id: str,
default: str,
options: indie.Optional[list[str]] = None,
title: indie.Optional[str] = None
) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.
default
— Default value for the parameter in settings pane.
options
— List of the possible values of the parameter.
title
— Human readable title which is visible in the indicator's Settings panel.
EXAMPLE
@param.time_frame('time_frame', default='30m', options=['1m', '30m', '1h', '4h', '1D', '1W', '1M', '1Y'])
def main(ctx, time_frame):
# Use time_frame variable...
The type of time_frame
in the example variable will be TimeFrame
. But please note, that for the convenience, default value has str
type.
If options
parameter is used then in Settings panel there will be a combobox widget for changing value of this input.
@indicator()
param
TimeFrame
tf()
@param_ref()
decorator
Declares an input parameter for @ctx_func
function that is linked to the input parameter of main()
by id
.
@param_ref(id: str) -> NoneType
PARAMETERS
id
— Name of main()
parameter binded to the input parameter.EXAMPLE
@ctx_func
@param_ref('referenced_param')
def sec_main(ctx, referenced_param) -> float:
# Use referenced_param variable...
@indicator('Referenced param example')
@param.int('referenced_param', default=50)
def main(ctx, referenced_param):
calc_on_result = ctx.calc_on(time_frame=tf('1D'), ctx_func=sec_main)
return calc_on_result[0]
@plot()
decorator
Declares attributes of a plot of an indicator. Could be applied only to the main()
function of the indicator. It is optional, so may be omitted in some simple use cases and plot will be rendered using defaults. When applied, it must match with the result of the main()
indicator function.
@plot(
id: indie.Optional[str] = None,
title: indie.Optional[str] = None,
color: indie.Optional[indie.Color] = None,
style: int = indie.plot_style.LINE,
line_style: indie.Optional[int] = None,
line_width: indie.Optional[int] = None,
continuous: indie.Optional[bool] = None,
base_value: indie.Optional[float] = None,
rel_width: indie.Optional[float] = None,
display_options: indie.PlotDisplayOptions =
indie.PlotDisplayOptions(pane=True, status_line=True, price_label=True)
) -> NoneType
PARAMETERS
id
— A unique identifier of plot which is used in cases when a @fill()
should be applied between some of the two plots of an indicator.
title
— Human readable title which is visible in the indicator's Settings panel.
color
— Color of the plot on a chart. This color could be overwritten if the plot is a multicolored one. Example of an indicator with a multicolored plot is Awesome Oscillator (AO).
style
— Determines how the plot data is rendered. It is represented as enum value of type plot_style
.
line_style
— Style of the line. Could be only used in combination with plot_style.LINE
. It is represented as enum value of type line_style
.
line_width
— Width of the line. Could be only used in combination with plot_style.LINE
, plot_style.STEPS
or plot_style.HISTOGRAM
.
continuous
— Whether the plot should be continuous when the indicator has NaN
values. Could be only used in combination with plot_style.LINE
.
base_value
— Base value. Could be only used in combination with plot_style.HISTOGRAM
or plot_style.COLUMNS
.
rel_width
— Relative width. Could be only used in combination with plot_style.COLUMNS
.
display_options
— Determines the ways to display plot data.
EXAMPLE
@plot()
@plot()
@plot(style=plot_style.HISTOGRAM)
# @plot() - for the fourth plot could be omitted
def main(ctx):
return ctx.open[0], ctx.high[0], ctx.low[0], ctx.close[0]
Color.__call__()
method
Applies transparency to the color.
__call__(alpha: float) -> indie.Color
PARAMETERS
alpha
— Transparency of color. 1.0
corresponds to opaque.SEE ALSO
Context.calc_on()
method
Requests additional instrument (creates a context object for it) for indicator and returns one or more Series
objects which matches with the arity of values ctx_func
function returns. All the returned series values are merged with (onto) the timescale of current context's instrument.
calc_on(
ctx_func: typing.Any = None,
exchange: indie.Optional[str] = None,
ticker: indie.Optional[str] = None,
time_frame: indie.Optional[indie.TimeFrame] = None,
lookahead: bool = False
) -> typing.Any
PARAMETERS
ctx_func
— Function decorated with @ctx_func()
. This function has the same semantics as Indie main()
, but for additional instrument (not the main one).
exchange
— Alias of exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.
ticker
— Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.
time_frame
— Time frame of additional instrument. If omitted, then the time frame of current context's instrument will be used. At the moment it is allowed to request only time frames which are higher or equal to the time frame of current context's instrument.
lookahead
— If this flag is true, then when calculating history, the bars of the secondary context are merged with the bars of the current context based on their opening time. Such a data merge strategy may result in unintended use of data from future history.
REMARKS
At least one of optional arguments (exchange
, ticker
and time_frame
) must be provided. More info about this function as well as code examples you may find in Request additional instruments chapter.
Fill.__init__()
method
Class constructor (initializer for the data type).
__init__(
offset: int = 0,
color: indie.Optional[indie.Color] = None
) -> indie.Fill
PARAMETERS
offset
— Offset (in bars) of the fill during its rendering.
color
— Color to overwrite the default one (that was set in a @fill()
decorator).
SEE ALSO
IndieError.__init__()
method
Class constructor (initializer for the data type).
__init__(msg: str) -> indie.IndieError
PARAMETERS
msg
— Error message.SEE ALSO
MutSeries.__getitem__()
method
Gets value of MutSeries
object at the specified index.
__getitem__(int) -> float
PARAMETERS
<unnamed param>
— Index to extract value at.SEE ALSO
MutSeries.__len__()
method
Gets len of MutSeries
object.
__len__() -> int
MutSeries.__setitem__()
method
Sets value of MutSeries
object at the specified index.
__setitem__(int, float) -> NoneType
PARAMETERS
<unnamed param>
— Index to extract value at.
<unnamed param>
— New value.
SEE ALSO
MutSeries.get()
method
Tries to get value of MutSeries
object at the specified index.
get(offset: int, default: float) -> float
PARAMETERS
offset
— Index to extract value at.
default
— Default value that will be used if an element at the specified index cannot be extracted.
SEE ALSO
MutSeries.request_size()
method
Expands the number of elements that MutSeries
object should persist in memory.
request_size(size: int) -> NoneType
PARAMETERS
size
— Number of elements that Series
object should persist in memory. Default and possible minimum size is 2, which means that series of size = 2
persists in memory value at the time of the last candle and value at the time of previous candle. Size is automatically expanded during history calculation of an indicator.SEE ALSO
Optional[T].value()
method
Tries to get value of Optional
object.
value() -> T
Optional[T].value_or()
method
Tries to get value of Optional
object and returns the value of default if there is no value.
value_or(default: T) -> T
PARAMETERS
default
— Default value that will be used if there is no value.SEE ALSO
Plot.__init__()
method
Class constructor (initializer for the data type).
__init__(
value: float,
offset: int = 0,
color: indie.Optional[indie.Color] = None
) -> indie.Plot
PARAMETERS
value
— Value that will be used as the current value of the plot.
offset
— Offset (in bars) of the plot during its rendering.
color
— Color to overwrite the default one (that was set in a @plot()
decorator).
SEE ALSO
PlotDisplayOptions.__init__()
method
Class constructor (initializer for the data type).
__init__(
pane: bool = False,
status_line: bool = False,
price_label: bool = False
) -> indie.PlotDisplayOptions
PARAMETERS
pane
— Whether or not to draw (by default) the plot on the pane.
status_line
— Whether or not to show the value of the plot in the status line.
price_label
— Whether or not to show the value label of the plot on the price axis.
SEE ALSO
Series.__getitem__()
method
Gets value of Series
object at the specified index.
__getitem__(int) -> float
PARAMETERS
<unnamed param>
— Index to extract value at.SEE ALSO
Series.__len__()
method
Gets len of Series
object.
__len__() -> int
Series.__setitem__()
method
Sets value of Series
object at the specified index.
__setitem__(int, float) -> NoneType
PARAMETERS
<unnamed param>
— Index to extract value at.
<unnamed param>
— New value.
SEE ALSO
Series.get()
method
Tries to get value of Series
object at the specified index.
get(offset: int, default: float) -> float
PARAMETERS
offset
— Index to extract value at.
default
— Default value that will be used if an element at the specified index cannot be extracted.
SEE ALSO
Series.request_size()
method
Expands the number of elements that Series
object should persist in memory.
request_size(size: int) -> NoneType
PARAMETERS
size
— Number of elements that Series
object should persist in memory. Default and possible minimum size is 2, which means that series of size = 2
persists in memory value at the time of the last candle and value at the time of previous candle. Size is automatically expanded during history calculation of an indicator.SEE ALSO
TimeFrame.to_minutes()
method
Converts TimeFrame
type to number of minutes. Month is considered as 30 days always, and year is 365 days.
to_minutes() -> int
mut_series()
function
Creates MutSeries
objects which are containers for calculated values in Indie code. The main feature of MutSeries
container is ability to store (or "remember") historical values of some variable, those values could be later accessed with the square brackets operator.
mut_series(
reset: indie.Optional[float] = None,
init: indie.Optional[float] = None,
size: indie.Optional[int] = None,
default: indie.Optional[float] = None
) -> indie.MutSeries
PARAMETERS
reset
— Value that is written into the most recent element of the Series
every time mut_series()
function is executed.
init
— Value that is written into the most recent element of the Series
object only once after the Series
object was created. Or, in other words, it is a value that is written only at the time of the first mut_series()
function call.
size
— Number of elements that Series
object should persist in memory. Default and possible minimum size is 2, which means that series of size = 2
persists in memory value at the time of the last candle and value at the time of previous candle. Size is automatically expanded during history calculation of an indicator. Series
objects also have a method request_size(new_size: int)
which can be used to expand the size explicitly.
default
— Value that is returned in certain cases when offset is out of bounds of Series
object. The certain cases here are only those which happen before all the internal buffers are trimmed (this usually happens right after calculation of history).
EXAMPLE
# this:
s1 = mut_series(reset_val)
s2 = mut_series(init=init_val)
# is the same as:
s1 = mut_series()
s1[0] = reset_val
s2 = mut_series()
if ctx.bar_index == 0:
s2[0] = init_val
At the moment this function only supports float
type as MutSeries
element.
mut_series()
MutSeries
Context
series()
function
Creates MutSeries
objects which are containers for calculated values in Indie code. The main feature of MutSeries
container is ability to store (or "remember") historical values of some variable, those values could be later accessed with the square brackets operator.
series(
reset: indie.Optional[float] = None,
init: indie.Optional[float] = None,
size: indie.Optional[int] = None,
default: indie.Optional[float] = None
) -> indie.MutSeries
PARAMETERS
reset
— Value that is written into the most recent element of the Series
every time mut_series()
function is executed.
init
— Value that is written into the most recent element of the Series
object only once after the Series
object was created. Or, in other words, it is a value that is written only at the time of the first mut_series()
function call.
size
— Number of elements that Series
object should persist in memory. Default and possible minimum size is 2, which means that series of size = 2
persists in memory value at the time of the last candle and value at the time of previous candle. Size is automatically expanded during history calculation of an indicator. Series
objects also have a method request_size(new_size: int)
which can be used to expand the size explicitly.
default
— Value that is returned in certain cases when offset is out of bounds of Series
object. The certain cases here are only those which happen before all the internal buffers are trimmed (this usually happens right after calculation of history).
EXAMPLE
# this:
s1 = series(reset_val)
s2 = series(init=init_val)
# is the same as:
s1 = series()
s1[0] = reset_val
s2 = series()
if ctx.bar_index == 0:
s2[0] = init_val
Deprecated, use mut_series
function instead. At the moment this function only supports float
type as MutSeries
element.
mut_series()
MutSeries
Context
tf()
function
Converts string representation of time frame to TimeFrame
type.
tf(s: str = None) -> indie.TimeFrame
PARAMETERS
s
— String representation of time frame.SEE ALSO
Context.bar_count
field
Current total number of bars. It is always true that ctx.bar_count
is equal to ctx.bar_index + 1
.
Context.bar_index
field
Index of a current bar. The very first bar has index equal to 0.0
and this is the oldest bar.
Context.close
field
Series of close prices of the context's instrument.
Context.high
field
Series of high prices of the context's instrument.
Context.hl2
field
Series of (high + low) / 2
values of the context's instrument.
Context.hlc3
field
Series of (high + low + close) / 3
values of the context's instrument.
Context.info
field
Information about the context's instrument.
Context.is_last_bar
field
Flag that is true if the current bar is the last bar in the history or it is a realtime bar.
Context.is_last_history_bar
field
Flag that is true if the current bar is the last bar in the history.
Context.is_realtime
field
Flag that is true if the current bar is a realtime bar.
Context.low
field
Series of low prices of the context's instrument.
Context.ohlc4
field
Series of (open + high + low + close) / 4
values of the context's instrument.
Context.open
field
Series of open prices of the context's instrument.
Context.time
field
Series of timestamps (in seconds) of the context's instrument. Every timestamp corresponds to start time of some bar on a chart.
Context.time_frame
field
Time frame of the context's instrument.
Context.volume
field
Series of volume values of the context's instrument.
SymbolInfo.exchange_aliases
field
Commonly recognized (but not exactly standardized) alias of an exchange. For example, an alias of the New York Stock Exchange, Inc. is 'NYSE'
. In most cases exchange alias matches with the exchange acronym (see ISO10383).
SymbolInfo.exchange_code
field
Exchange code of the context's instrument. For stocks it is a MIC. For crypto instruments it is just some identifier, not commonly recognized as MIC but unique within TakeProfit. For example, exchange_code
for the New York Stock Exchange, Inc. is 'XNYS'
.
SymbolInfo.marketdata_timezone
field
Name of the exchange timezone of the context's instrument. For example, 'America/New_York'
.
SymbolInfo.price_precision
field
Price precision of the context's instrument. For example, price precision of 100
means that prices have two digits after the floating point.
SymbolInfo.tick_size
field
Absolute value of a minimal movement of a price of the context's instrument in corresponding currency.
SymbolInfo.ticker
field
Ticker of the context's instrument.
format.INHERITED
static field
Indicator output values are formatted same as values of the main chart instrument.
format.PRICE
static field
Indicator output values are formatted using fixed number of digits after the floating point. The number of digits is set with additional parameter precision
of @indicator()
. The precision
param has effect only in combination with the format.PRICE
format.
format.VOLUME
static field
Indicator output values are formatted according to the rules of formatting large numbers, such as volumes of trades. For example 100500.0
will be formatted as 100.5K
.
line_style.DASHED
static field
Builtin line style that determines how the line is rendered.
line_style.DOTTED
static field
Builtin line style that determines how the line is rendered.
line_style.SOLID
static field
Builtin line style that determines how the line is rendered.
plot_style.COLUMNS
static field
Builtin plot style that determines how the plot data is rendered.
plot_style.HISTOGRAM
static field
Builtin plot style that determines how the plot data is rendered.
plot_style.LINE
static field
Builtin plot style that determines how the plot data is rendered.
plot_style.STEPS
static field
Builtin plot style that determines how the plot data is rendered.
source.CLOSE
static field
Builtin series got from ctx
used to initialize source input parameter.
source.HIGH
static field
Builtin series got from ctx
used to initialize source input parameter.
source.HL2
static field
Builtin series got from ctx
used to initialize source input parameter.
source.HLC3
static field
Builtin series got from ctx
used to initialize source input parameter.
source.LOW
static field
Builtin series got from ctx
used to initialize source input parameter.
source.OHLC4
static field
Builtin series got from ctx
used to initialize source input parameter.
source.OPEN
static field
Builtin series got from ctx
used to initialize source input parameter.
source.VOLUME
static field
Builtin series got from ctx
used to initialize source input parameter.
indie.algorithm
Algorithms package of indie language.
adx()
atr()
bb()
cci()
change()
cum_sum()
dev()
donchian()
ema()
fix_nan()
highest()
lowest()
ma()
median()
mfv()
nan_to_zero()
net_volume()
percent_rank()
rma()
roc()
rsi()
since_highest()
since_lowest()
sma()
std_dev()
stoch()
sum()
supertrend()
tr()
tsi()
vwap()
vwma()
wma()
adx()
function
Returns series of Minus Directional Indicator, Average Directional Index and Plus Directional Indicator.
adx(
ctx: indie.Context,
adx_len: int,
di_len: int
) -> tuple[indie.MutSeries, indie.MutSeries, indie.MutSeries]
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
adx_len
— Number of bars to calculate smoothing.
di_len
— Number of bars to calculate directional indicator.
SOURCE CODE
from math import nan, isclose
from indie import func, MutSeries, mut_series, Context
from indie.algorithm import change, rma, tr, fix_nan
@func
def adx(ctx: Context, adx_len: int, di_len: int) -> tuple[MutSeries, MutSeries, MutSeries]:
'''Average Directional Index'''
up = change(ctx.high)[0]
down = -change(ctx.low)[0]
plus_dm = mut_series(0 if up <= down or up <= 0 else up)
minus_dm = mut_series(0 if down <= up or down <= 0 else down)
truerange = rma(tr(ctx), di_len)
plus = mut_series(init=nan)
minus = mut_series(init=nan)
if not isclose(truerange[0], 0):
plus[0] = 100 * rma(plus_dm, di_len)[0] / truerange[0]
minus[0] = 100 * rma(minus_dm, di_len)[0] / truerange[0]
plus = fix_nan(plus)
minus = fix_nan(minus)
sum = plus[0] + minus[0]
res = 100 * rma(mut_series(abs(plus[0] - minus[0]) / (sum if sum != 0 else 1)), adx_len)[0]
return minus, mut_series(res), plus
atr()
function
Returns series of Average True Range values calculated for the length
bars period using moving average specified by ma_algorithm
argument.
atr(
ctx: indie.Context,
length: int,
ma_algorithm: str = "RMA"
) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
length
— Number of bars in calculation taken into account.
ma_algorithm
— Moving average algorithm name, should be one of 'EMA'
, 'SMA'
, 'SMMA (RMA)'
, 'RMA'
, 'VWMA'
or 'WMA'
.
SOURCE CODE
from indie import func, MutSeries, Context
from indie.algorithm import tr, ma
@func
def atr(ctx: Context, length: int, ma_algorithm: str = 'RMA') -> MutSeries:
'''Average True Range'''
return ma(ctx, tr(ctx, True), length, ma_algorithm)
bb()
function
Returns middle, upper and lower series of Bollinger Bands calculated on src
series for the length
bars period.
bb(
src: indie.Series,
length: int,
mult: float
) -> tuple[indie.MutSeries, indie.MutSeries, indie.MutSeries]
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
mult
— Multiplier for standard deviation.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sma, std_dev
@func
def bb(src: Series, length: int, mult: float) -> tuple[MutSeries, MutSeries, MutSeries]:
'''Bollinger Bands'''
middle = sma(src, length)[0]
dev = mult * std_dev(src, length)[0]
lower = middle - dev
upper = middle + dev
return mut_series(lower), mut_series(middle), mut_series(upper)
cci()
function
Returns series of Commodity Channel Index values calculated on src
series for the length
bars period.
cci(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import nan, isclose
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sma, dev
@func
def cci(src: Series, length: int) -> MutSeries:
'''Commodity Channel Index'''
ma = sma(src, length)
dv = dev(src, length)[0]
res = nan
if not isclose(dv, 0):
res = (src[0] - ma[0]) / (0.015 * dv)
return mut_series(res)
change()
function
Returns the difference between current src
value and its value length
bars ago.
change(src: indie.Series, length: int = 1) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars ago to compare the current value.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
@func
def change(src: Series, length: int = 1) -> MutSeries:
return mut_series(src[0] - src[length])
cum_sum()
function
Returns series of cumulative sum of src
values.
cum_sum(src: indie.Series) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.SOURCE CODE
from indie import func, Series, MutSeries, mut_series
@func
def cum_sum(src: Series) -> MutSeries:
res = mut_series(init=0)
res[0] += src[0]
return mut_series(res[0])
dev()
function
Returns series of Mean Absolute Deviation values calculated on src
series for the length
bars period.
dev(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sma
@func
def dev(src: Series, length: int) -> MutSeries:
'''Mean Absolute Deviation'''
mean = sma(src, length)[0]
sum = 0.0
for i in range(length):
sum += abs(src[i] - mean)
return mut_series(sum / length)
donchian()
function
Returns series of Middle Channel of Donchian Channels calculated for the length
bars period.
donchian(ctx: indie.Context, length: int) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, MutSeries, mut_series, Context
from indie.algorithm import lowest, highest
@func
def donchian(ctx: Context, length: int) -> MutSeries:
return mut_series((lowest(length, ctx.low)[0] + highest(length, ctx.high)[0]) / 2)
ema()
function
Returns series of Exponential Moving Average values calculated on src
series for the length
bars period.
ema(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import isnan, nan
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sma
@func
def ema(src: Series, length: int) -> MutSeries:
'''Exponential Moving Average'''
alpha = 2 / (length + 1)
s = mut_series(init=0)
res_sma = sma(src, length)[0]
result = 0.0
if isnan(src[0]):
s[0] = nan
result = res_sma
elif isnan(s[1]):
s[0] = res_sma
result = s[0]
else:
s[0] = alpha * src[0] + (1 - alpha) * s[1]
result = s[0]
return mut_series(result)
fix_nan()
function
Returns series created from src
by replacing nan
values with previous nearest non-nan
value.
fix_nan(src: indie.Series) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.SOURCE CODE
from math import isnan
from indie import func, Series, MutSeries, mut_series
@func
def fix_nan(src: Series) -> MutSeries:
res = mut_series(init=src[0])
if not isnan(src[0]):
res[0] = src[0]
return mut_series(res[0])
highest()
function
Returns maximum price of given src
series over a period of length
bars.
highest(length: int, src: indie.Series) -> indie.MutSeries
PARAMETERS
length
— Number of bars in calculation taken into account.
src
— Series data to perform the calculation.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
@func
def highest(length: int, src: Series) -> MutSeries:
src.request_size(length)
result = src[0]
for i in range(1, length):
result = max(src[i], result)
return mut_series(result)
lowest()
function
Returns minimum price of given src
series over a period of length
bars.
lowest(length: int, src: indie.Series) -> indie.MutSeries
PARAMETERS
length
— Number of bars in calculation taken into account.
src
— Series data to perform the calculation.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
@func
def lowest(length: int, src: Series) -> MutSeries:
src.request_size(length)
result = src[0]
for i in range(1, length):
result = min(src[i], result)
return mut_series(result)
ma()
function
Returns a moving average of src
specified by algorithm
argument.
ma(
ctx: indie.Context,
src: indie.Series,
length: int,
algorithm: str
) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
algorithm
— Moving average algorithm name, should be one of 'EMA'
, 'SMA'
, 'SMMA (RMA)'
, 'RMA'
, 'VWMA'
or 'WMA'
.
SOURCE CODE
from indie import func, Series, MutSeries, Optional, IndieError, Context
from indie.algorithm import ema, sma, rma, vwma, wma
@func
def ma(ctx: Context, src: Series, length: int, algorithm: str) -> MutSeries:
'''Moving Average'''
result: Optional[MutSeries]
if algorithm == 'EMA':
result = ema(src, length)
elif algorithm == 'SMA':
result = sma(src, length)
elif algorithm == 'SMMA (RMA)' or algorithm == 'RMA':
result = rma(src, length)
elif algorithm == 'VWMA':
result = vwma(ctx, src, length)
elif algorithm == 'WMA':
result = wma(src, length)
else:
raise IndieError("moving average algorithm should be one of 'EMA', 'SMA', "
"'SMMA (RMA)', 'RMA', 'VWMA' or 'WMA' but it is " + algorithm)
return result.value()
median()
function
Returns series of Moving Median values calculated from series of src
for the length
bars period.
median(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
REMARKS
Indie implementation is currently unavailable.
mfv()
function
Returns series of Money Flow Volume.
mfv(ctx: indie.Context) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.SOURCE CODE
from math import isclose
from indie import func, MutSeries, Context, mut_series
@func
def mfv(ctx: Context) -> MutSeries:
'''Money Flow Volume'''
h = ctx.high[0]
l = ctx.low[0]
c = ctx.close[0]
v = ctx.volume[0]
res = 0.0
if not isclose(h - l, 0):
res = ((c - l) - (h - c)) / (h - l) * v
return mut_series(res)
nan_to_zero()
function
Returns series created from src
by replacing nan
values with zeros.
nan_to_zero(src: indie.Series) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.SOURCE CODE
from math import isnan
from indie import func, Series, MutSeries, mut_series
@func
def nan_to_zero(src: Series) -> MutSeries:
res = 0 if isnan(src[0]) else src[0]
return mut_series(res)
net_volume()
function
Returns series of Net Volume values calculated on src
series.
net_volume(ctx: indie.Context, src: indie.Series) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
src
— Series data to perform the calculation.
SOURCE CODE
from math import nan
from indie import func, Series, MutSeries, mut_series, Context
from indie.algorithm import change
@func
def net_volume(ctx: Context, src: Series) -> MutSeries:
der = change(src)[0]
nv = mut_series(init=nan)
if der > 0:
nv[0] = ctx.volume[0]
elif der < 0:
nv[0] = -ctx.volume[0]
elif der == 0:
nv[0] = 0
return mut_series(nv[0])
percent_rank()
function
Returns series of Percent Rank (number of previous values that are less or equal to the current value) calculated on src
series for the length
bars period.
percent_rank(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
@func
def percent_rank(src: Series, length: int) -> MutSeries:
num_leq = 0
for idx in range(1, length + 1):
if src[idx] <= src[0]:
num_leq += 1
return mut_series(100.0 * num_leq / length)
rma()
function
Returns a Moving Average that is used in calculations of rsi()
.
rma(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import isnan
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sma
@func
def rma(src: Series, length: int) -> MutSeries:
'''RSI Moving Average'''
result = mut_series(init=0)
if isnan(result[1]):
result[0] = sma(src, length)[0]
else:
result[0] = (src[0] + (length - 1) * result[1]) / length
return mut_series(result[0])
roc()
function
Returns series of Rate Of Change (percentage of change between the current value and value length
bars ago) calculated on src
series.
roc(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import nan, isclose
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import change
@func
def roc(src: Series, length: int) -> MutSeries:
'''Rate Of Change'''
res = nan
if not isclose(src[length], 0):
res = 100 * change(src, length)[0] / src[length]
return mut_series(res)
rsi()
function
Returns series of Relative Strength Index values calculated on src
series for the length
bars period.
rsi(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import isclose
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import nan_to_zero, change, rma
@func
def rsi(src: Series, length: int) -> MutSeries:
'''Relative Strength Index'''
u = max(nan_to_zero(change(src))[0], 0) # upward change
rma_u = rma(mut_series(u), length)
d = max(-nan_to_zero(change(src))[0], 0) # downward change
rma_d = rma(mut_series(d), length)
res = 100.0
if not isclose(rma_d[0], 0):
rs = rma_u[0] / rma_d[0]
res = 100 - 100 / (1 + rs)
return mut_series(res)
since_highest()
function
Returns the number of bars after the maximum price for the length
bars period.
since_highest(ctx: indie.Context, length: int) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, MutSeries, Context, mut_series
@func
def since_highest(ctx: Context, length: int) -> MutSeries:
offset = 0
for idx in range(length):
if ctx.high[idx] >= ctx.high[offset]:
offset = idx
return mut_series(offset)
since_lowest()
function
Returns the number of bars after the minimum price for the length
bars period.
since_lowest(ctx: indie.Context, length: int) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, MutSeries, Context, mut_series
@func
def since_lowest(ctx: Context, length: int) -> MutSeries:
offset = 0
for idx in range(length):
if ctx.low[idx] <= ctx.low[offset]:
offset = idx
return mut_series(offset)
sma()
function
Returns series of Simple Moving Average values calculated from series of src
for the length
bars period.
sma(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sum
@func
def sma(src: Series, length: int) -> MutSeries:
'''Simple Moving Average'''
s = sum(src, length)
return mut_series(s[0] / length)
std_dev()
function
Returns series of Standard Deviation values calculated from series of src
for the length
bars period.
std_dev(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import sqrt
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import sma
@func
def std_dev(src: Series, length: int) -> MutSeries:
avg = sma(src, length)
sum_of_square_deviations = 0.0
for i in range(length):
dev = src[i] - avg[0]
sum_of_square_deviations += dev * dev
return mut_series(sqrt(sum_of_square_deviations / length))
stoch()
function
Returns series of Stochastic on src
series with high
and low
highs and lows of the source over a period of length
bars.
stoch(
src: indie.Series,
low: indie.Series,
high: indie.Series,
length: int
) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
low
— Series of low values.
high
— Series of high values.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import isclose
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import lowest, highest
@func
def stoch(src: Series, low: Series, high: Series, length: int) -> MutSeries:
lowest_low = lowest(length, low)[0]
highest_high = highest(length, high)[0]
res = 100.0
if not isclose(highest_high - lowest_low, 0):
res = 100 * (src[0] - lowest_low) / (highest_high - lowest_low)
return mut_series(res)
sum()
function
Returns series of Sliding Sum values calculated on src
series for the length
bars period.
sum(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import isnan, nan
from indie import func, Series, MutSeries, mut_series
@func
def sum(src: Series, length: int) -> MutSeries:
src.request_size(length + 1)
nan_count = mut_series(init=0)
s = mut_series(init=0)
s[0] += src.get(0, 0)
result = 0.0
if isnan(src[0]):
nan_count[0] += 1
result = nan
else:
if len(src) - nan_count[0] > length:
s[0] -= src[length]
if len(src) - nan_count[0] < length:
result = nan
else:
result = s[0]
return mut_series(result)
supertrend()
function
Returns a tuple of two Supertrend series: Supertrend Line and Direction Of Trend.
supertrend(
ctx: indie.Context,
factor: float,
atr_period: int,
ma_algorithm: str
) -> tuple[indie.MutSeries, indie.MutSeries]
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
factor
— The multiplier by which the ATR will get multiplied.
atr_period
— Number of bars to calculate ATR.
ma_algorithm
— Moving average algorithm name, should be one of 'EMA'
, 'SMA'
, 'SMMA (RMA)'
, 'RMA'
, 'VWMA'
or 'WMA'
.
SOURCE CODE
from math import isnan
from indie import func, MutSeries, Context, mut_series
from indie.algorithm import atr as atr_alg
@func
def supertrend(ctx: Context, factor: float, atr_period: int, ma_algorithm: str) -> tuple[MutSeries, MutSeries]:
src = ctx.hl2
atr = atr_alg(ctx, atr_period, ma_algorithm)
upper_band = mut_series(src[0] + factor * atr[0])
lower_band = mut_series(src[0] - factor * atr[0])
prev_lower_band = lower_band.get(1, 0)
prev_upper_band = upper_band.get(1, 0)
lower_band[0] = lower_band[0] \
if lower_band[0] > prev_lower_band or ctx.close[1] < prev_lower_band \
else prev_lower_band
upper_band[0] = upper_band[0] \
if upper_band[0] < prev_upper_band or ctx.close[1] > prev_upper_band \
else prev_upper_band
direction: float
super_trend = mut_series(init=0)
prev_super_trend = super_trend[1]
if isnan(atr[1]):
direction = 1.0
elif prev_super_trend == prev_upper_band:
direction = -1.0 if ctx.close[0] > upper_band[0] else 1.0
else:
direction = 1.0 if ctx.close[0] < lower_band[0] else -1.0
super_trend[0] = lower_band[0] if direction < 0 else upper_band[0]
return mut_series(super_trend[0]), mut_series(direction)
tr()
function
Returns series of True Range values.
tr(ctx: indie.Context, handle_na: bool = False) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
handle_na
— Flag that says how NaN
close values of the previous day are handled.
SOURCE CODE
from math import nan, isnan
from indie import func, MutSeries, mut_series, Context
@func
def tr(ctx: Context, handle_na: bool = False) -> MutSeries:
'''True Range'''
res = nan if handle_na else ctx.high[0] - ctx.low[0]
if not isnan(ctx.close[1]):
res = max(ctx.high[0] - ctx.low[0],
abs(ctx.high[0] - ctx.close[1]),
abs(ctx.low[0] - ctx.close[1]),
)
return mut_series(res)
tsi()
function
Returns series of True Strength Index values.
tsi(src: indie.Series, long_len: int, short_len: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
long_len
— Long length.
short_len
— Short length.
SOURCE CODE
from math import nan, isclose
from indie import func, Series, MutSeries, mut_series
from indie.algorithm import ema, change
@func
def double_smooth(src: Series, long_len: int, short_len: int) -> MutSeries:
return ema(ema(src, long_len), short_len)
@func
def tsi(src: Series, long_len: int, short_len: int) -> MutSeries:
'''True Strength Index'''
pc = change(src)
double_smoothed_pc = double_smooth(pc, long_len, short_len)[0]
abs_pc = mut_series(abs(pc[0]))
double_smoothed_abs_pc = double_smooth(abs_pc, long_len, short_len)[0]
res = nan
if not isclose(double_smoothed_abs_pc, 0):
res = double_smoothed_pc / double_smoothed_abs_pc
return mut_series(res)
vwap()
function
Returns series of Volume Weighted Average Price values with band of its standard deviation.
vwap(
ctx: indie.Context,
src: indie.Series,
anchor: str,
std_dev_mult: float
) -> tuple[indie.MutSeries, indie.MutSeries, indie.MutSeries]
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
src
— Series data to perform the calculation.
anchor
— At what points in time do we need to reset the accumulated amounts. Valid values are: 'day', 'week', 'month', 'year'.
std_dev_mult
— Multiplier for standard deviation.
SOURCE CODE
from math import sqrt
from indie import func, Series, MutSeries, mut_series, Context
from datetime import datetime
@func
def vwap(
ctx: Context, src: Series, anchor: str, std_dev_mult: float
) -> tuple[MutSeries, MutSeries, MutSeries]:
'''
Volume Weighted Average Price
anchor can be 'day', 'week', 'month', 'year'
'''
cum_weighted_price = mut_series(init=0)
cum_volume = mut_series(init=0)
vwap_values = mut_series(init=0)
vwap_sum = mut_series(init=0)
vwap_count = mut_series(init=0)
vwap_avg = mut_series(init=0)
vwap_dev_squares = mut_series(init=0)
vwap_std_dev = mut_series(init=0)
current_datetime = datetime.utcfromtimestamp(float(ctx.time[0])/1000.0)
prev_datetime = datetime.utcfromtimestamp(float(ctx.time.get(1, 0))/1000.0)
need_reset = False
if anchor == "day" and (current_datetime.day != prev_datetime.day or
(current_datetime-prev_datetime).days >= 1):
need_reset = True
elif anchor == "week" and ((current_datetime.weekday() == 0 and prev_datetime.weekday() != 0) or
(current_datetime-prev_datetime).days >= 7):
need_reset = True
elif anchor == "month" and (current_datetime.month != prev_datetime.month or
(current_datetime-prev_datetime).days >= 31):
need_reset = True
elif anchor == "year" and current_datetime.year != prev_datetime.year:
need_reset = True
if need_reset:
cum_weighted_price[0] = 0.0
cum_volume[0] = 0.0
vwap_sum[0] = 0.0
vwap_count[0] = 0
vwap_dev_squares[0] = 0.0
cum_weighted_price[0] += src[0] * ctx.volume[0]
cum_volume[0] += ctx.volume[0]
vwap_values[0] = cum_weighted_price[0] / cum_volume[0]
vwap_sum[0] += vwap_values[0]
vwap_count[0] += 1
vwap_avg[0] = vwap_sum[0] / vwap_count[0]
vwap_dev_squares[0] += (vwap_values[0] - vwap_avg[0]) ** 2
vwap_std_dev[0] = sqrt(vwap_dev_squares[0] / vwap_count[0])
std_dev = std_dev_mult * vwap_std_dev[0]
lower = mut_series(vwap_values[0] - std_dev)
upper = mut_series(vwap_values[0] + std_dev)
return vwap_values, upper, lower
vwma()
function
Returns series of Volume Weighted Moving Average values calculated for src
series for the length
bars period.
vwma(ctx: indie.Context, src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
ctx
— Context object from main()
or @ctx_func()
function that represents an instrument with OHLCV series values.
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from math import nan, isclose
from indie import func, Series, MutSeries, mut_series, Context
from indie.algorithm import sma
@func
def vwma(ctx: Context, src: Series, length: int) -> MutSeries:
'''Volume Weighted Moving Average'''
src_vol = mut_series(src[0] * ctx.volume[0])
sma_src_vol = sma(src_vol, length)
sma_vol = sma(ctx.volume, length)
res = nan
if not isclose(sma_vol[0], 0):
res = sma_src_vol[0] / sma_vol[0]
return mut_series(res)
wma()
function
Returns series of Weighted Moving Average values calculated for src
series for the length
bars period.
wma(src: indie.Series, length: int) -> indie.MutSeries
PARAMETERS
src
— Series data to perform the calculation.
length
— Number of bars in calculation taken into account.
SOURCE CODE
from indie import func, Series, MutSeries, mut_series
@func
def wma(src: Series, length: int) -> MutSeries:
'''Weighted Moving Average'''
norm = 0.0
s = 0.0
for i in range(length):
weight = length - i
norm += weight
s += src[i] * weight
return mut_series(s / norm)
indie.color
Class-container for builtin colors and rgba()
function.
AQUA
BLACK
BLUE
FUCHSIA
GRAY
GREEN
LIME
MAROON
NAVY
OLIVE
PURPLE
RED
rgba()
SILVER
TEAL
WHITE
YELLOW
rgba()
function
Returns color by its RGB components and transparency.
rgba(red: int, green: int, blue: int, alpha: float = 1.0) -> indie.Color
PARAMETERS
red
— Red component of color.
green
— Green component of color.
blue
— Blue component of color.
alpha
— Transparency of color. 1.0
corresponds to opaque.
AQUA
object
Builtin color.
BLACK
object
Builtin color.
BLUE
object
Builtin color.
FUCHSIA
object
Builtin color.
GRAY
object
Builtin color.
GREEN
object
Builtin color.
LIME
object
Builtin color.
MAROON
object
Builtin color.
NAVY
object
Builtin color.
OLIVE
object
Builtin color.
PURPLE
object
Builtin color.
RED
object
Builtin color.
SILVER
object
Builtin color.
TEAL
object
Builtin color.
WHITE
object
Builtin color.
YELLOW
object
Builtin color.
math
Math package.
acos()
asin()
atan()
ceil()
cos()
e
exp()
exp2()
floor()
isclose()
isnan()
log()
log10()
log2()
nan
pi
pow()
sin()
sqrt()
tan()
See description in the official Python docs.
acos()
function
Standard function of Indie math package (similar to Python one).
acos(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
asin()
function
Standard function of Indie math package (similar to Python one).
asin(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
atan()
function
Standard function of Indie math package (similar to Python one).
atan(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
ceil()
function
Standard function of Indie math package (similar to Python one).
ceil(float) -> int
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
cos()
function
Standard function of Indie math package (similar to Python one).
cos(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
exp()
function
Standard function of Indie math package (similar to Python one).
exp(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
exp2()
function
Standard function of Indie math package (similar to Python one).
exp2(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
floor()
function
Standard function of Indie math package (similar to Python one).
floor(float) -> int
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
isclose()
function
Standard function of Indie math package (similar to Python one).
isclose(float, float, rel_tol: float = 1e-9, abs_tol: float = 0.0) -> bool
PARAMETERS
<unnamed param>
— First value to check for proximity.
<unnamed param>
— Second value to check for proximity.
rel_tol
— Relative tolerance for proximity check.
abs_tol
— Absolute tolerance for proximity check.
isnan()
function
Standard function of Indie math package (similar to Python one).
isnan(float) -> bool
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
log()
function
Standard function of Indie math package (similar to Python one).
log(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
log10()
function
Standard function of Indie math package (similar to Python one).
log10(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
log2()
function
Standard function of Indie math package (similar to Python one).
log2(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
pow()
function
Standard function of Indie math package (similar to Python one).
pow(float, float) -> float
PARAMETERS
<unnamed param>
— Base value to calculate exponentiation.
<unnamed param>
— Exponent (power) value to calculate exponentiation.
sin()
function
Standard function of Indie math package (similar to Python one).
sin(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
sqrt()
function
Standard function of Indie math package (similar to Python one).
sqrt(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
tan()
function
Standard function of Indie math package (similar to Python one).
tan(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
e
object
Standard constant of Indie math package (similar to Python one).
nan
object
Standard constant of Indie math package (similar to Python one).
pi
object
Standard constant of Indie math package (similar to Python one).
statistics
Statistics package.
See description in the official Python docs.
fmean()
function
Standard statistics function.
fmean(data: list[float]) -> float
PARAMETERS
data
— List on which the function will be calculated.
mean()
function
Standard statistics function.
mean(data: list[float]) -> float
mean(data: list[int]) -> float
PARAMETERS
data
— List on which the function will be calculated.
median()
function
Standard statistics function.
median(data: list[float]) -> float
PARAMETERS
data
— List on which the function will be calculated.
datetime
The datetime package supplies classes for manipulating dates and times.
See description in the official Python docs.
datetime
type
Represents date and time information.
__add__()
__init__()
__sub__()
day
hour
microsecond
minute
month
second
utcfromtimestamp()
weekday()
year
timedelta
type
A timedelta object represents a duration, the difference between two dates or times.
__init__()
days
microseconds
seconds
total_seconds()
datetime.__add__()
method
+
operator for datetime
objects.
__add__(delta: datetime.timedelta) -> datetime.datetime
PARAMETERS
delta
— Timedelta to add to the current datetime.SEE ALSO
datetime.__init__()
method
Class constructor (initializer for the data type).
__init__(
year: int,
month: int,
day: int,
hour: int = 0,
minute: int = 0,
second: int = 0,
microsecond: int = 0
) -> datetime.datetime
PARAMETERS
year
— Year value.
month
— Month value.
day
— Day value.
hour
— Hour value.
minute
— Minute value.
second
— Second value.
microsecond
— Microsecond value.
SEE ALSO
datetime.__sub__()
method
-
operator for datetime
objects.
__sub__(delta: datetime.timedelta) -> datetime.datetime
__sub__(other: datetime.datetime) -> datetime.timedelta
PARAMETERS
delta
— Timedelta to subtract from the current datetime.
other
— Datetime to subtract from the current datetime.
SEE ALSO
datetime.utcfromtimestamp()
static method
Returns the UTC datetime corresponding to the POSIX timestamp.
utcfromtimestamp(timestamp: float) -> datetime.datetime
PARAMETERS
timestamp
— Timestamp in UTC.SEE ALSO
datetime.weekday()
method
Returns the day of the week as an integer, where Monday is 0 and Sunday is 6.
weekday() -> int
timedelta.__init__()
method
Class constructor (initializer for the data type).
__init__(
days: int = 0,
seconds: int = 0,
microseconds: int = 0,
milliseconds: int = 0,
minutes: int = 0,
hours: int = 0,
weeks: int = 0
) -> datetime.timedelta
PARAMETERS
days
— Number of days.
seconds
— Number of seconds.
microseconds
— Number of microseconds.
milliseconds
— Number of milliseconds.
minutes
— Number of minutes.
hours
— Number of hours.
weeks
— Number of weeks.
SEE ALSO
timedelta.total_seconds()
method
Returns the total number of seconds contained in the duration.
total_seconds() -> float
datetime.day
field
The day value of the datetime object.
datetime.hour
field
The hour value of the datetime object.
datetime.microsecond
field
The microsecond value of the datetime object.
datetime.minute
field
The minute value of the datetime object.
datetime.month
field
The month value of the datetime object.
datetime.second
field
The second value of the datetime object.
datetime.year
field
The year value of the datetime object.
timedelta.days
field
The days value of the timedelta object.
timedelta.microseconds
field
The microseconds value of the timedelta object.
timedelta.seconds
field
The seconds value of the timedelta object.
NoneType
type
Builtin Indie type (similar to Python None
type).
bool
type
Builtin Indie type (similar to Python one).
dict[K, V]
type
Builtin Indie type (similar to Python one).
float
type
Builtin Indie type (similar to Python one).
int
type
Builtin Indie type (similar to Python one).
list[T]
type
Builtin Indie type (similar to Python one).
__getitem__()
__init__()
__len__()
__setitem__()
append()
pop()
remove()
# examples of list creation:
a = [1, 2, 3] # `a` has type `list[int]`
b = [1, 2, 3, 4.2] # `b` has type `list[float]`
c = ["a", "b", "c"] # `c` has type `list[str]`
d = [(1, "a"), (2, "b"), (3, "c")] # `d` has type `list[tuple[int, str]]`
e = [0, 1, 2, 3, 4, 5, 6, 7]
f = e[2:5] # `f` is `[2, 3, 4]`
g = e[:5] # `g` is `[0, 1, 2, 3, 4]`
h = e[2:] # `h` is `[2, 3, 4, 5, 6, 7]`
i = e[:] # `i` is a copy of `e`
j = e[1:7:2] # `j` is `[1, 3, 5]`
k = e[5:2:-1] # `k` is `[5, 4, 3]`
l = e[5::-1] # `l` is `[5, 4, 3, 2, 1, 0]`
m = e[::-1] # `m` is `[7, 6, 5, 4, 3, 2, 1, 0]`
str
type
Builtin Indie type (similar to Python one).
tuple[...]
type
Builtin Indie type (similar to Python one).
abs()
function
Builtin Indie function (similar to Python one).
abs(int) -> int
abs(float) -> float
PARAMETERS
<unnamed param>
— Number on which the function will be calculated.
bool.__init__()
method
Cast constructor for builtin Indie type.
__init__(bool) -> bool
__init__(int) -> bool
__init__(float) -> bool
__init__(str) -> bool
__init__(NoneType) -> bool
__init__(indie.Optional[bool]) -> bool
__init__(indie.Optional[int]) -> bool
__init__(indie.Optional[float]) -> bool
__init__(indie.Optional[str]) -> bool
PARAMETERS
<unnamed param>
— Value to cast from.SEE ALSO
float.__init__()
method
Cast constructor for builtin Indie type.
__init__(float) -> float
__init__(int) -> float
__init__(str) -> float
__init__(bool) -> float
PARAMETERS
<unnamed param>
— Value to cast from.SEE ALSO
int.__init__()
method
Cast constructor for builtin Indie type.
__init__(int) -> int
__init__(float) -> int
__init__(str) -> int
__init__(bool) -> int
PARAMETERS
<unnamed param>
— Value to cast from.SEE ALSO
len()
function
Builtin Indie function (similar to Python one).
len(list[float]) -> int
len(list[int]) -> int
len(list[str]) -> int
len(str) -> int
len(indie.Series) -> int
len(indie.MutSeries) -> int
PARAMETERS
<unnamed param>
— List on which the function will be calculated.
<unnamed param>
— String on which the function will be calculated.
<unnamed param>
— Series on which the function will be calculated.
<unnamed param>
— MutSeries on which the function will be calculated.
list[T].__getitem__()
method
Builtin Indie function (similar to Python one).
__getitem__(int) -> T
__getitem__(slice) -> list[T]
PARAMETERS
<unnamed param>
— Index of an element in the list.
<unnamed param>
— Slice of elements in the list, similar to Python slices. Slices allow to specify a start and end index, as well as a step size, in the format [start:stop:step]. Any of the slice indices can be omitted. See more examples here.
SEE ALSO
list[T].__init__()
method
Builtin Indie function (similar to Python one).
__init__(list[T]) -> list[T]
PARAMETERS
<unnamed param>
— List of elements.SEE ALSO
list[T].__len__()
method
Builtin Indie function (similar to Python one).
__len__() -> int
list[T].__setitem__()
method
Builtin Indie function (similar to Python one).
__setitem__(int, T) -> NoneType
PARAMETERS
<unnamed param>
— Index of an element in the list.
<unnamed param>
— New value that will be put to the list.
SEE ALSO
list[T].append()
method
Builtin Indie function (similar to Python one).
append(T) -> NoneType
PARAMETERS
<unnamed param>
— New value that will be put to the list.SEE ALSO
list[T].pop()
method
Builtin Indie function (similar to Python one).
pop(int) -> T
PARAMETERS
<unnamed param>
— Index of an element in the list.SEE ALSO
list[T].remove()
method
Builtin Indie function (similar to Python one).
remove(T) -> NoneType
PARAMETERS
<unnamed param>
— Value that will be removed from the listSEE ALSO
max()
function
Builtin Indie function (similar to Python one).
max(int, int) -> int
max(int, int, int) -> int
max(float, float) -> float
max(float, float, float) -> float
PARAMETERS
<unnamed param>
— First number to calculate the function.
<unnamed param>
— Second number to calculate the function.
<unnamed param>
— Third number to calculate the function.
min()
function
Builtin Indie function (similar to Python one).
min(int, int) -> int
min(int, int, int) -> int
min(float, float) -> float
min(float, float, float) -> float
PARAMETERS
<unnamed param>
— First number to calculate the function.
<unnamed param>
— Second number to calculate the function.
<unnamed param>
— Third number to calculate the function.
range()
function
Builtin Indie function (similar to Python one).
range(stop: int) -> list[int]
range(start: int, stop: int, step: int = 1) -> list[int]
PARAMETERS
stop
— Last value of the range (exclusive).
start
— First value of the range.
step
— Step value of the range.
round()
function
Builtin Indie function (similar to Python one).
round(number: float) -> int
round(number: float, ndigits: indie.Optional[int] = None) -> float
PARAMETERS
number
— Number on which the function will be calculated.
ndigits
— Rounding precision.
str.__init__()
method
Cast constructor for builtin Indie type.
__init__(int) -> str
__init__(float) -> str
__init__(str) -> str
__init__(bool) -> str
PARAMETERS
<unnamed param>
— Value to cast from.SEE ALSO
str.__len__()
method
Builtin Indie function (similar to Python one).
__len__() -> int
sum()
function
Builtin Indie function (similar to Python one).
sum(list[int], start: int = 0) -> int
sum(list[float], start: float = 0.0) -> float
PARAMETERS
<unnamed param>
— List on which the function will be calculated.
start
— Initial value to calculate sum of the list.
tuple[...].__getitem__()
method
Builtin Indie function (similar to Python one).
__getitem__(int) -> NoneType
PARAMETERS
<unnamed param>
— Index of an element in the tuple.SEE ALSO
False
object
Builtin Indie object (similar to Python one).
None
object
Builtin Indie object (similar to Python one).
True
object
Builtin Indie object (similar to Python one).