> ## Documentation Index
> Fetch the complete documentation index at: https://takeprofit.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Package indie

> The indie package: the decorators, functions, types, and enums at the core of every indicator and strategy.

Main package of Indie language.

***

## Decorators

### `@algorithm()`

*decorator*

**1. Overloads**

@algorithm

() -> None

Decorates a function, making it a *series processor* algorithm. Such algorithms are specifically designed to process series of data, like close prices of an instrument of a candle chart. One way of using such an algorithm is to call `new` static method, read more [here](https://takeprofit.com/docs/indie/How-Indies-syntactic-sugar-works.md#algorithm-new-method).
\[!NOTE] Most of the functions in the `indie.algorithms` package are decorated with `@indie.algorithm` decorator. Read more about it in [Series processors](https://takeprofit.com/docs/indie/Algorithms-for-series-processing.md) chapter.
\[!NOTE] See also: [`Algorithm`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Algorithm)

***

### `@band()`

*decorator*

**1. Overloads**

@band

(value1, value2, title, fill\_color, line\_color, line\_style, line\_width) -> None

Use this decorator to add a band (two horizontal lines usually with a semi-transparent fill in between them) to indicator.

**parameters info**

value1

float

required

Value of the first horizontal line of a band on a vertical scale of an indicator.

value2

float

required

Value of the second horizontal line of a band on a vertical scale of an indicator.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

fill\_color

indie.Color

default:
indie.color.GREEN(0.05)

Color of the background.

line\_color

indie.Color

default:
indie.color.GRAY(0.5)

Color of the plot on a chart. This color can be overwritten if the plot is a multicolored one. Example of an indicator with a multicolored plot is *Awesome Oscillator (AO)*.

line\_style

indie.line\_style

default:
indie.line\_style.DASHED

Style of the line. It is represented as enum value of type `line_style`.

line\_width

int

default:
1

Width of the line.

```py Example theme={null}
@indicator('Band example')
@band(145, 155, line_color=color.RED, line_width=4)
def Main(self):
    return self.close[0]
```

> [!NOTE]
>
> See also: [`@level()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_level)

***

### `@data_context()`

*decorator*

**1. Overloads**

@data\_context

() -> None

Decorates a function, making it an entry point that is executed once per row of an external data source. The type argument is a `@dataclass` that describes the shape of a row; inside the function the rows are available as `self.data`. Such a context is connected to the main context with `Context.calc_on` and its `source` argument.

```py Example theme={null}
# indie:lang_version = 5
from dataclasses import dataclass
from indie import indicator, MainContext, data_context
from indie.data import sources

@dataclass
class ModelOutput:
    signal: float
    confidence: float

@data_context[ModelOutput]
def ModelSignal(self):
    return self.data[0].signal * self.data[0].confidence

@indicator('External model signal')
class Main(MainContext):
    def __init__(self):
        self._signal = self.calc_on(
            ModelSignal,
            source=sources.Csv('https://example.com/signals.csv'))

    def calc(self):
        return self._signal[0]
```

> [!NOTE]
>
> More info on this topic you can find in [Typed external data](https://takeprofit.com/docs/indie/External-data/Typed-external-data.md) chapter.

> [!NOTE]
>
> See also: [`Context.calc_on()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_calc_on)[`Csv`](https://takeprofit.com/docs/indie/Library-reference/package-indie-data-sources#class_Csv)[`request_series()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#func_request_series)

***

### `@indicator()`

*decorator*

**1. Overloads**

@indicator

(abbrev\_title, overlay\_main\_pane, format, precision) -> None

Decorator that should be applied to the `Main` entry point of any indicator.

**parameters info**

abbrev\_title

str

required

Abbreviated title of the indicator.

overlay\_main\_pane

bool

default:
False

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

indie.format

default:
indie.format.INHERITED

Formatting style of indicator output values represented as enum value of type `format`.

precision

indie.Optional\[int]

default:
None

Number of digits after floating point for indicator output values.

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)

***

### `@level()`

*decorator*

**1. Overloads**

@level

(value, title, line\_color, line\_style, line\_width) -> None

Decorator that is used to create a level (horizontal line) in an indicator.

**parameters info**

value

float

required

Value of the level on a vertical scale of an indicator.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

line\_color

indie.Color

default:
indie.color.GRAY(0.5)

Color of the plot on a chart. This color can be overwritten if the plot is a multicolored one. Example of an indicator with a multicolored plot is *Awesome Oscillator (AO)*.

line\_style

indie.line\_style

default:
indie.line\_style.DASHED

Style of the line. It is represented as enum value of type `line_style`.

line\_width

int

default:
1

Width of the line.

```py Example theme={null}
@indicator('Level example')
@level(150, line_color=color.RED, line_width=4)
def Main(self):
    return self.close[0]
```

> [!NOTE]
>
> See also: [`@band()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_band)

***

### `@param_ref()`

*decorator*

**1. Overloads**

@param\_ref

(id) -> None

Declares an input parameter for `@sec_context` function that is linked to the input parameter of `Main` by `id`.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

```py Example theme={null}
@sec_context
@param_ref('referenced_param')
def SecMain(self, referenced_param) -> float:
    # Use referenced_param variable...

@indicator('Referenced param example')
@param.int('referenced_param', default=50)
class Main(MainContext):
    def __init__(self):
        self._calc_on_result = self.calc_on(time_frame=TimeFrame.from_str('1D'), sec_context=SecMain)

    def calc(self):
        return self._calc_on_result[0]
```

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`param`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_param)

***

### `param`

*type*

Class with decorators of indicator input parameters of various types.

**1. Static methods**

[Navigate to decor\_param\_bool](#decor_param_bool)

@bool

(id, default, title, group, show\_if, tooltip) -> None

Declares a bool input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

bool

required

Default value for the parameter in settings pane.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.bool('is_something_enabled', default=False)
def Main(self, is_something_enabled):
    # Use is_something_enabled variable...
```

[Navigate to decor\_param\_int](#decor_param_int)

@int

(id, default, min, max, step, title, group, show\_if, tooltip) -> None

Declares an integer input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

int

required

Default value for the parameter in settings pane.

min

int

default:
-1000000

Minimum value of the parameter.

max

int

default:
1000000

Maximum value of the parameter.

step

int

default:
1

Step between values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.int('meaning_of_life', default=42)
def Main(self, meaning_of_life):
    # Use meaning_of_life variable...
```

[Navigate to decor\_param\_float](#decor_param_float)

@float

(id, default, min, max, step, title, group, show\_if, tooltip) -> None

Declares a float input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

float

required

Default value for the parameter in settings pane.

min

float

default:
-1000000.0

Minimum value of the parameter.

max

float

default:
1000000.0

Maximum value of the parameter.

step

float

default:
0.1

Step between values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.float('speed_of_light', default=299_792.458)
def Main(self, speed_of_light):
    # Use speed_of_light variable...
```

[Navigate to decor\_param\_str](#decor_param_str)

@str

(id, default, options, title, group, show\_if, tooltip) -> None

Declares a str input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

str

required

Default value for the parameter in settings pane.

options

indie.Optional\[list\[str]]

default:
None

List of the possible values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.str('name', default='Lisa', options=['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie'])
def Main(self, name):
    # Use name variable...
```

> [!NOTE]
>
> If `options` parameter is used then in Settings panel there will be a combobox widget for changing value of this input.

[Navigate to decor\_param\_source](#decor_param_source)

@source

(id, default, options, title, group, show\_if, tooltip) -> None

Declares a source input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

indie.source

default:
source.CLOSE

Default value for the parameter in settings pane.

options

indie.Optional\[list\[indie.source]]

default:
None

List of the possible values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.source('src', default=source.CLOSE, options=[source.CLOSE, source.HL2, source.HLC3, source.OHLC4])
def Main(self, src):
    # Use src variable...
```

> [!NOTE]
>
> 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.

> [!NOTE]
>
> See also: [`param`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_param)[`source`](https://takeprofit.com/docs/indie/Library-reference/package-indie#enum_source)

[Navigate to decor\_param\_time\_frame](#decor_param_time_frame)

@time\_frame

(id, default, options, title, group, show\_if, tooltip) -> None

Declares a time frame input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

str

required

Default value for the parameter in settings pane.

options

indie.Optional\[list\[str]]

default:
None

List of the possible values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.time_frame('time_frame', default='1s', options=['1s', '5s', '1m', '30m'])
def Main(self, time_frame):
    # Use time_frame variable...
```

> [!NOTE]
>
> The type of `time_frame` in the example variable will be `TimeFrame`. But please note, that for the convenience, default value has `str` type. String representation of `TimeFrame` has a form of `<number>[s|m|h|D|W|M|Y]` where suffixes mean: `s` - seconds, `m` - minutes, `h` - hours, `D` - days, `W` - weeks, `M` - months, `Y` - years. Seconds (`s`) are supported. Without `options`, Settings includes 1s, 3s, 5s, 10s, 15s, 30s, 45s and the existing minute-or-larger values. If `options` parameter is used then in Settings panel there will be a combobox widget for changing value of this input.

> [!NOTE]
>
> See also: [`TimeFrame`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_TimeFrame)

[Navigate to decor\_param\_calc\_time\_frame](#decor_param_calc_time_frame)

@calc\_time\_frame

(id, default, options, title, count\_param, auto, extended\_hours, extended\_hours\_param, group, show\_if, tooltip) -> None

Declares the indicator calculation timeframe parameter. Unlike `@param.time_frame`, it sets the main calculation timeframe for the indicator run independently of the chart timeframe (for example, `1D` for Session Volume Profile or TPO).

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

indie.Optional\[str]

default:
None

Default value for the parameter in settings pane.

options

indie.Optional\[list\[str]]

default:
None

List of the possible values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

count\_param

indie.Optional\[str]

default:
None

Optional integer parameter ID that multiplies the selected calculation timeframe.

auto

indie.Optional\[dict\[int, str]]

default:
None

Optional mapping from minimum chart bar duration in seconds (starting at `0`) to automatic calculation timeframe strings.

extended\_hours

indie.Optional\[bool]

default:
None

Fixed extended-hours flag for the calculation timeframe; mutually exclusive with `extended_hours_param`.

extended\_hours\_param

indie.Optional\[str]

default:
None

Optional boolean parameter ID controlling extended hours for the calculation timeframe; mutually exclusive with `extended_hours`.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

@calc\_time\_frame

(id, default, options, title, count\_param, auto, extended\_hours, extended\_hours\_param, group, show\_if, tooltip) -> None

Declares the indicator calculation timeframe parameter. Unlike `@param.time_frame`, it sets the main calculation timeframe for the indicator run independently of the chart timeframe (for example, `1D` for Session Volume Profile or TPO).

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

indie.Optional\[str]

default:
None

Default value for the parameter in settings pane.

options

indie.Optional\[dict\[str, str]]

default:
None

List of the possible values of the parameter.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

count\_param

indie.Optional\[str]

default:
None

Optional integer parameter ID that multiplies the selected calculation timeframe.

auto

indie.Optional\[dict\[int, str]]

default:
None

Optional mapping from minimum chart bar duration in seconds (starting at `0`) to automatic calculation timeframe strings.

extended\_hours

indie.Optional\[bool]

default:
None

Fixed extended-hours flag for the calculation timeframe; mutually exclusive with `extended_hours_param`.

extended\_hours\_param

indie.Optional\[str]

default:
None

Optional boolean parameter ID controlling extended hours for the calculation timeframe; mutually exclusive with `extended_hours`.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

[Navigate to decor\_param\_color](#decor_param_color)

@color

(id, default, title, group, show\_if, tooltip) -> None

Declares a color input parameter of indicator. Values of input parameters can be changed in indicator's Settings panel. Input parameters are used in combination with corresponding parameter declaration in `Main` entry point.

**parameters info**

id

str

required

Name of `Main` function or class parameter bound to the input parameter.

default

indie.Color

required

Default value for the parameter in settings pane.

title

indie.Optional\[str]

default:
None

Human readable title which is visible in the indicator's Settings panel.

group

indie.Optional\[str]

default:
None

Title of the collapsible section of the indicator's Settings panel that shows the parameter. Parameters with the same `group` are shown together; parameters without a group are shown first. Must be a non-empty string of at most 64 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed. `Strategy Settings` and `Backtesting Settings` are reserved regardless of letter case and extra spaces. See `param` for the order of sections.

show\_if

indie.Optional\[str]

default:
None

Shows the parameter in the indicator's Settings panel only while another parameter has a given value; the parameter keeps its value while hidden. Forms: `'flag'` or `'not flag'`, where `flag` is a `param.bool`; `'mode == A'` or `'mode != A'`, where `mode` is a `param.str` with `options` and `A` is one of them (list several as `'mode == A | B'`). The referenced parameter can have its own `show_if`; then the parameter is shown only while that one is shown too.

tooltip

indie.Optional\[str]

default:
None

Help text shown next to the parameter's title in the indicator's Settings panel, for example what the parameter does or how its options differ. Must be a non-empty string of at most 512 printable characters (no line breaks, tabs or zero-width characters); leading and trailing spaces are removed.

```py Example theme={null}
@param.color('my_color', default=color.BLUE)
def Main(self, my_color):
    # Use my_color variable...
```

> [!NOTE]
>
> The type of `my_color` in the example variable will be `Color`

> [!NOTE]
>
> See also: [`Color`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Color)

```py Example theme={null}
MS = 'Market structure'

@indicator('Grouped inputs example', overlay_main_pane=True)
@param.int('length', default=20, min=1, tooltip='Number of bars in the moving average')
@param.bool('show_internal', default=True, title='Internal', group=MS)
@param.int('internal_length', default=5, min=2, title='Internal length', group=MS)
@param.color('bull_color', default=color.GREEN, title='Bullish', group='Colors')
@param.color('bear_color', default=color.RED, title='Bearish', group='Colors')
def Main(self, length, show_internal, internal_length, bull_color, bear_color):
    # Use input parameters...
```

> [!NOTE]
>
> Every `@param.*` decorator accepts an optional `group` argument. Parameters with the same `group` are shown together in a collapsible section of the indicator's Settings panel titled with the group name. Parameters without a group are shown first, then the sections in the order in which their groups first appear in the decorators, from top to bottom. In the example, `length` is shown first, then the `Market structure` section, then the `Colors` section. The names `Strategy Settings` and `Backtesting Settings` are reserved for the built-in settings of strategies. Every `@param.*` decorator also accepts an optional `tooltip`: a help text shown next to the parameter's title.

***

### `@sec_context()`

*decorator*

**1. Overloads**

@sec\_context

() -> None

Decorates a function, making it a secondary `Main` entry point for additional instrument of an indicator. Additional instruments are requested with the help of `Context.calc_on` function and this decorator.

```py Example theme={null}
# indie:lang_version = 5
from indie import indicator, sec_context, param

@sec_context
def Main2(self):
    return self.high[0], self.low[0]

@indicator('Minimal calc_on example', overlay_main_pane=True)
@param.time_frame('sec_time_frame', default='1D')
class Main(MainContext):
    def __init__(self, sec_time_frame):
        self._sec_high, self._sec_low = self.calc_on(time_frame=sec_time_frame, sec_context=Main2)

    def calc(self):
        return self._sec_high[0], self._sec_low[0]
```

> [!NOTE]
>
> More info on this topic you can find in [Request additional instruments](https://takeprofit.com/docs/indie/Request-additional-instruments.md) chapter.

> [!NOTE]
>
> See also: [`@indicator()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_indicator)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)[`Context.calc_on()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_calc_on)

***

### `@strategy()`

*decorator*

**1. Overloads**

@strategy

(abbrev\_title, \*, overlay\_main\_pane, format, precision, initial\_capital, commission, leverage, intrabar\_order\_filter, market\_order\_price, risk\_free\_rate) -> None

Decorator that marks a function as a trading strategy. Configures backtesting parameters including initial capital, commission, leverage, and order execution settings. The decorated function receives a `MainStrategyContext` object with access to trading operations.

**parameters info**

abbrev\_title

str

required

Abbreviated title of the indicator.

overlay\_main\_pane

bool

default:
False

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

indie.format

default:
indie.format.INHERITED

Formatting style of indicator output values represented as enum value of type `format`.

precision

indie.Optional\[int]

default:
None

Number of digits after floating point for indicator output values.

initial\_capital

float

default:
1000000.0

Starting capital amount for the strategy backtest. Default is `1000000.0`.

commission

indie.strategies.Commission

default:
indie.strategies.Commission(0.0, indie.strategies.commission\_type.PERCENT)

Commission settings applied to all trades. Default is zero commission.

leverage

float

default:
1.0

Leverage multiplier for the strategy. Values greater than 1.0 allow trading with borrowed capital. Default is `1.0` (no leverage).

intrabar\_order\_filter

indie.strategies.intrabar\_order\_filter

default:
indie.strategies.intrabar\_order\_filter.ON\_BAR\_CLOSE

Determines when orders are executed within a bar during backtesting. Default is `ON_BAR_CLOSE`.

market\_order\_price

indie.strategies.market\_order\_price

default:
indie.strategies.market\_order\_price.MARKET\_PRICE

Price used for market order execution in backtesting. Default is `MARKET_PRICE`.

risk\_free\_rate

float

default:
0.02

Annual risk-free rate used for calculating strategy performance metrics like Sharpe ratio. Default is `0.02` (2%).

***

## Functions

### `request_series()`

*function*

**1. Overloads**

request\_series

(data\_class, source, time\_frame, lookahead) -> indie.RequestedSeries\[T]

Requests a typed series of rows from an external data source without a callback. Returns `RequestedSeries[T]` with an explicit `time_frame`, otherwise `Series[T]`. `T` is the dataclass given as the type argument; on each bar, offset `[0]` is the latest external row with a timestamp at or before that bar. Must be called in the subscript form `request_series[YourDataClass](...)` from an `__init__` constructor method.

**parameters info**

data\_class

T

required

Type argument of `request_series[T](...)`: a custom `@dataclass` for external rows, or the fixed DTO required by a built-in source.

source

indie.Optional\[indie.data.sources.IExternalSource]

required

Typed source descriptor, e.g. `sources.Csv`, `sources.DataFeed`, `sources.Tpo`, `sources.VolumeFootprint`, or `sources.OrderBook`.

time\_frame

indie.Optional\[indie.TimeFrame]

default:
None

Time frame of the requested series. Custom external rows may omit it for event data; built-in profile sources require it.

lookahead

bool

default:
False

If this flag is true, an external row on its own time frame becomes visible from the bar where it opens instead of the bar where it closes. Such a data merge strategy may result in unintended use of data from future history. Requires an explicit `time_frame`.

```py Example theme={null}
# indie:lang_version = 5
from dataclasses import dataclass
from indie import indicator, MainContext, request_series
from indie.data import sources

@dataclass
class RiskFactor:
    value: float

@indicator('Risk-adjusted close')
class Main(MainContext):
    def __init__(self):
        self._risk = request_series[RiskFactor](
            source=sources.Csv('https://example.com/risk.csv'))

    def calc(self):
        row = self._risk.get(0, RiskFactor(1.0))
        return self.close[0] * row.value
```

> [!NOTE]
>
> On chart bars before the first external row, reading with `[0]` raises an error; use `.get(0, default)` with a default row during warm-up. More info on this topic you can find in [Typed external data](https://takeprofit.com/docs/indie/External-data/Typed-external-data.md) chapter.

> [!NOTE]
>
> See also: [`@data_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_data_context)[`Csv`](https://takeprofit.com/docs/indie/Library-reference/package-indie-data-sources#class_Csv)

***

## Types

### `Algorithm`

*type*

Base class for the classes that perform some processing of series data.

**1. Fields**

[Navigate to field\_Algorithm\_ctx](#field_Algorithm_ctx)

ctx

indie.Context

Represents context of an instrument which is currently bound to this algorithm instance. An indicator has at least one instrument — the main instrument of a chart where the indicator was added to. Besides the main instrument an indicator may have several additional instruments, which is done with the help of `Context.calc_on` function.

**2. Methods**

[Navigate to method\_Algorithm\_init](#method_Algorithm_init)

**init**

(ctx) -> None

Class constructor (initializer for the data type).

**parameters info**

ctx

indie.Context

required

Context object.

> [!NOTE]
>
> See also: [`@algorithm()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_algorithm)[`MainContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MainContext)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)

***

### `Color`

*type*

Data type to represent color.

**1. Methods**

[Navigate to method\_Color\_call](#method_Color_call)

**call**

(alpha) -> indie.Color

Creates a new Color instance with the given transparency applied to the existing color.

**parameters info**

alpha

float

required

Alpha channel (component) of color which ranges from `0.0` (fully transparent) to `1.0` (fully opaque).

```py Example theme={null}
half_transparent_red = color.RED(0.5)  # This implicitly calls `color.RED.__call__(0.5)`
```

> [!NOTE]
>
> Method `__call__` should never be called directly, instead `color_obj(value)` syntax should be used.

> [!NOTE]
>
> See also: [`color`](https://takeprofit.com/docs/indie/Library-reference/package-indie-color)

***

### `Context`

*type*

Data type that represents an instrument with OHLCV series values and other related information.

**1. Fields**

[Navigate to field\_Context\_time](#field_Context_time)

time

indie.Series\[float]

Series of timestamps (as unix time UTC seconds) of the context's instrument. Every timestamp corresponds to start time of some bar on a chart.

[Navigate to field\_Context\_open](#field_Context_open)

open

indie.Series\[float]

Series of 'open' prices of the context's instrument.

[Navigate to field\_Context\_high](#field_Context_high)

high

indie.Series\[float]

Series of 'high' prices of the context's instrument.

[Navigate to field\_Context\_low](#field_Context_low)

low

indie.Series\[float]

Series of 'low' prices of the context's instrument.

[Navigate to field\_Context\_close](#field_Context_close)

close

indie.Series\[float]

Series of 'close' prices of the context's instrument.

[Navigate to field\_Context\_volume](#field_Context_volume)

volume

indie.Series\[float]

Series of 'volume' values of the context's instrument.

[Navigate to field\_Context\_hl2](#field_Context_hl2)

hl2

indie.Series\[float]

Series of '(high + low) / 2' values of the context's instrument.

[Navigate to field\_Context\_hlc3](#field_Context_hlc3)

hlc3

indie.Series\[float]

Series of '(high + low + close) / 3' values of the context's instrument.

[Navigate to field\_Context\_ohlc4](#field_Context_ohlc4)

ohlc4

indie.Series\[float]

Series of '(open + high + low + close) / 4' values of the context's instrument.

[Navigate to field\_Context\_info](#field_Context_info)

info

indie.SymbolInfo

Information about the context's instrument.

[Navigate to field\_Context\_bar\_index](#field_Context_bar_index)

bar\_index

int

Index of a last (current) bar in this context's instrument which the indicator has received. The very first bar has index equal to `0` and this is the oldest bar.

[Navigate to field\_Context\_bar\_count](#field_Context_bar_count)

bar\_count

int

Current total number of bars in this context's instrument which the indicator has received. It is always true that `self.bar_count` is equal to `self.bar_index + 1`.

[Navigate to field\_Context\_is\_closed\_bar](#field_Context_is_closed_bar)

is\_closed\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.

[Navigate to field\_Context\_is\_history](#field_Context_is_history)

is\_history

bool

Flag that is `True` if the current bar is a historical bar.

[Navigate to field\_Context\_is\_last\_bar](#field_Context_is_last_bar)

is\_last\_bar

bool

Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.

[Navigate to field\_Context\_is\_last\_history\_bar](#field_Context_is_last_history_bar)

is\_last\_history\_bar

bool

Flag that is `True` if the current bar is the last bar of the historical part of prices data.

[Navigate to field\_Context\_last\_bar\_time](#field_Context_last_bar_time)

last\_bar\_time

float

Timestamp (as unix time UTC seconds) of the last bar of the context's instrument. It is known on every historical bar, so a historical bar can be compared with the end of the data. In realtime it is the time of the current realtime bar.

```py Example theme={null}
# indie:lang_version = 5
from indie import indicator, color, plot

@indicator('Last day', overlay_main_pane=True)
@plot.bar_color()
def Main(self):
    last_day_start = self.last_bar_time // 86400 * 86400
    if self.time[0] >= last_day_start:
        return plot.BarColor(color=color.YELLOW)
    return plot.BarColor()
```

> [!NOTE]
>
> Bars that were calculated before a new realtime bar arrived are not recalculated. If the day changes while the chart is open, bars of the previous day keep their color until the indicator is calculated again. In a secondary context created with `Context.calc_on` it is the time of the last bar of that context.

> [!NOTE]
>
> See also: [`Context.time`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_time)[`Context.is_last_bar`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_is_last_bar)

[Navigate to field\_Context\_is\_new\_bar](#field_Context_is_new_bar)

is\_new\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.

[Navigate to field\_Context\_is\_realtime](#field_Context_is_realtime)

is\_realtime

bool

Flag that is `True` if the last (current) bar is a realtime bar.

[Navigate to field\_Context\_time\_frame](#field_Context_time_frame)

time\_frame

indie.TimeFrame

Time frame of the context's instrument.

[Navigate to field\_Context\_trading\_session](#field_Context_trading_session)

trading\_session

indie.TradingSession

Trading session of the context's instrument.

**2. Methods**

[Navigate to method\_Context\_calc\_on](#method_Context_calc_on)

calc\_on

(sec\_context, exchange, ticker, time\_frame, \*, source, lookahead) -> indie.SeriesF | tuple\[indie.SeriesF, ...]

Requests additional instrument (creates a secondary context object for it) for indicator and returns one or more `SeriesF` objects which match with the arity of values that `sec_context` function returns. All the returned series values are merged into the timescale of current context's instrument.

**parameters info**

sec\_context

typing.Any

required

Function decorated with `@indie.sec_context`. This function has the same semantics as Indie `Main`, but for additional instrument (not the main one).

exchange

indie.Optional\[str]

default:
None

Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.

ticker

indie.Optional\[str]

default:
None

Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.

time\_frame

indie.Optional\[indie.TimeFrame]

default:
None

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. For an external candle source (a `@sec_context` callback with the `source` argument) `time_frame` is required and must match the cadence of the rows in the file.

source

indie.Optional\[indie.data.sources.IExternalSource]

default:
None

External data source descriptor, e.g. `indie.data.sources.Csv`. Mutually exclusive with `exchange` and `ticker`. With a `@sec_context` callback (external candles) an explicit `time_frame` is required.

lookahead

bool

default:
False

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. With an external `source`, `lookahead=True` requires an explicit `time_frame`.

> [!NOTE]
>
> For a market instrument at least one of optional arguments (`exchange`, `ticker` or `time_frame`) must be provided. More info about this function as well as code examples you may find in [Request additional instruments](https://takeprofit.com/docs/indie/Request-additional-instruments.md) chapter.

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)

[Navigate to method\_Context\_new\_mut\_series\_f](#method_Context_new_mut_series_f)

new\_mut\_series\_f

(default, size) -> indie.MutSeries\[float]

Creates a `MutSeriesF` (an alias for `MutSeries[float]`) object, which is a container for `float` values in Indie code. The main feature of the `MutSeriesF` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

indie.Optional\[float]

default:
None

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeriesF` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`MutSeriesF`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeriesF)

[Navigate to method\_Context\_new\_mut\_series](#method_Context_new_mut_series)

new\_mut\_series

(default, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

[Navigate to method\_Context\_new\_var](#method_Context_new_var)

new\_var

(init) -> indie.Var\[T]

Creates a `Var[T]` object, which is a container for `T` value in Indie code. The main feature of the `Var[T]` container is its ability to rollback the value of the variable when a new realtime update appears to its value after the previous bar.

**parameters info**

init

T

required

Value that is written into `Var` object only once after the `Var` object was created.

[Navigate to method\_Context\_is\_first\_in\_session](#method_Context_is_first_in_session)

is\_first\_in\_session

() -> bool

Detects whether the current bar is the first bar of a new trading session (extended session included). Returns `True` if the current bar is the first bar of the trading session or `False` if the current bar is not the first in the session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the session does not exist or is unavailable (e.g., due to data gaps or missing information).

[Navigate to method\_Context\_is\_first\_in\_regular\_session](#method_Context_is_first_in_regular_session)

is\_first\_in\_regular\_session

() -> bool

Detects whether the current bar is the first bar of the regular trading session (excluding pre-market session). Returns `True` if the current bar is the first bar of the regular trading session or `False` if the current bar is not the first in the regular session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the regular session does not exist or is unavailable (e.g., due to data gaps or missing information).

[Navigate to method\_Context\_is\_last\_in\_session](#method_Context_is_last_in_session)

is\_last\_in\_session

() -> bool

Detects whether the current bar is the last bar of the trading session (extended session included). Returns `True` if the current bar is the last bar of the trading session or `False` if the current bar is not the last in the session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

[Navigate to method\_Context\_is\_last\_in\_regular\_session](#method_Context_is_last_in_regular_session)

is\_last\_in\_regular\_session

() -> bool

Detects whether the current bar is the last bar of the regular trading session (excluding after-hours session). Returns `True` if the current bar is the last bar of the regular trading session or `False` if the current bar is not the last in the regular session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

> [!NOTE]
>
> See also: [`MainContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MainContext)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)[`SymbolInfo`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SymbolInfo)[`Series[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Series)[`MutSeries[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeries)[`TradingSession`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_TradingSession)

***

### `DataContext[T]`

*type*

Base class for typed external data contexts. Objects of this class are created by the `@data_context` decorator; the rows of the external data source are available via the `data` property. An external data source carries no candles, so candle members like `close` or `volume` are not available in a `DataContext`.

**1. Parent**

[`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)

**2. Fields**

[Navigate to field\_DataContext\_data](#field_DataContext_data)

data

indie.Series\[T]

Series of typed rows of the external data source, where `data[0]` is the current row. The row type is the dataclass given as the type argument of `@data_context`.

**3. Inherited fields**

time

indie.Series\[float]

Series of timestamps (as unix time UTC seconds) of the context's instrument. Every timestamp corresponds to start time of some bar on a chart.

open

indie.Series\[float]

Series of 'open' prices of the context's instrument.

high

indie.Series\[float]

Series of 'high' prices of the context's instrument.

low

indie.Series\[float]

Series of 'low' prices of the context's instrument.

close

indie.Series\[float]

Series of 'close' prices of the context's instrument.

volume

indie.Series\[float]

Series of 'volume' values of the context's instrument.

hl2

indie.Series\[float]

Series of '(high + low) / 2' values of the context's instrument.

hlc3

indie.Series\[float]

Series of '(high + low + close) / 3' values of the context's instrument.

ohlc4

indie.Series\[float]

Series of '(open + high + low + close) / 4' values of the context's instrument.

info

indie.SymbolInfo

Information about the context's instrument.

bar\_index

int

Index of a last (current) bar in this context's instrument which the indicator has received. The very first bar has index equal to `0` and this is the oldest bar.

bar\_count

int

Current total number of bars in this context's instrument which the indicator has received. It is always true that `self.bar_count` is equal to `self.bar_index + 1`.

is\_closed\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.

is\_history

bool

Flag that is `True` if the current bar is a historical bar.

is\_last\_bar

bool

Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.

is\_last\_history\_bar

bool

Flag that is `True` if the current bar is the last bar of the historical part of prices data.

last\_bar\_time

float

Timestamp (as unix time UTC seconds) of the last bar of the context's instrument. It is known on every historical bar, so a historical bar can be compared with the end of the data. In realtime it is the time of the current realtime bar.

```py Example theme={null}
# indie:lang_version = 5
from indie import indicator, color, plot

@indicator('Last day', overlay_main_pane=True)
@plot.bar_color()
def Main(self):
    last_day_start = self.last_bar_time // 86400 * 86400
    if self.time[0] >= last_day_start:
        return plot.BarColor(color=color.YELLOW)
    return plot.BarColor()
```

> [!NOTE]
>
> Bars that were calculated before a new realtime bar arrived are not recalculated. If the day changes while the chart is open, bars of the previous day keep their color until the indicator is calculated again. In a secondary context created with `Context.calc_on` it is the time of the last bar of that context.

> [!NOTE]
>
> See also: [`Context.time`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_time)[`Context.is_last_bar`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_is_last_bar)

is\_new\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.

is\_realtime

bool

Flag that is `True` if the last (current) bar is a realtime bar.

time\_frame

indie.TimeFrame

Time frame of the context's instrument.

trading\_session

indie.TradingSession

Trading session of the context's instrument.

**4. Inherited methods**

calc\_on

(sec\_context, exchange, ticker, time\_frame, \*, source, lookahead) -> indie.SeriesF | tuple\[indie.SeriesF, ...]

Requests additional instrument (creates a secondary context object for it) for indicator and returns one or more `SeriesF` objects which match with the arity of values that `sec_context` function returns. All the returned series values are merged into the timescale of current context's instrument.

**parameters info**

sec\_context

typing.Any

required

Function decorated with `@indie.sec_context`. This function has the same semantics as Indie `Main`, but for additional instrument (not the main one).

exchange

indie.Optional\[str]

default:
None

Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.

ticker

indie.Optional\[str]

default:
None

Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.

time\_frame

indie.Optional\[indie.TimeFrame]

default:
None

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. For an external candle source (a `@sec_context` callback with the `source` argument) `time_frame` is required and must match the cadence of the rows in the file.

source

indie.Optional\[indie.data.sources.IExternalSource]

default:
None

External data source descriptor, e.g. `indie.data.sources.Csv`. Mutually exclusive with `exchange` and `ticker`. With a `@sec_context` callback (external candles) an explicit `time_frame` is required.

lookahead

bool

default:
False

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. With an external `source`, `lookahead=True` requires an explicit `time_frame`.

> [!NOTE]
>
> For a market instrument at least one of optional arguments (`exchange`, `ticker` or `time_frame`) must be provided. More info about this function as well as code examples you may find in [Request additional instruments](https://takeprofit.com/docs/indie/Request-additional-instruments.md) chapter.

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)

new\_mut\_series\_f

(default, size) -> indie.MutSeries\[float]

Creates a `MutSeriesF` (an alias for `MutSeries[float]`) object, which is a container for `float` values in Indie code. The main feature of the `MutSeriesF` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

indie.Optional\[float]

default:
None

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeriesF` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`MutSeriesF`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeriesF)

new\_mut\_series

(default, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

new\_var

(init) -> indie.Var\[T]

Creates a `Var[T]` object, which is a container for `T` value in Indie code. The main feature of the `Var[T]` container is its ability to rollback the value of the variable when a new realtime update appears to its value after the previous bar.

**parameters info**

init

T

required

Value that is written into `Var` object only once after the `Var` object was created.

is\_first\_in\_session

() -> bool

Detects whether the current bar is the first bar of a new trading session (extended session included). Returns `True` if the current bar is the first bar of the trading session or `False` if the current bar is not the first in the session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_first\_in\_regular\_session

() -> bool

Detects whether the current bar is the first bar of the regular trading session (excluding pre-market session). Returns `True` if the current bar is the first bar of the regular trading session or `False` if the current bar is not the first in the regular session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the regular session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_last\_in\_session

() -> bool

Detects whether the current bar is the last bar of the trading session (extended session included). Returns `True` if the current bar is the last bar of the trading session or `False` if the current bar is not the last in the session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

is\_last\_in\_regular\_session

() -> bool

Detects whether the current bar is the last bar of the regular trading session (excluding after-hours session). Returns `True` if the current bar is the last bar of the regular trading session or `False` if the current bar is not the last in the regular session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

> [!NOTE]
>
> See also: [`@data_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_data_context)[`Context.calc_on()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_calc_on)

***

### `IndieError`

*type*

Data type for Indie errors.

**1. Methods**

[Navigate to method\_IndieError\_init](#method_IndieError_init)

**init**

(msg) -> None

Class constructor (initializer for the data type).

**parameters info**

msg

str

required

Error message.

***

### `MainContext`

*type*

Base class for the class that represents main context.

**1. Parent**

[`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)

**2. Fields**

[Navigate to field\_MainContext\_chart](#field_MainContext_chart)

chart

indie.drawings.Chart

Chart object for drawing and managing non-series visual elements.

[Navigate to field\_MainContext\_extended\_hours](#field_MainContext_extended_hours)

extended\_hours

bool

Whether the main chart requests pre-market or post-market data. Read-only.

**3. Inherited fields**

time

indie.Series\[float]

Series of timestamps (as unix time UTC seconds) of the context's instrument. Every timestamp corresponds to start time of some bar on a chart.

open

indie.Series\[float]

Series of 'open' prices of the context's instrument.

high

indie.Series\[float]

Series of 'high' prices of the context's instrument.

low

indie.Series\[float]

Series of 'low' prices of the context's instrument.

close

indie.Series\[float]

Series of 'close' prices of the context's instrument.

volume

indie.Series\[float]

Series of 'volume' values of the context's instrument.

hl2

indie.Series\[float]

Series of '(high + low) / 2' values of the context's instrument.

hlc3

indie.Series\[float]

Series of '(high + low + close) / 3' values of the context's instrument.

ohlc4

indie.Series\[float]

Series of '(open + high + low + close) / 4' values of the context's instrument.

info

indie.SymbolInfo

Information about the context's instrument.

bar\_index

int

Index of a last (current) bar in this context's instrument which the indicator has received. The very first bar has index equal to `0` and this is the oldest bar.

bar\_count

int

Current total number of bars in this context's instrument which the indicator has received. It is always true that `self.bar_count` is equal to `self.bar_index + 1`.

is\_closed\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.

is\_history

bool

Flag that is `True` if the current bar is a historical bar.

is\_last\_bar

bool

Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.

is\_last\_history\_bar

bool

Flag that is `True` if the current bar is the last bar of the historical part of prices data.

last\_bar\_time

float

Timestamp (as unix time UTC seconds) of the last bar of the context's instrument. It is known on every historical bar, so a historical bar can be compared with the end of the data. In realtime it is the time of the current realtime bar.

```py Example theme={null}
# indie:lang_version = 5
from indie import indicator, color, plot

@indicator('Last day', overlay_main_pane=True)
@plot.bar_color()
def Main(self):
    last_day_start = self.last_bar_time // 86400 * 86400
    if self.time[0] >= last_day_start:
        return plot.BarColor(color=color.YELLOW)
    return plot.BarColor()
```

> [!NOTE]
>
> Bars that were calculated before a new realtime bar arrived are not recalculated. If the day changes while the chart is open, bars of the previous day keep their color until the indicator is calculated again. In a secondary context created with `Context.calc_on` it is the time of the last bar of that context.

> [!NOTE]
>
> See also: [`Context.time`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_time)[`Context.is_last_bar`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_is_last_bar)

is\_new\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.

is\_realtime

bool

Flag that is `True` if the last (current) bar is a realtime bar.

time\_frame

indie.TimeFrame

Time frame of the context's instrument.

trading\_session

indie.TradingSession

Trading session of the context's instrument.

**4. Methods**

[Navigate to method\_MainContext\_get\_profile\_series](#method_MainContext_get_profile_series)

get\_profile\_series

(id) -> indie.ProfileSeries

Returns the declared `ProfileSeries` handle by id.

**parameters info**

id

str

required

Unique output ID declared by a profile plot decorator.

**5. Inherited methods**

calc\_on

(sec\_context, exchange, ticker, time\_frame, \*, source, lookahead) -> indie.SeriesF | tuple\[indie.SeriesF, ...]

Requests additional instrument (creates a secondary context object for it) for indicator and returns one or more `SeriesF` objects which match with the arity of values that `sec_context` function returns. All the returned series values are merged into the timescale of current context's instrument.

**parameters info**

sec\_context

typing.Any

required

Function decorated with `@indie.sec_context`. This function has the same semantics as Indie `Main`, but for additional instrument (not the main one).

exchange

indie.Optional\[str]

default:
None

Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.

ticker

indie.Optional\[str]

default:
None

Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.

time\_frame

indie.Optional\[indie.TimeFrame]

default:
None

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. For an external candle source (a `@sec_context` callback with the `source` argument) `time_frame` is required and must match the cadence of the rows in the file.

source

indie.Optional\[indie.data.sources.IExternalSource]

default:
None

External data source descriptor, e.g. `indie.data.sources.Csv`. Mutually exclusive with `exchange` and `ticker`. With a `@sec_context` callback (external candles) an explicit `time_frame` is required.

lookahead

bool

default:
False

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. With an external `source`, `lookahead=True` requires an explicit `time_frame`.

> [!NOTE]
>
> For a market instrument at least one of optional arguments (`exchange`, `ticker` or `time_frame`) must be provided. More info about this function as well as code examples you may find in [Request additional instruments](https://takeprofit.com/docs/indie/Request-additional-instruments.md) chapter.

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)

new\_mut\_series\_f

(default, size) -> indie.MutSeries\[float]

Creates a `MutSeriesF` (an alias for `MutSeries[float]`) object, which is a container for `float` values in Indie code. The main feature of the `MutSeriesF` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

indie.Optional\[float]

default:
None

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeriesF` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`MutSeriesF`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeriesF)

new\_mut\_series

(default, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

new\_var

(init) -> indie.Var\[T]

Creates a `Var[T]` object, which is a container for `T` value in Indie code. The main feature of the `Var[T]` container is its ability to rollback the value of the variable when a new realtime update appears to its value after the previous bar.

**parameters info**

init

T

required

Value that is written into `Var` object only once after the `Var` object was created.

is\_first\_in\_session

() -> bool

Detects whether the current bar is the first bar of a new trading session (extended session included). Returns `True` if the current bar is the first bar of the trading session or `False` if the current bar is not the first in the session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_first\_in\_regular\_session

() -> bool

Detects whether the current bar is the first bar of the regular trading session (excluding pre-market session). Returns `True` if the current bar is the first bar of the regular trading session or `False` if the current bar is not the first in the regular session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the regular session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_last\_in\_session

() -> bool

Detects whether the current bar is the last bar of the trading session (extended session included). Returns `True` if the current bar is the last bar of the trading session or `False` if the current bar is not the last in the session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

is\_last\_in\_regular\_session

() -> bool

Detects whether the current bar is the last bar of the regular trading session (excluding after-hours session). Returns `True` if the current bar is the last bar of the regular trading session or `False` if the current bar is not the last in the regular session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

> [!NOTE]
>
> See also: [`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)[`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)[`Algorithm`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Algorithm)

***

### `MainStrategyContext`

*type*

Extended context object available in strategy functions decorated with `@strategy`. Inherits from `MainContext` and provides access to trading operations through the `trading()` method.

**1. Parent**

[`MainContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MainContext)

**2. Fields**

[Navigate to field\_MainStrategyContext\_trading](#field_MainStrategyContext_trading)

trading

indie.strategies.Trading

Property that returns the `Trading` object for executing trading operations such as creating, updating, and canceling orders. Also provides access to current position and account balance.

**3. Inherited fields**

chart

indie.drawings.Chart

Chart object for drawing and managing non-series visual elements.

extended\_hours

bool

Whether the main chart requests pre-market or post-market data. Read-only.

time

indie.Series\[float]

Series of timestamps (as unix time UTC seconds) of the context's instrument. Every timestamp corresponds to start time of some bar on a chart.

open

indie.Series\[float]

Series of 'open' prices of the context's instrument.

high

indie.Series\[float]

Series of 'high' prices of the context's instrument.

low

indie.Series\[float]

Series of 'low' prices of the context's instrument.

close

indie.Series\[float]

Series of 'close' prices of the context's instrument.

volume

indie.Series\[float]

Series of 'volume' values of the context's instrument.

hl2

indie.Series\[float]

Series of '(high + low) / 2' values of the context's instrument.

hlc3

indie.Series\[float]

Series of '(high + low + close) / 3' values of the context's instrument.

ohlc4

indie.Series\[float]

Series of '(open + high + low + close) / 4' values of the context's instrument.

info

indie.SymbolInfo

Information about the context's instrument.

bar\_index

int

Index of a last (current) bar in this context's instrument which the indicator has received. The very first bar has index equal to `0` and this is the oldest bar.

bar\_count

int

Current total number of bars in this context's instrument which the indicator has received. It is always true that `self.bar_count` is equal to `self.bar_index + 1`.

is\_closed\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.

is\_history

bool

Flag that is `True` if the current bar is a historical bar.

is\_last\_bar

bool

Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.

is\_last\_history\_bar

bool

Flag that is `True` if the current bar is the last bar of the historical part of prices data.

last\_bar\_time

float

Timestamp (as unix time UTC seconds) of the last bar of the context's instrument. It is known on every historical bar, so a historical bar can be compared with the end of the data. In realtime it is the time of the current realtime bar.

```py Example theme={null}
# indie:lang_version = 5
from indie import indicator, color, plot

@indicator('Last day', overlay_main_pane=True)
@plot.bar_color()
def Main(self):
    last_day_start = self.last_bar_time // 86400 * 86400
    if self.time[0] >= last_day_start:
        return plot.BarColor(color=color.YELLOW)
    return plot.BarColor()
```

> [!NOTE]
>
> Bars that were calculated before a new realtime bar arrived are not recalculated. If the day changes while the chart is open, bars of the previous day keep their color until the indicator is calculated again. In a secondary context created with `Context.calc_on` it is the time of the last bar of that context.

> [!NOTE]
>
> See also: [`Context.time`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_time)[`Context.is_last_bar`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_is_last_bar)

is\_new\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.

is\_realtime

bool

Flag that is `True` if the last (current) bar is a realtime bar.

time\_frame

indie.TimeFrame

Time frame of the context's instrument.

trading\_session

indie.TradingSession

Trading session of the context's instrument.

**4. Inherited methods**

get\_profile\_series

(id) -> indie.ProfileSeries

Returns the declared `ProfileSeries` handle by id.

**parameters info**

id

str

required

Unique output ID declared by a profile plot decorator.

calc\_on

(sec\_context, exchange, ticker, time\_frame, \*, source, lookahead) -> indie.SeriesF | tuple\[indie.SeriesF, ...]

Requests additional instrument (creates a secondary context object for it) for indicator and returns one or more `SeriesF` objects which match with the arity of values that `sec_context` function returns. All the returned series values are merged into the timescale of current context's instrument.

**parameters info**

sec\_context

typing.Any

required

Function decorated with `@indie.sec_context`. This function has the same semantics as Indie `Main`, but for additional instrument (not the main one).

exchange

indie.Optional\[str]

default:
None

Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.

ticker

indie.Optional\[str]

default:
None

Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.

time\_frame

indie.Optional\[indie.TimeFrame]

default:
None

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. For an external candle source (a `@sec_context` callback with the `source` argument) `time_frame` is required and must match the cadence of the rows in the file.

source

indie.Optional\[indie.data.sources.IExternalSource]

default:
None

External data source descriptor, e.g. `indie.data.sources.Csv`. Mutually exclusive with `exchange` and `ticker`. With a `@sec_context` callback (external candles) an explicit `time_frame` is required.

lookahead

bool

default:
False

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. With an external `source`, `lookahead=True` requires an explicit `time_frame`.

> [!NOTE]
>
> For a market instrument at least one of optional arguments (`exchange`, `ticker` or `time_frame`) must be provided. More info about this function as well as code examples you may find in [Request additional instruments](https://takeprofit.com/docs/indie/Request-additional-instruments.md) chapter.

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)

new\_mut\_series\_f

(default, size) -> indie.MutSeries\[float]

Creates a `MutSeriesF` (an alias for `MutSeries[float]`) object, which is a container for `float` values in Indie code. The main feature of the `MutSeriesF` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

indie.Optional\[float]

default:
None

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeriesF` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`MutSeriesF`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeriesF)

new\_mut\_series

(default, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

new\_var

(init) -> indie.Var\[T]

Creates a `Var[T]` object, which is a container for `T` value in Indie code. The main feature of the `Var[T]` container is its ability to rollback the value of the variable when a new realtime update appears to its value after the previous bar.

**parameters info**

init

T

required

Value that is written into `Var` object only once after the `Var` object was created.

is\_first\_in\_session

() -> bool

Detects whether the current bar is the first bar of a new trading session (extended session included). Returns `True` if the current bar is the first bar of the trading session or `False` if the current bar is not the first in the session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_first\_in\_regular\_session

() -> bool

Detects whether the current bar is the first bar of the regular trading session (excluding pre-market session). Returns `True` if the current bar is the first bar of the regular trading session or `False` if the current bar is not the first in the regular session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the regular session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_last\_in\_session

() -> bool

Detects whether the current bar is the last bar of the trading session (extended session included). Returns `True` if the current bar is the last bar of the trading session or `False` if the current bar is not the last in the session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

is\_last\_in\_regular\_session

() -> bool

Detects whether the current bar is the last bar of the regular trading session (excluding after-hours session). Returns `True` if the current bar is the last bar of the regular trading session or `False` if the current bar is not the last in the regular session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

***

### `MutSeries[T]`

*type*

Generic data type that represents read-write series of values of type `T`. Type `T` can be float, int, str, or almost any other type.

**1. Aliases**

```py theme={null}
MutSeriesF = MutSeries[float]
```

**2. Parent**

[`Series[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Series)

**3. Methods**

[Navigate to method\_MutSeries\_setitem](#method_MutSeries_setitem)

**setitem**

(i, x) -> None

Sets value of `MutSeries[T]` object at the specified index.

**parameters info**

i

int

required

Index to assign value at.

x

T

required

New value.

```py Example theme={null}
ms = MutSeries[float].new(init=0)
ms[0] = 42  # This implicitly calls `ms.__setitem__(0, 42)`
```

> [!NOTE]
>
> (1) The index must be equal to 0 (because historical values cannot be updated), otherwise the function will raise an error at runtime. Yes, this looks very weird and maybe it would be much better just to have a method `MutSeriesF.set_last(value: float)` but we like the syntax of square brackets. Maybe this will be fixed in the future versions of Indie, hard to say for sure. (2) Method `__setitem__` should never be called directly, instead syntax `series_obj[index] = value` should be used.

[Navigate to method\_MutSeries\_calc](#method_MutSeries_calc)

calc

(reset, init, size) -> indie.MutSeries\[T]

Recalculates a `MutSeries[T]` object. In most cases, you can simply use the `s[i] = ...` syntax instead, but this method allows you to pass an initialization value to the series.

**parameters info**

reset

indie.Optional\[T]

default:
None

Value that is written into the most recent element of the `MutSeries` every time `MutSeries.new` function is executed.

init

indie.Optional\[T]

default:
None

Value that is written into the most recent element of the `MutSeries` object only once after the `MutSeries` object was created.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

**4. Static methods**

[Navigate to method\_MutSeries\_new](#method_MutSeries_new)

new

(reset, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

reset

T

required

Value that is written into the most recent element of the `MutSeries` every time `MutSeries.new` function is executed.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`Context.new_mut_series()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_new_mut_series)

new

(reset, init, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

reset

indie.Optional\[T]

default:
None

Value that is written into the most recent element of the `MutSeries` every time `MutSeries.new` function is executed.

init

indie.Optional\[T]

default:
None

Value that is written into the most recent element of the `MutSeries` object only once after the `MutSeries` object was created.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`Context.new_mut_series()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_new_mut_series)

**5. Inherited methods**

get

(offset, default, neg\_offset\_ok) -> T

Returns value of `Series[T]` object at the specified index or given `default` if the value is missing.

**parameters info**

offset

int

required

Offset to extract value at.

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

neg\_offset\_ok

bool

default:
False

If `False` then `get` method raises an error on any `offset < 0`. If `True` then `get` method returns `default` value on negative offsets too. Default value is `False`.

request\_size

(size) -> None

Expands the capacity of `Series[T]` object (number of elements that `Series[T]` object should store in memory).

**parameters info**

size

int

required

Number of elements that `SeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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.

set\_size

(size) -> None

Sets the exact number of values stored by a `Series[T]` object.

**parameters info**

size

int

required

Exact number of elements that `Series[T]` object should store in memory.

**getitem**

(i) -> T

Returns value of `Series[T]` object at the specified index. If the value is missing, then the default value of type `T` is returned (e.g. `math.nan` if `T` is float).

**parameters info**

i

int

required

Index to extract value at.

```py Example theme={null}
@indicator('Example')
def Main(self):
    return self.close[0]  # This implicitly calls `self.close.__getitem__(0)`
```

> [!NOTE]
>
> Method `__getitem__` should never be called directly. Instead syntax `series_obj[index]` should be used.

**len**

() -> int

Returns length (number of elements) of a `Series[T]` object.

```py Example theme={null}
l = len(self.close)  # this implicitly calls `self.close.__len__()`
```

> [!NOTE]
>
> Method `__len__` should never be called directly. Instead syntax `len(series_obj)` should be used.

> [!NOTE]
>
> See also: [`Context.new_mut_series()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_new_mut_series)[`Series[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Series)

***

### `Optional[T]`

*type*

Builtin Indie type (similar to Python's `typing.Optional`).

**1. Methods**

[Navigate to method\_Optional\_init](#method_Optional_init)

**init**

(value) -> None

Class constructor (initializer for the data type).

**parameters info**

value

T

required

Value to cast from.

**init**

() -> None

Class constructor (initializer for the data type).

[Navigate to method\_Optional\_value](#method_Optional_value)

value

() -> T

Returns value of `indie.Optional[T]` object. Raises a runtime error if the optional object is `None`.

[Navigate to method\_Optional\_value\_or](#method_Optional_value_or)

value\_or

(default) -> T

Returns value of `indie.Optional[T]` object or given `default` if the optional object is `None`.

**parameters info**

default

T

required

Default value that will be used if there is no value.

[Navigate to method\_Optional\_bool](#method_Optional_bool)

**bool**

() -> bool

Casts `Optional` object to bool.
\[!NOTE] This method is present for `Optional[T]` only if `T` can be converted to `bool`.

[Navigate to method\_Optional\_isnone](#method_Optional_isnone)

**isnone**

() -> bool

Returns `True` if the optional value is `None`, otherwise `False`.

```py Example theme={null}
my_val: Optional[int] = 4
my_bool = my_val is None
```

> [!NOTE]
>
> Method `__isnone__` should never be called directly, instead `val is None` syntax should be used.

***

### `ProfileSeries`

*type*

A declared price-histogram or TPO output with its own time intervals. Obtain it with `self.get_profile_series(id)` and publish data in `calc`; shared style defaults belong to its decorator.

**1. Methods**

[Navigate to method\_ProfileSeries\_set\_volume](#method_ProfileSeries_set_volume)

set\_volume

(profile, is\_closed, display\_to, merge\_rows\_on\_zoom, levels\_per\_row) -> None

Publishes a Volume Footprint profile. Declare two layers ordered Buy, Sell. Both sides are preserved in Total and Split display modes.

**parameters info**

profile

indie.data.VolumeFootprintProfile

required

Native VolumeFootprintProfile with real Buy/Sell volumes.

is\_closed

bool

default:
False

Whether this period is final. A closed item cannot change.

display\_to

indie.Optional\[float]

default:
None

Optional chart cutoff inside the interval; leaves the period identity and scheduled end unchanged.

merge\_rows\_on\_zoom

indie.Optional\[bool]

default:
None

Optional override for this profile; None keeps the user or decorator setting.

levels\_per\_row

int

default:
1

Number of source price levels per output row. Must be positive; 1 preserves the source grid. Larger values aggregate on a grid anchored at zero.

[Navigate to method\_ProfileSeries\_set\_tpo](#method_ProfileSeries_set_tpo)

set\_tpo

(profile, is\_closed, display\_to) -> None

Publishes a TPO profile with native block offsets, independent of chart bars.

**parameters info**

profile

indie.data.TpoProfile

required

Native TpoProfile with price occupancy and block offsets.

is\_closed

bool

default:
False

Whether this period is final. A closed item cannot change.

display\_to

indie.Optional\[float]

default:
None

Optional chart cutoff inside the interval; leaves the period identity and scheduled end unchanged.

[Navigate to method\_ProfileSeries\_set\_histogram](#method_ProfileSeries_set_histogram)

set\_histogram

(time\_from, time\_to, row\_size, prices, values, is\_closed, display\_to, merge\_rows\_on\_zoom) -> None

Replaces the current profile with price rows and their layer values. Missing rows have zero volume; an empty list represents a known empty profile.

**parameters info**

time\_from

float

required

UTC Unix seconds of the stable period start.

time\_to

float

required

Exclusive scheduled end; immutable for this key.

row\_size

float

required

Positive price height of each row.

prices

list\[float]

required

Increasing lower row edges on one price grid; gaps are allowed.

values

list\[list\[float]]

required

One list per price, with finite nonnegative values for every layer.

is\_closed

bool

default:
False

Whether this period is final. A closed item cannot change.

display\_to

indie.Optional\[float]

default:
None

Optional chart cutoff inside the interval; leaves the period identity and scheduled end unchanged.

merge\_rows\_on\_zoom

indie.Optional\[bool]

default:
None

Optional override for this profile; None keeps the user or decorator setting.

[Navigate to method\_ProfileSeries\_set\_cells](#method_ProfileSeries_set_cells)

set\_cells

(time\_from, time\_to, row\_size, column\_offsets, prices, column\_indexes, is\_closed, display\_to, poc\_price) -> None

Replaces the current TPO profile with columns and unique occupied price/column pairs.

**parameters info**

time\_from

float

required

UTC Unix seconds of the stable period start.

time\_to

float

required

Exclusive scheduled end; immutable for this key.

row\_size

float

required

Positive price height of each TPO row.

column\_offsets

list\[int]

required

Increasing nonnegative seconds from time\_from, inside the interval.

prices

list\[float]

required

Price of each occupied cell; same length as column\_indexes.

column\_indexes

list\[int]

required

Zero-based column index of each occupied cell.

is\_closed

bool

default:
False

Whether this period is final. A closed item cannot change.

display\_to

indie.Optional\[float]

default:
None

Optional chart cutoff inside the interval; leaves the period identity and scheduled end unchanged.

poc\_price

indie.Optional\[float]

default:
None

Known Point of Control price; None leaves it unavailable.

[Navigate to method\_ProfileSeries\_set\_no\_data](#method_ProfileSeries_set_no_data)

set\_no\_data

(time\_from, time\_to, is\_closed, display\_to) -> None

Marks an interval as unavailable. This differs from known zero volume or an empty history page.

**parameters info**

time\_from

float

required

UTC Unix seconds of the stable period start.

time\_to

float

required

Exclusive scheduled end; immutable for this key.

is\_closed

bool

default:
False

Whether this period is final. A closed item cannot change.

display\_to

indie.Optional\[float]

default:
None

Optional chart cutoff inside the interval; leaves the period identity and scheduled end unchanged.

> [!NOTE]
>
> Items are keyed by period start. A new period closes the previous item automatically. Closed items are immutable; intervals cannot overlap. Profiles do not consume calc return values.

***

### `RequestedSeries[T]`

*type*

A read-only Series\[T] returned by request\_series\[T] with an explicit timeframe, with access to source values inside a chart bar through subperiods.

**1. Parent**

[`Series[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Series)

**2. Methods**

[Navigate to method\_RequestedSeries\_request\_subperiods](#method_RequestedSeries_request_subperiods)

request\_subperiods

(size) -> None

Reserves source detail for size chart bars, including offsets that will be read conditionally.

**parameters info**

size

int

required

Number of chart bars of source detail to reserve.

> [!NOTE]
>
> Call on each calculation before conditional reads. For example, request\_subperiods(3) reserves offsets 0, 1 and 2 for the current chart position. The size must be positive and the detail must fit the subperiods budget. Increasing the reservation cannot recover discarded data; those intervals remain None.

> [!NOTE]
>
> See also: [`RequestedSeries[T].subperiods()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_RequestedSeries_subperiods)

[Navigate to method\_RequestedSeries\_subperiods](#method_RequestedSeries_subperiods)

subperiods

(offset) -> indie.Optional\[list\[T]]

Returns Optional\[List\[T]] containing source values fully inside a chart bar, ordered from oldest to newest. Read a present result with value().

**parameters info**

offset

int

default:
0

Chart-bar offset. Zero selects the current bar.

> [!NOTE]
>
> Available on RequestedSeries returned by request\_series with a timeframe. None means the requested interval is not known: it can precede coverage, extend beyond received source data, have been discarded, use a coarser source, or contain a profile crossing the chart boundary. An empty list means there are no source rows inside a gap within known history. Native VF and TPO coverage starts after the first profile, which may have been truncated upstream; coverage does not certify internal feed completeness. Native profiles use their actual boundaries, and cadence-based custom rows use their declared timeframe. An open bar contains only profiles received so far. Closing a chart bar does not close the independent source stream. Re-read earlier offsets when later source data arrives. Call request\_subperiods(n) on each calculation to reserve detail for n chart bars, including offsets used conditionally. Retention adapts to observed gaps up to a budget of 5000 source values and 250000 native profile elements, counting price rows, TPO blocks and block indexes. The element budget uses the largest accepted profile, so denser updates can exceed it. Exceeding the detail budget is an error: choose a coarser source timeframe explicitly. Equal timeframes have no finer intrabar path, and coarse detail can understate extrema.

> [!NOTE]
>
> See also: [`RequestedSeries[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_RequestedSeries)[`request_series()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#func_request_series)

**3. Inherited methods**

get

(offset, default, neg\_offset\_ok) -> T

Returns value of `Series[T]` object at the specified index or given `default` if the value is missing.

**parameters info**

offset

int

required

Offset to extract value at.

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

neg\_offset\_ok

bool

default:
False

If `False` then `get` method raises an error on any `offset < 0`. If `True` then `get` method returns `default` value on negative offsets too. Default value is `False`.

request\_size

(size) -> None

Expands the capacity of `Series[T]` object (number of elements that `Series[T]` object should store in memory).

**parameters info**

size

int

required

Number of elements that `SeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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.

set\_size

(size) -> None

Sets the exact number of values stored by a `Series[T]` object.

**parameters info**

size

int

required

Exact number of elements that `Series[T]` object should store in memory.

**getitem**

(i) -> T

Returns value of `Series[T]` object at the specified index. If the value is missing, then the default value of type `T` is returned (e.g. `math.nan` if `T` is float).

**parameters info**

i

int

required

Index to extract value at.

```py Example theme={null}
@indicator('Example')
def Main(self):
    return self.close[0]  # This implicitly calls `self.close.__getitem__(0)`
```

> [!NOTE]
>
> Method `__getitem__` should never be called directly. Instead syntax `series_obj[index]` should be used.

**len**

() -> int

Returns length (number of elements) of a `Series[T]` object.

```py Example theme={null}
l = len(self.close)  # this implicitly calls `self.close.__len__()`
```

> [!NOTE]
>
> Method `__len__` should never be called directly. Instead syntax `len(series_obj)` should be used.

> [!NOTE]
>
> See also: [`Series[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Series)[`request_series()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#func_request_series)[`RequestedSeries[T].subperiods()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_RequestedSeries_subperiods)

***

### `SecContext`

*type*

Base class for the classes that represent additional contexts besides the main one.

**1. Parent**

[`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)

**2. Inherited fields**

time

indie.Series\[float]

Series of timestamps (as unix time UTC seconds) of the context's instrument. Every timestamp corresponds to start time of some bar on a chart.

open

indie.Series\[float]

Series of 'open' prices of the context's instrument.

high

indie.Series\[float]

Series of 'high' prices of the context's instrument.

low

indie.Series\[float]

Series of 'low' prices of the context's instrument.

close

indie.Series\[float]

Series of 'close' prices of the context's instrument.

volume

indie.Series\[float]

Series of 'volume' values of the context's instrument.

hl2

indie.Series\[float]

Series of '(high + low) / 2' values of the context's instrument.

hlc3

indie.Series\[float]

Series of '(high + low + close) / 3' values of the context's instrument.

ohlc4

indie.Series\[float]

Series of '(open + high + low + close) / 4' values of the context's instrument.

info

indie.SymbolInfo

Information about the context's instrument.

bar\_index

int

Index of a last (current) bar in this context's instrument which the indicator has received. The very first bar has index equal to `0` and this is the oldest bar.

bar\_count

int

Current total number of bars in this context's instrument which the indicator has received. It is always true that `self.bar_count` is equal to `self.bar_index + 1`.

is\_closed\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.

is\_history

bool

Flag that is `True` if the current bar is a historical bar.

is\_last\_bar

bool

Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.

is\_last\_history\_bar

bool

Flag that is `True` if the current bar is the last bar of the historical part of prices data.

last\_bar\_time

float

Timestamp (as unix time UTC seconds) of the last bar of the context's instrument. It is known on every historical bar, so a historical bar can be compared with the end of the data. In realtime it is the time of the current realtime bar.

```py Example theme={null}
# indie:lang_version = 5
from indie import indicator, color, plot

@indicator('Last day', overlay_main_pane=True)
@plot.bar_color()
def Main(self):
    last_day_start = self.last_bar_time // 86400 * 86400
    if self.time[0] >= last_day_start:
        return plot.BarColor(color=color.YELLOW)
    return plot.BarColor()
```

> [!NOTE]
>
> Bars that were calculated before a new realtime bar arrived are not recalculated. If the day changes while the chart is open, bars of the previous day keep their color until the indicator is calculated again. In a secondary context created with `Context.calc_on` it is the time of the last bar of that context.

> [!NOTE]
>
> See also: [`Context.time`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_time)[`Context.is_last_bar`](https://takeprofit.com/docs/indie/Library-reference/package-indie#field_Context_is_last_bar)

is\_new\_bar

bool

Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.

is\_realtime

bool

Flag that is `True` if the last (current) bar is a realtime bar.

time\_frame

indie.TimeFrame

Time frame of the context's instrument.

trading\_session

indie.TradingSession

Trading session of the context's instrument.

**3. Inherited methods**

calc\_on

(sec\_context, exchange, ticker, time\_frame, \*, source, lookahead) -> indie.SeriesF | tuple\[indie.SeriesF, ...]

Requests additional instrument (creates a secondary context object for it) for indicator and returns one or more `SeriesF` objects which match with the arity of values that `sec_context` function returns. All the returned series values are merged into the timescale of current context's instrument.

**parameters info**

sec\_context

typing.Any

required

Function decorated with `@indie.sec_context`. This function has the same semantics as Indie `Main`, but for additional instrument (not the main one).

exchange

indie.Optional\[str]

default:
None

Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.

ticker

indie.Optional\[str]

default:
None

Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.

time\_frame

indie.Optional\[indie.TimeFrame]

default:
None

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. For an external candle source (a `@sec_context` callback with the `source` argument) `time_frame` is required and must match the cadence of the rows in the file.

source

indie.Optional\[indie.data.sources.IExternalSource]

default:
None

External data source descriptor, e.g. `indie.data.sources.Csv`. Mutually exclusive with `exchange` and `ticker`. With a `@sec_context` callback (external candles) an explicit `time_frame` is required.

lookahead

bool

default:
False

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. With an external `source`, `lookahead=True` requires an explicit `time_frame`.

> [!NOTE]
>
> For a market instrument at least one of optional arguments (`exchange`, `ticker` or `time_frame`) must be provided. More info about this function as well as code examples you may find in [Request additional instruments](https://takeprofit.com/docs/indie/Request-additional-instruments.md) chapter.

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`SecContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SecContext)

new\_mut\_series\_f

(default, size) -> indie.MutSeries\[float]

Creates a `MutSeriesF` (an alias for `MutSeries[float]`) object, which is a container for `float` values in Indie code. The main feature of the `MutSeriesF` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

indie.Optional\[float]

default:
None

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeriesF` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

> [!NOTE]
>
> See also: [`MutSeriesF`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeriesF)

new\_mut\_series

(default, size) -> indie.MutSeries\[T]

Creates a `MutSeries[T]` object, which is a container for `T` values in Indie code. The main feature of the `MutSeries[T]` container is its ability to store (or 'remember') the historical values of a variable. These values can be accessed later using the square brackets operator (via the `__getitem__` method).

**parameters info**

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

size

int

default:
2

Number of elements that `MutSeries` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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. `MutSeries` objects also have a method `request_size(new_size: int)` which can be used to expand the size explicitly.

new\_var

(init) -> indie.Var\[T]

Creates a `Var[T]` object, which is a container for `T` value in Indie code. The main feature of the `Var[T]` container is its ability to rollback the value of the variable when a new realtime update appears to its value after the previous bar.

**parameters info**

init

T

required

Value that is written into `Var` object only once after the `Var` object was created.

is\_first\_in\_session

() -> bool

Detects whether the current bar is the first bar of a new trading session (extended session included). Returns `True` if the current bar is the first bar of the trading session or `False` if the current bar is not the first in the session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_first\_in\_regular\_session

() -> bool

Detects whether the current bar is the first bar of the regular trading session (excluding pre-market session). Returns `True` if the current bar is the first bar of the regular trading session or `False` if the current bar is not the first in the regular session or if no session has started.
\[!NOTE] The function will return `False` if the first bar of the regular session does not exist or is unavailable (e.g., due to data gaps or missing information).

is\_last\_in\_session

() -> bool

Detects whether the current bar is the last bar of the trading session (extended session included). Returns `True` if the current bar is the last bar of the trading session or `False` if the current bar is not the last in the session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

is\_last\_in\_regular\_session

() -> bool

Detects whether the current bar is the last bar of the regular trading session (excluding after-hours session). Returns `True` if the current bar is the last bar of the regular trading session or `False` if the current bar is not the last in the regular session.
\[!NOTE] The function will return `False` if the session ends without a valid last bar (e.g., due to missing data).

> [!NOTE]
>
> See also: [`@sec_context()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_sec_context)[`MainContext`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MainContext)[`Algorithm`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Algorithm)

***

### `Series[T]`

*type*

Generic data type that represents read only series of values of type `T`. Type `T` can be float, int, str, or almost any other type.

**1. Aliases**

```py theme={null}
SeriesF = Series[float]
```

**2. Methods**

[Navigate to method\_Series\_get](#method_Series_get)

get

(offset, default, neg\_offset\_ok) -> T

Returns value of `Series[T]` object at the specified index or given `default` if the value is missing.

**parameters info**

offset

int

required

Offset to extract value at.

default

T

required

Default value that will be used if an element at the specified index cannot be extracted.

neg\_offset\_ok

bool

default:
False

If `False` then `get` method raises an error on any `offset < 0`. If `True` then `get` method returns `default` value on negative offsets too. Default value is `False`.

[Navigate to method\_Series\_request\_size](#method_Series_request_size)

request\_size

(size) -> None

Expands the capacity of `Series[T]` object (number of elements that `Series[T]` object should store in memory).

**parameters info**

size

int

required

Number of elements that `SeriesF` object should store in memory. Default and possible minimum size is 2, which means that series of `size = 2` stores 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.

[Navigate to method\_Series\_set\_size](#method_Series_set_size)

set\_size

(size) -> None

Sets the exact number of values stored by a `Series[T]` object.

**parameters info**

size

int

required

Exact number of elements that `Series[T]` object should store in memory.

[Navigate to method\_Series\_getitem](#method_Series_getitem)

**getitem**

(i) -> T

Returns value of `Series[T]` object at the specified index. If the value is missing, then the default value of type `T` is returned (e.g. `math.nan` if `T` is float).

**parameters info**

i

int

required

Index to extract value at.

```py Example theme={null}
@indicator('Example')
def Main(self):
    return self.close[0]  # This implicitly calls `self.close.__getitem__(0)`
```

> [!NOTE]
>
> Method `__getitem__` should never be called directly. Instead syntax `series_obj[index]` should be used.

[Navigate to method\_Series\_len](#method_Series_len)

**len**

() -> int

Returns length (number of elements) of a `Series[T]` object.

```py Example theme={null}
l = len(self.close)  # this implicitly calls `self.close.__len__()`
```

> [!NOTE]
>
> Method `__len__` should never be called directly. Instead syntax `len(series_obj)` should be used.

> [!NOTE]
>
> See also: [`MutSeries[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeries)[`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)

***

### `SymbolInfo`

*type*

Data type to represent information about the context's instrument.

**1. Fields**

[Navigate to field\_SymbolInfo\_ticker](#field_SymbolInfo_ticker)

ticker

str

Ticker of the context's instrument.

[Navigate to field\_SymbolInfo\_exchange\_code](#field_SymbolInfo_exchange_code)

exchange\_code

str

Exchange code of the context's instrument. For stocks it is a [MIC](https://en.wikipedia.org/wiki/Market_Identifier_Code). 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'`.

[Navigate to field\_SymbolInfo\_exchange\_aliases](#field_SymbolInfo_exchange_aliases)

exchange\_aliases

list\[str]

Commonly recognized (but not exactly standardized) alias for an exchange. For example, an alias for the New York Stock Exchange, Inc. is `'NYSE'`. In most cases exchange alias matches with the exchange acronym (see ISO10383).

[Navigate to field\_SymbolInfo\_price\_precision](#field_SymbolInfo_price_precision)

price\_precision

int

Price precision of the context's instrument. For example, price precision of `2` means that prices have two digits after the floating point.

[Navigate to field\_SymbolInfo\_tick\_size](#field_SymbolInfo_tick_size)

tick\_size

float

Absolute value of a minimal movement of a price of the context's instrument in corresponding currency.

[Navigate to field\_SymbolInfo\_timezone](#field_SymbolInfo_timezone)

timezone

str

Name of the exchange timezone of the context's instrument. For example, `'America/New_York'`.

> [!NOTE]
>
> See also: [`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)

***

### `TimeFrame`

*type*

Data type that represents time frame.

**1. Fields**

[Navigate to field\_TimeFrame\_count](#field_TimeFrame_count)

count

int

Numeric part of the time frame.

[Navigate to field\_TimeFrame\_unit](#field_TimeFrame_unit)

unit

indie.time\_frame\_unit

Unit of the time frame.

**2. Methods**

[Navigate to method\_TimeFrame\_init](#method_TimeFrame_init)

**init**

(count, unit) -> None

Class constructor (initializer for the data type).

**parameters info**

count

int

required

Numeric part of time frame.

unit

indie.time\_frame\_unit

required

Unit of time frame, can be 's', 'm', 'h', 'D', 'W' or 'M'.

[Navigate to method\_TimeFrame\_to\_minutes](#method_TimeFrame_to_minutes)

to\_minutes

() -> int

Converts `TimeFrame` object to corresponding number of minutes. Month is always considered to be of 30 days long, and year is always of 365 days long.

[Navigate to method\_TimeFrame\_to\_seconds](#method_TimeFrame_to_seconds)

to\_seconds

() -> int

Converts `TimeFrame` object to corresponding number of seconds. Month is always considered to be of 30 days long, and year is always of 365 days long.

[Navigate to method\_TimeFrame\_eq](#method_TimeFrame_eq)

**eq**

(other) -> bool

Returns `True` if the TimeFrame objects are equal.

**parameters info**

other

indie.TimeFrame

required

Other value to compare.

> [!NOTE]
>
> Method `__eq__` should never be called directly, instead `obj1 == obj2` syntax should be used.

[Navigate to method\_TimeFrame\_lt](#method_TimeFrame_lt)

**lt**

(other) -> bool

Returns `True` if the TimeFrame object is less than another TimeFrame object.

**parameters info**

other

indie.TimeFrame

required

Other value to compare.

> [!NOTE]
>
> Method `__lt__` should never be called directly, instead `obj1 < obj2` syntax should be used.

[Navigate to method\_TimeFrame\_le](#method_TimeFrame_le)

**le**

(other) -> bool

Returns `True` if the TimeFrame object is less or equal than another TimeFrame object.

**parameters info**

other

indie.TimeFrame

required

Other value to compare.

> [!NOTE]
>
> Method `__le__` should never be called directly, instead `obj1 <= obj2` syntax should be used.

**3. Static methods**

[Navigate to method\_TimeFrame\_from\_str](#method_TimeFrame_from_str)

from\_str

(tf\_str) -> indie.TimeFrame

Converts string representation of time frame to `TimeFrame` type. String representation of `TimeFrame` has a form of `<number>[s|m|h|D|W|M|Y]` where suffixes mean: `s` - seconds, `m` - minutes, `h` - hours, `D` - days, `W` - weeks, `M` - months, `Y` - years. For example `TimeFrame.from_str('15m')` creates a `TimeFrame` object which corresponds to 15 minute time frame.

**parameters info**

tf\_str

str

required

String representation of time frame.

***

### `TradingSession`

*type*

Data type to represent different trading periods within a day, including pre-market, regular, and after-hours sessions. Each period is defined by its own schedule.

**1. Fields**

[Navigate to field\_TradingSession\_pre\_market](#field_TradingSession_pre_market)

pre\_market

indie.schedule.Schedule

Schedule instance that defines the rules and exceptions for the pre-market trading session.

[Navigate to field\_TradingSession\_regular](#field_TradingSession_regular)

regular

indie.schedule.Schedule

Schedule instance that defines the rules and exceptions for the regular trading session.

[Navigate to field\_TradingSession\_after\_hours](#field_TradingSession_after_hours)

after\_hours

indie.schedule.Schedule

Schedule instance that defines the rules and exceptions for the after-hours trading session.

[Navigate to field\_TradingSession\_extended](#field_TradingSession_extended)

extended

indie.schedule.Schedule

Schedule instance that defines the rules and exceptions for the extended session (pre-market + after-hours).

**2. Methods**

[Navigate to method\_TradingSession\_contains](#method_TradingSession_contains)

**contains**

(t) -> bool

Checks whether a given timestamp falls within the defined trading session. Returns `True` if the timestamp falls within the trading session's active periods, otherwise returns `False`.

**parameters info**

t

float

required

Timestamp to check in defined trading session.

**contains**

(d) -> bool

Checks whether a given timestamp falls within the defined trading session. Returns `True` if the timestamp falls within the trading session's active periods, otherwise returns `False`.

**parameters info**

d

datetime.datetime

required

Datetime to check in defined trading session.

[Navigate to method\_TradingSession\_is\_same\_period](#method_TradingSession_is_same_period)

is\_same\_period

(timestamp1, timestamp2) -> bool

Determines whether two timestamps fall within the same trading session period on the same day. Returns `True` if both timestamps fall within the same period of the trading session, even if they are in different calendar days. False if the timestamps belong to different periods within the trading session.

**parameters info**

timestamp1

float

required

First timestamp to check.

timestamp2

float

required

Second timestamp to check.

> [!NOTE]
>
> This method checks if two timestamps, which may belong to different calendar days, are part of the same trading session period. It handles cases where a trading session spans across two consecutive days (e.g., a trading schedule that extends past midnight) and ensures both timestamps belong to the same logical period within the schedule.

[Navigate to method\_TradingSession\_is\_regular](#method_TradingSession_is_regular)

is\_regular

(timestamp) -> bool

Determines whether a given timestamp falls within a regular trading session.

**parameters info**

timestamp

float

required

Timestamp to check against the specific part of trading sessions.

[Navigate to method\_TradingSession\_is\_extended](#method_TradingSession_is_extended)

is\_extended

(timestamp) -> bool

Determines whether a given timestamp falls within an extended trading session (either pre-market or after-hours).

**parameters info**

timestamp

float

required

Timestamp to check against the specific part of trading sessions.

> [!NOTE]
>
> Returns `True` if the provided timestamp falls within either the pre-market or after-hours session. Returns `False` otherwise.

[Navigate to method\_TradingSession\_is\_pre\_market](#method_TradingSession_is_pre_market)

is\_pre\_market

(timestamp) -> bool

Determines whether a given timestamp falls within a pre-market trading session.

**parameters info**

timestamp

float

required

Timestamp to check against the specific part of trading sessions.

[Navigate to method\_TradingSession\_is\_after\_hours](#method_TradingSession_is_after_hours)

is\_after\_hours

(timestamp) -> bool

Determines whether a given timestamp falls within a after-hours trading session.

**parameters info**

timestamp

float

required

Timestamp to check against the specific part of trading sessions.

> [!NOTE]
>
> See also: [`Context`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Context)[`Schedule`](https://takeprofit.com/docs/indie/Library-reference/package-indie-schedule#class_Schedule)[`ScheduleRule`](https://takeprofit.com/docs/indie/Library-reference/package-indie-schedule#class_ScheduleRule)

***

### `Var[T]`

*type*

Generic data type that represents a rollbackable container for value of type `T`. Type `T` can be float, int, str, or almost any other type.

**1. Methods**

[Navigate to method\_Var\_get](#method_Var_get)

get

() -> T

Returns value of `Var[T]` object.

[Navigate to method\_Var\_set](#method_Var_set)

set

(new\_value) -> None

Sets value of `Var[T]` object. The container stores the value on its own, so read it back with `get()` instead of keeping the object that was passed here.

**parameters info**

new\_value

T

required

New value that will be put to `Var` object.

**2. Static methods**

[Navigate to method\_Var\_new](#method_Var_new)

new

(init) -> indie.Var\[T]

Creates a `Var[T]` object, which is a container for `T` value in Indie code. The main feature of the `Var[T]` container is its ability to rollback the value of the variable when a new realtime update appears to its value after the previous bar.

**parameters info**

init

T

required

Value that is written into `Var` object only once after the `Var` object was created.

> [!NOTE]
>
> A `Var[T]` keeps only the latest value and rolls it back on every intrabar update, so each re-execution of a candle starts from the value that candle began with; use `MutSeries[T]` instead when you also need the values of previous candles. For drawings this matters when the next state of a drawing is built from its current one, see [Common drawing patterns](https://takeprofit.com/docs/indie/Code-examples/common-drawing-patterns.md).

> [!NOTE]
>
> See also: [`Context.new_var()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#method_Context_new_var)[`MutSeries[T]`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_MutSeries)

***

## Enums

### `format`

*enum*

Enum-like class with constants that determine how to format the indicator value on the price scale.

**1. Static fields**

[Navigate to const\_format\_INHERITED](#const_format_INHERITED)

INHERITED

indie.format

Indicator output values are formatted same as values of the main chart instrument.

[Navigate to const\_format\_PRICE](#const_format_PRICE)

PRICE

indie.format

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.

[Navigate to const\_format\_VOLUME](#const_format_VOLUME)

VOLUME

indie.format

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`.

> [!NOTE]
>
> See also: [`@indicator()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_indicator)

***

### `line_style`

*enum*

Enum-like class with constants of line styles.

**1. Static fields**

[Navigate to const\_line\_style\_SOLID](#const_line_style_SOLID)

SOLID

indie.line\_style

Built-in line style constant that determines how the line is rendered.

[Navigate to const\_line\_style\_DASHED](#const_line_style_DASHED)

DASHED

indie.line\_style

Built-in line style constant that determines how the line is rendered.

[Navigate to const\_line\_style\_DOTTED](#const_line_style_DOTTED)

DOTTED

indie.line\_style

Built-in line style constant that determines how the line is rendered.

> [!NOTE]
>
> See also: [`@line()`](https://takeprofit.com/docs/indie/Library-reference/package-indie-plot#decor_line)[`@level()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_level)[`@fill()`](https://takeprofit.com/docs/indie/Library-reference/package-indie-plot#decor_fill)

***

### `source`

*enum*

Enum-like class with constants for various price sources (it is used in `@indie.param.source`).

**1. Static fields**

[Navigate to const\_source\_OPEN](#const_source_OPEN)

OPEN

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_HIGH](#const_source_HIGH)

HIGH

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_LOW](#const_source_LOW)

LOW

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_CLOSE](#const_source_CLOSE)

CLOSE

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_VOLUME](#const_source_VOLUME)

VOLUME

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_HL2](#const_source_HL2)

HL2

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_HLC3](#const_source_HLC3)

HLC3

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

[Navigate to const\_source\_OHLC4](#const_source_OHLC4)

OHLC4

indie.source

Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.

> [!NOTE]
>
> See also: [`@param.source()`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_source)

***

### `time_frame_unit`

*enum*

Enum-like class with constants for time frame units.

**1. Static fields**

[Navigate to const\_time\_frame\_unit\_SECOND](#const_time_frame_unit_SECOND)

SECOND

indie.time\_frame\_unit

Built-in constants that represent time frame units.

[Navigate to const\_time\_frame\_unit\_MINUTE](#const_time_frame_unit_MINUTE)

MINUTE

indie.time\_frame\_unit

Built-in constants that represent time frame units.

[Navigate to const\_time\_frame\_unit\_HOUR](#const_time_frame_unit_HOUR)

HOUR

indie.time\_frame\_unit

Built-in constants that represent time frame units.

[Navigate to const\_time\_frame\_unit\_DAY](#const_time_frame_unit_DAY)

DAY

indie.time\_frame\_unit

Built-in constants that represent time frame units.

[Navigate to const\_time\_frame\_unit\_WEEK](#const_time_frame_unit_WEEK)

WEEK

indie.time\_frame\_unit

Built-in constants that represent time frame units.

[Navigate to const\_time\_frame\_unit\_MONTH](#const_time_frame_unit_MONTH)

MONTH

indie.time\_frame\_unit

Built-in constants that represent time frame units.

> [!NOTE]
>
> See also: [`TimeFrame`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_TimeFrame)

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.