> ## 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

> Complete reference for Indie language core package. Documents types, decorators, and functions used in technical trading indicator development.

export const Anchor = ({id}) => {
  return <div id={id} style={{
    scrollMarginTop: "var(--scroll-mt)"
  }}></div>;
};

export const Field = ({id, name, type, required, defaultVal, children}) => {
  return <div id={id} style={{
    scrollMarginTop: "var(--scroll-mt)"
  }} className="mt-4">
      <div className="pt-2.5 pb-5 my-2.5 border-gray-50 dark:border-gray-800/50 border-b">
        <div className="flex font-mono text-sm group/param-head param-head">
          <div className="flex-1 flex content-start py-0.5 mr-5">
            <div className="flex items-center flex-wrap gap-2">
              {id && <div className="absolute">
                  <a href={`#${id}`} className="-ml-10 flex items-center opacity-0 border-0 group-hover/param-head:opacity-100 py-2" aria-label={`Navigate to ${id}`}>
                    <div className="w-6 h-6 text-gray-400 rounded-md flex items-center justify-center zinc-box bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20">
                      <svg xmlns="http://www.w3.org/2000/svg" fill="gray" height="12px" viewBox="0 0 576 512">
                        <path d="M0 256C0 167.6 71.6 96 160 96h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C98.1 144 48 194.1 48 256s50.1 112 112 112h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C71.6 416 0 344.4 0 256zm576 0c0 88.4-71.6 160-160 160H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c61.9 0 112-50.1 112-112s-50.1-112-112-112H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c88.4 0 160 71.6 160 160zM184 232H392c13.3 0 24 10.7 24 24s-10.7 24-24 24H184c-13.3 0-24-10.7-24-24s10.7-24 24-24z"></path>
                      </svg>
                    </div>
                  </a>
                </div>}
              <div className="font-semibold text-primary dark:text-primary-light">
                {name}
              </div>
              <div className="flex items-center space-x-2 text-xs font-medium">
                <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium">
                  {type}
                </div>
                {required && <span className="px-2 py-0.5 rounded-md bg-red-100/50 dark:bg-red-400/10 text-red-600 dark:text-red-300 font-medium">
                    required
                  </span>}
                {defaultVal && <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium">
                    <span class="text-gray-400 dark:text-gray-500">default:</span>
                    {defaultVal}
                  </div>}
              </div>
            </div>
          </div>
        </div>
        <div className="mt-4 prose-sm prose-gray dark:prose-invert">
          {children}
        </div>
      </div>
    </div>;
};

Main package of Indie language.

***

## Decorators

<Anchor id="decor_algorithm" />

### `@algorithm()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@algorithm" type="() -> 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](/indie/How-Indies-syntactic-sugar-works#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](/indie/Algorithms-for-series-processing) chapter.</Note>
      <Info>See also: [`Algorithm`](/indie/Library-reference/package-indie#class_Algorithm)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="decor_band" />

### `@band()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@band" type="(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.

      <Expandable title="parameters info">
        <Field name="value1" type="float" required>
          Value of the first horizontal line of a band on a vertical scale of an indicator.
        </Field>

        <Field name="value2" type="float" required>
          Value of the second horizontal line of a band on a vertical scale of an indicator.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>

        <Field name="fill_color" type="indie.Color" defaultVal="indie.color.GREEN(0.05)">
          Color of the background.
        </Field>

        <Field name="line_color" type="indie.Color" defaultVal="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)*.
        </Field>

        <Field name="line_style" type="indie.line_style" defaultVal="indie.line_style.DASHED">
          Style of the line. It is represented as enum value of type `line_style`.
        </Field>

        <Field name="line_width" type="int" defaultVal="1">
          Width of the line.
        </Field>
      </Expandable>

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

      <Info>See also: [`@level()`](/indie/Library-reference/package-indie#decor_level)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="decor_indicator" />

### `@indicator()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@indicator" type="(abbrev_title, overlay_main_pane, format, precision) -> None">
      Decorator that should be applied to the `Main` entry point of any indicator.

      <Expandable title="parameters info">
        <Field name="abbrev_title" type="str" required>
          Abbreviated title of the indicator.
        </Field>

        <Field name="overlay_main_pane" type="bool" defaultVal="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.
        </Field>

        <Field name="format" type="indie.format" defaultVal="indie.format.INHERITED">
          Formatting style of indicator output values represented as enum value of type `format`.
        </Field>

        <Field name="precision" type="indie.Optional[int]" defaultVal="None">
          Number of digits after floating point for indicator output values.
        </Field>
      </Expandable>

      <Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="decor_level" />

### `@level()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@level" type="(value, title, line_color, line_style, line_width) -> None">
      Decorator that is used to create a level (horizontal line) in an indicator.

      <Expandable title="parameters info">
        <Field name="value" type="float" required>
          Value of the level on a vertical scale of an indicator.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>

        <Field name="line_color" type="indie.Color" defaultVal="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)*.
        </Field>

        <Field name="line_style" type="indie.line_style" defaultVal="indie.line_style.DASHED">
          Style of the line. It is represented as enum value of type `line_style`.
        </Field>

        <Field name="line_width" type="int" defaultVal="1">
          Width of the line.
        </Field>
      </Expandable>

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

      <Info>See also: [`@band()`](/indie/Library-reference/package-indie#decor_band)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="decor_param_ref" />

### `@param_ref()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@param_ref" type="(id) -> None">
      Declares an input parameter for `@sec_context` function that is linked to the input parameter of `Main` by `id`.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>
      </Expandable>

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

      <Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context) [`param`](/indie/Library-reference/package-indie#class_param)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_param" />

### `param`

*type*

Class with decorators of indicator input parameters of various types.

<Steps>
  <Step title="Static methods" icon="cubes">
    <Field id="decor_param_bool" name="@bool" type="(id, default, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="bool" required>
          Default value for the parameter in settings pane.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

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

    <Field id="decor_param_int" name="@int" type="(id, default, min, max, step, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="int" required>
          Default value for the parameter in settings pane.
        </Field>

        <Field name="min" type="int" defaultVal="-1000000">
          Minimum value of the parameter.
        </Field>

        <Field name="max" type="int" defaultVal="1000000">
          Maximum value of the parameter.
        </Field>

        <Field name="step" type="int" defaultVal="1">
          Step between values of the parameter.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

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

    <Field id="decor_param_float" name="@float" type="(id, default, min, max, step, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="float" required>
          Default value for the parameter in settings pane.
        </Field>

        <Field name="min" type="float" defaultVal="-1000000.0">
          Minimum value of the parameter.
        </Field>

        <Field name="max" type="float" defaultVal="1000000.0">
          Maximum value of the parameter.
        </Field>

        <Field name="step" type="float" defaultVal="0.1">
          Step between values of the parameter.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

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

    <Field id="decor_param_str" name="@str" type="(id, default, options, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="str" required>
          Default value for the parameter in settings pane.
        </Field>

        <Field name="options" type="indie.Optional[list[str]]" defaultVal="None">
          List of the possible values of the parameter.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

      ```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.</Note>
    </Field>

    <Field id="decor_param_source" name="@source" type="(id, default, options, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="indie.source" defaultVal="source.CLOSE">
          Default value for the parameter in settings pane.
        </Field>

        <Field name="options" type="indie.Optional[list[indie.source]]" defaultVal="None">
          List of the possible values of the parameter.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

      ```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>
      <Info>See also: [`param`](/indie/Library-reference/package-indie#class_param) [`source`](/indie/Library-reference/package-indie#enum_source)</Info>
    </Field>

    <Field id="decor_param_time_frame" name="@time_frame" type="(id, default, options, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="str" required>
          Default value for the parameter in settings pane.
        </Field>

        <Field name="options" type="indie.Optional[list[str]]" defaultVal="None">
          List of the possible values of the parameter.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

      ```py Example theme={null}
      @param.time_frame('time_frame', default='30m', options=['1m', '30m', '1h', '4h', '1D', '1W', '1M', '1Y'])
      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>[m|h|D|W|M|Y]` where suffixes mean: `m` - minutes, `h` - hours, `D` - days, `W` - weeks, `M` - months, `Y` - years. If `options` parameter is used then in Settings panel there will be a combobox widget for changing value of this input.</Note>
      <Info>See also: [`TimeFrame`](/indie/Library-reference/package-indie#class_TimeFrame)</Info>
    </Field>

    <Field id="decor_param_color" name="@color" type="(id, default, title) -> 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.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Name of `Main` function or class parameter bound to the input parameter.
        </Field>

        <Field name="default" type="indie.Color" required>
          Default value for the parameter in settings pane.
        </Field>

        <Field name="title" type="indie.Optional[str]" defaultVal="None">
          Human readable title which is visible in the indicator's Settings panel.
        </Field>
      </Expandable>

      ```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>
      <Info>See also: [`Color`](/indie/Library-reference/package-indie#class_Color)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="decor_sec_context" />

### `@sec_context()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@sec_context" type="() -> 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](/indie/Request-additional-instruments) chapter.</Note>
      <Info>See also: [`@indicator()`](/indie/Library-reference/package-indie#decor_indicator) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext) [`Context.calc_on()`](/indie/Library-reference/package-indie#method_Context_calc_on)</Info>
    </Field>
  </Step>
</Steps>

***

<Anchor id="decor_strategy" />

### `@strategy()`

*decorator*

<Steps>
  <Step title="Overloads" icon="pencil">
    <Field name="@strategy" type="(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.

      <Expandable title="parameters info">
        <Field name="abbrev_title" type="str" required>
          Abbreviated title of the indicator.
        </Field>

        <Field name="overlay_main_pane" type="bool" defaultVal="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.
        </Field>

        <Field name="format" type="indie.format" defaultVal="indie.format.INHERITED">
          Formatting style of indicator output values represented as enum value of type `format`.
        </Field>

        <Field name="precision" type="indie.Optional[int]" defaultVal="None">
          Number of digits after floating point for indicator output values.
        </Field>

        <Field name="initial_capital" type="float" defaultVal="1000000.0">
          Starting capital amount for the strategy backtest. Default is `1000000.0`.
        </Field>

        <Field name="commission" type="indie.strategies.Commission" defaultVal="indie.strategies.Commission(0.0, indie.strategies.commission_type.PERCENT)">
          Commission settings applied to all trades. Default is zero commission.
        </Field>

        <Field name="leverage" type="float" defaultVal="1.0">
          Leverage multiplier for the strategy. Values greater than 1.0 allow trading with borrowed capital. Default is `1.0` (no leverage).
        </Field>

        <Field name="intrabar_order_filter" type="indie.strategies.intrabar_order_filter" defaultVal="indie.strategies.intrabar_order_filter.ON_BAR_CLOSE">
          Determines when orders are executed within a bar during backtesting. Default is `ON_BAR_CLOSE`.
        </Field>

        <Field name="market_order_price" type="indie.strategies.market_order_price" defaultVal="indie.strategies.market_order_price.MARKET_PRICE">
          Price used for market order execution in backtesting. Default is `MARKET_PRICE`.
        </Field>

        <Field name="risk_free_rate" type="float" defaultVal="0.02">
          Annual risk-free rate used for calculating strategy performance metrics like Sharpe ratio. Default is `0.02` (2%).
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

***

## Types

<Anchor id="class_Algorithm" />

### `Algorithm`

*type*

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

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_Algorithm_ctx" name="ctx" type="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.
    </Field>
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_Algorithm_init" name="__init__" type="(ctx) -> None">
      Class constructor (initializer for the data type).

      <Expandable title="parameters info">
        <Field name="ctx" type="indie.Context" required>
          Context object.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

<Info>See also: [`@algorithm()`](/indie/Library-reference/package-indie#decor_algorithm) [`MainContext`](/indie/Library-reference/package-indie#class_MainContext) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext)</Info>

***

<Anchor id="class_Color" />

### `Color`

*type*

Data type to represent color.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_Color_call" name="__call__" type="(alpha) -> indie.Color">
      Creates a new Color instance with the given transparency applied to the existing color.

      <Expandable title="parameters info">
        <Field name="alpha" type="float" required>
          Alpha channel (component) of color which ranges from `0.0` (fully transparent) to `1.0` (fully opaque).
        </Field>
      </Expandable>

      ```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>
    </Field>
  </Step>
</Steps>

<Info>See also: [`color`](/indie/Library-reference/package-indie-color)</Info>

***

<Anchor id="class_Context" />

### `Context`

*type*

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

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_Context_time" name="time" type="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.
    </Field>

    <Field id="field_Context_open" name="open" type="indie.Series[float]">
      Series of 'open' prices of the context's instrument.
    </Field>

    <Field id="field_Context_high" name="high" type="indie.Series[float]">
      Series of 'high' prices of the context's instrument.
    </Field>

    <Field id="field_Context_low" name="low" type="indie.Series[float]">
      Series of 'low' prices of the context's instrument.
    </Field>

    <Field id="field_Context_close" name="close" type="indie.Series[float]">
      Series of 'close' prices of the context's instrument.
    </Field>

    <Field id="field_Context_volume" name="volume" type="indie.Series[float]">
      Series of 'volume' values of the context's instrument.
    </Field>

    <Field id="field_Context_hl2" name="hl2" type="indie.Series[float]">
      Series of '(high + low) / 2' values of the context's instrument.
    </Field>

    <Field id="field_Context_hlc3" name="hlc3" type="indie.Series[float]">
      Series of '(high + low + close) / 3' values of the context's instrument.
    </Field>

    <Field id="field_Context_ohlc4" name="ohlc4" type="indie.Series[float]">
      Series of '(open + high + low + close) / 4' values of the context's instrument.
    </Field>

    <Field id="field_Context_info" name="info" type="indie.SymbolInfo">
      Information about the context's instrument.
    </Field>

    <Field id="field_Context_bar_index" name="bar_index" type="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.
    </Field>

    <Field id="field_Context_bar_count" name="bar_count" type="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`.
    </Field>

    <Field id="field_Context_is_closed_bar" name="is_closed_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.
    </Field>

    <Field id="field_Context_is_history" name="is_history" type="bool">
      Flag that is `True` if the current bar is a historical bar.
    </Field>

    <Field id="field_Context_is_last_bar" name="is_last_bar" type="bool">
      Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.
    </Field>

    <Field id="field_Context_is_last_history_bar" name="is_last_history_bar" type="bool">
      Flag that is `True` if the current bar is the last bar of the historical part of prices data.
    </Field>

    <Field id="field_Context_is_new_bar" name="is_new_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.
    </Field>

    <Field id="field_Context_is_realtime" name="is_realtime" type="bool">
      Flag that is `True` if the last (current) bar is a realtime bar.
    </Field>

    <Field id="field_Context_time_frame" name="time_frame" type="indie.TimeFrame">
      Time frame of the context's instrument.
    </Field>

    <Field id="field_Context_trading_session" name="trading_session" type="indie.TradingSession">
      Trading session of the context's instrument.
    </Field>
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_Context_calc_on" name="calc_on" type="(sec_context, exchange, ticker, time_frame, *, 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.

      <Expandable title="parameters info">
        <Field name="sec_context" type="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).
        </Field>

        <Field name="exchange" type="indie.Optional[str]" defaultVal="None">
          Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.
        </Field>

        <Field name="ticker" type="indie.Optional[str]" defaultVal="None">
          Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.
        </Field>

        <Field name="time_frame" type="indie.Optional[indie.TimeFrame]" defaultVal="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.
        </Field>

        <Field name="lookahead" type="bool" defaultVal="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.
        </Field>
      </Expandable>

      <Note>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](/indie/Request-additional-instruments) chapter.</Note>
      <Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext)</Info>
    </Field>

    <Field id="method_Context_new_mut_series_f" name="new_mut_series_f" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="indie.Optional[float]" defaultVal="None">
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>

      <Info>See also: [`MutSeriesF`](/indie/Library-reference/package-indie#class_MutSeriesF)</Info>
    </Field>

    <Field id="method_Context_new_mut_series" name="new_mut_series" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="T" required>
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Context_new_var" name="new_var" type="(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.

      <Expandable title="parameters info">
        <Field name="init" type="T" required>
          Value that is written into `Var` object only once after the `Var` object was created.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Context_is_first_in_session" name="is_first_in_session" type="() -> 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).</Note>
    </Field>

    <Field id="method_Context_is_first_in_regular_session" name="is_first_in_regular_session" type="() -> 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).</Note>
    </Field>

    <Field id="method_Context_is_last_in_session" name="is_last_in_session" type="() -> 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).</Note>
    </Field>

    <Field id="method_Context_is_last_in_regular_session" name="is_last_in_regular_session" type="() -> 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>
    </Field>
  </Step>
</Steps>

<Info>See also: [`MainContext`](/indie/Library-reference/package-indie#class_MainContext) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext) [`SymbolInfo`](/indie/Library-reference/package-indie#class_SymbolInfo) [`Series[T]`](/indie/Library-reference/package-indie#class_Series) [`MutSeries[T]`](/indie/Library-reference/package-indie#class_MutSeries) [`TradingSession`](/indie/Library-reference/package-indie#class_TradingSession)</Info>

***

<Anchor id="class_IndieError" />

### `IndieError`

*type*

Data type for Indie errors.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_IndieError_init" name="__init__" type="(msg) -> None">
      Class constructor (initializer for the data type).

      <Expandable title="parameters info">
        <Field name="msg" type="str" required>
          Error message.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_MainContext" />

### `MainContext`

*type*

Base class for the class that represents main context.

<Steps>
  <Step title="Parent" icon="person-cane">
    [`Context`](/indie/Library-reference/package-indie#class_Context)
  </Step>

  <Step title="Fields" icon="key">
    <Field id="field_MainContext_chart" name="chart" type="indie.drawings.Chart">
      Chart object for drawing and managing non-series visual elements.
    </Field>
  </Step>

  <Step title="Inherited fields" icon="gift">
    <Field name="time" type="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.
    </Field>

    <Field name="open" type="indie.Series[float]">
      Series of 'open' prices of the context's instrument.
    </Field>

    <Field name="high" type="indie.Series[float]">
      Series of 'high' prices of the context's instrument.
    </Field>

    <Field name="low" type="indie.Series[float]">
      Series of 'low' prices of the context's instrument.
    </Field>

    <Field name="close" type="indie.Series[float]">
      Series of 'close' prices of the context's instrument.
    </Field>

    <Field name="volume" type="indie.Series[float]">
      Series of 'volume' values of the context's instrument.
    </Field>

    <Field name="hl2" type="indie.Series[float]">
      Series of '(high + low) / 2' values of the context's instrument.
    </Field>

    <Field name="hlc3" type="indie.Series[float]">
      Series of '(high + low + close) / 3' values of the context's instrument.
    </Field>

    <Field name="ohlc4" type="indie.Series[float]">
      Series of '(open + high + low + close) / 4' values of the context's instrument.
    </Field>

    <Field name="info" type="indie.SymbolInfo">
      Information about the context's instrument.
    </Field>

    <Field name="bar_index" type="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.
    </Field>

    <Field name="bar_count" type="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`.
    </Field>

    <Field name="is_closed_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.
    </Field>

    <Field name="is_history" type="bool">
      Flag that is `True` if the current bar is a historical bar.
    </Field>

    <Field name="is_last_bar" type="bool">
      Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.
    </Field>

    <Field name="is_last_history_bar" type="bool">
      Flag that is `True` if the current bar is the last bar of the historical part of prices data.
    </Field>

    <Field name="is_new_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.
    </Field>

    <Field name="is_realtime" type="bool">
      Flag that is `True` if the last (current) bar is a realtime bar.
    </Field>

    <Field name="time_frame" type="indie.TimeFrame">
      Time frame of the context's instrument.
    </Field>

    <Field name="trading_session" type="indie.TradingSession">
      Trading session of the context's instrument.
    </Field>
  </Step>

  <Step title="Inherited methods" icon="gift">
    <Field name="calc_on" type="(sec_context, exchange, ticker, time_frame, *, 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.

      <Expandable title="parameters info">
        <Field name="sec_context" type="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).
        </Field>

        <Field name="exchange" type="indie.Optional[str]" defaultVal="None">
          Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.
        </Field>

        <Field name="ticker" type="indie.Optional[str]" defaultVal="None">
          Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.
        </Field>

        <Field name="time_frame" type="indie.Optional[indie.TimeFrame]" defaultVal="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.
        </Field>

        <Field name="lookahead" type="bool" defaultVal="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.
        </Field>
      </Expandable>

      <Note>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](/indie/Request-additional-instruments) chapter.</Note>
      <Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext)</Info>
    </Field>

    <Field name="new_mut_series_f" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="indie.Optional[float]" defaultVal="None">
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>

      <Info>See also: [`MutSeriesF`](/indie/Library-reference/package-indie#class_MutSeriesF)</Info>
    </Field>

    <Field name="new_mut_series" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="T" required>
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>
    </Field>

    <Field name="new_var" type="(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.

      <Expandable title="parameters info">
        <Field name="init" type="T" required>
          Value that is written into `Var` object only once after the `Var` object was created.
        </Field>
      </Expandable>
    </Field>

    <Field name="is_first_in_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_first_in_regular_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_last_in_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_last_in_regular_session" type="() -> 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>
    </Field>
  </Step>
</Steps>

<Info>See also: [`SecContext`](/indie/Library-reference/package-indie#class_SecContext) [`Context`](/indie/Library-reference/package-indie#class_Context) [`Algorithm`](/indie/Library-reference/package-indie#class_Algorithm)</Info>

***

<Anchor id="class_MainStrategyContext" />

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

<Steps>
  <Step title="Parent" icon="person-cane">
    [`MainContext`](/indie/Library-reference/package-indie#class_MainContext)
  </Step>

  <Step title="Fields" icon="key">
    <Field id="field_MainStrategyContext_trading" name="trading" type="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.
    </Field>
  </Step>

  <Step title="Inherited fields" icon="gift">
    <Field name="chart" type="indie.drawings.Chart">
      Chart object for drawing and managing non-series visual elements.
    </Field>

    <Field name="time" type="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.
    </Field>

    <Field name="open" type="indie.Series[float]">
      Series of 'open' prices of the context's instrument.
    </Field>

    <Field name="high" type="indie.Series[float]">
      Series of 'high' prices of the context's instrument.
    </Field>

    <Field name="low" type="indie.Series[float]">
      Series of 'low' prices of the context's instrument.
    </Field>

    <Field name="close" type="indie.Series[float]">
      Series of 'close' prices of the context's instrument.
    </Field>

    <Field name="volume" type="indie.Series[float]">
      Series of 'volume' values of the context's instrument.
    </Field>

    <Field name="hl2" type="indie.Series[float]">
      Series of '(high + low) / 2' values of the context's instrument.
    </Field>

    <Field name="hlc3" type="indie.Series[float]">
      Series of '(high + low + close) / 3' values of the context's instrument.
    </Field>

    <Field name="ohlc4" type="indie.Series[float]">
      Series of '(open + high + low + close) / 4' values of the context's instrument.
    </Field>

    <Field name="info" type="indie.SymbolInfo">
      Information about the context's instrument.
    </Field>

    <Field name="bar_index" type="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.
    </Field>

    <Field name="bar_count" type="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`.
    </Field>

    <Field name="is_closed_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.
    </Field>

    <Field name="is_history" type="bool">
      Flag that is `True` if the current bar is a historical bar.
    </Field>

    <Field name="is_last_bar" type="bool">
      Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.
    </Field>

    <Field name="is_last_history_bar" type="bool">
      Flag that is `True` if the current bar is the last bar of the historical part of prices data.
    </Field>

    <Field name="is_new_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.
    </Field>

    <Field name="is_realtime" type="bool">
      Flag that is `True` if the last (current) bar is a realtime bar.
    </Field>

    <Field name="time_frame" type="indie.TimeFrame">
      Time frame of the context's instrument.
    </Field>

    <Field name="trading_session" type="indie.TradingSession">
      Trading session of the context's instrument.
    </Field>
  </Step>

  <Step title="Inherited methods" icon="gift">
    <Field name="calc_on" type="(sec_context, exchange, ticker, time_frame, *, 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.

      <Expandable title="parameters info">
        <Field name="sec_context" type="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).
        </Field>

        <Field name="exchange" type="indie.Optional[str]" defaultVal="None">
          Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.
        </Field>

        <Field name="ticker" type="indie.Optional[str]" defaultVal="None">
          Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.
        </Field>

        <Field name="time_frame" type="indie.Optional[indie.TimeFrame]" defaultVal="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.
        </Field>

        <Field name="lookahead" type="bool" defaultVal="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.
        </Field>
      </Expandable>

      <Note>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](/indie/Request-additional-instruments) chapter.</Note>
      <Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext)</Info>
    </Field>

    <Field name="new_mut_series_f" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="indie.Optional[float]" defaultVal="None">
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>

      <Info>See also: [`MutSeriesF`](/indie/Library-reference/package-indie#class_MutSeriesF)</Info>
    </Field>

    <Field name="new_mut_series" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="T" required>
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>
    </Field>

    <Field name="new_var" type="(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.

      <Expandable title="parameters info">
        <Field name="init" type="T" required>
          Value that is written into `Var` object only once after the `Var` object was created.
        </Field>
      </Expandable>
    </Field>

    <Field name="is_first_in_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_first_in_regular_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_last_in_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_last_in_regular_session" type="() -> 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>
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_MutSeries" />

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

<Steps>
  <Step title="Aliases" icon="copyright">
    <Anchor id="class_MutSeriesF" />

    ```py theme={null}
    MutSeriesF = MutSeries[float]
    ```
  </Step>

  <Step title="Parent" icon="person-cane">
    [`Series[T]`](/indie/Library-reference/package-indie#class_Series)
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_MutSeries_setitem" name="__setitem__" type="(i, x) -> None">
      Sets value of `MutSeries[T]` object at the specified index.

      <Expandable title="parameters info">
        <Field name="i" type="int" required>
          Index to assign value at.
        </Field>

        <Field name="x" type="T" required>
          New value.
        </Field>
      </Expandable>

      ```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.</Note>
    </Field>

    <Field id="method_MutSeries_calc" name="calc" type="(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.

      <Expandable title="parameters info">
        <Field name="reset" type="indie.Optional[T]" defaultVal="None">
          Value that is written into the most recent element of the `MutSeries` every time `MutSeries.new` function is executed.
        </Field>

        <Field name="init" type="indie.Optional[T]" defaultVal="None">
          Value that is written into the most recent element of the `MutSeries` object only once after the `MutSeries` object was created.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>
    </Field>
  </Step>

  <Step title="Static methods" icon="cubes">
    <Field id="method_MutSeries_new" name="new" type="(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).

      <Expandable title="parameters info">
        <Field name="reset" type="T" required>
          Value that is written into the most recent element of the `MutSeries` every time `MutSeries.new` function is executed.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>

      <Info>See also: [`Context.new_mut_series()`](/indie/Library-reference/package-indie#method_Context_new_mut_series)</Info>
    </Field>

    <Field name="new" type="(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).

      <Expandable title="parameters info">
        <Field name="reset" type="indie.Optional[T]" defaultVal="None">
          Value that is written into the most recent element of the `MutSeries` every time `MutSeries.new` function is executed.
        </Field>

        <Field name="init" type="indie.Optional[T]" defaultVal="None">
          Value that is written into the most recent element of the `MutSeries` object only once after the `MutSeries` object was created.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>

      <Info>See also: [`Context.new_mut_series()`](/indie/Library-reference/package-indie#method_Context_new_mut_series)</Info>
    </Field>
  </Step>

  <Step title="Inherited methods" icon="gift">
    <Field name="get" type="(offset, default, neg_offset_ok) -> T">
      Returns value of `Series[T]` object at the specified index or given `default` if the value is missing.

      <Expandable title="parameters info">
        <Field name="offset" type="int" required>
          Offset to extract value at.
        </Field>

        <Field name="default" type="T" required>
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="neg_offset_ok" type="bool" defaultVal="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`.
        </Field>
      </Expandable>
    </Field>

    <Field name="request_size" type="(size) -> None">
      Expands the capacity of `Series[T]` object (number of elements that `Series[T]` object should store in memory).

      <Expandable title="parameters info">
        <Field name="size" type="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.
        </Field>
      </Expandable>
    </Field>

    <Field name="__getitem__" type="(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).

      <Expandable title="parameters info">
        <Field name="i" type="int" required>
          Index to extract value at.
        </Field>
      </Expandable>

      ```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.</Note>
    </Field>

    <Field name="__len__" type="() -> 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>
    </Field>
  </Step>
</Steps>

<Info>See also: [`Context.new_mut_series()`](/indie/Library-reference/package-indie#method_Context_new_mut_series) [`Series[T]`](/indie/Library-reference/package-indie#class_Series)</Info>

***

<Anchor id="class_Optional" />

### `Optional[T]`

*type*

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

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_Optional_init" name="__init__" type="(value) -> None">
      Class constructor (initializer for the data type).

      <Expandable title="parameters info">
        <Field name="value" type="T" required>
          Value to cast from.
        </Field>
      </Expandable>
    </Field>

    <Field name="__init__" type="() -> None">
      Class constructor (initializer for the data type).
    </Field>

    <Field id="method_Optional_value" name="value" type="() -> T">
      Returns value of `indie.Optional[T]` object. Raises a runtime error if the optional object is `None`.
    </Field>

    <Field id="method_Optional_value_or" name="value_or" type="(default) -> T">
      Returns value of `indie.Optional[T]` object or given `default` if the optional object is `None`.

      <Expandable title="parameters info">
        <Field name="default" type="T" required>
          Default value that will be used if there is no value.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Optional_bool" name="__bool__" type="() -> bool">
      Casts `Optional` object to bool.
      <Note>This method is present for `Optional[T]` only if `T` can be converted to `bool`.</Note>
    </Field>

    <Field id="method_Optional_isnone" name="__isnone__" type="() -> 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.</Note>
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_SecContext" />

### `SecContext`

*type*

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

<Steps>
  <Step title="Parent" icon="person-cane">
    [`Context`](/indie/Library-reference/package-indie#class_Context)
  </Step>

  <Step title="Inherited fields" icon="gift">
    <Field name="time" type="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.
    </Field>

    <Field name="open" type="indie.Series[float]">
      Series of 'open' prices of the context's instrument.
    </Field>

    <Field name="high" type="indie.Series[float]">
      Series of 'high' prices of the context's instrument.
    </Field>

    <Field name="low" type="indie.Series[float]">
      Series of 'low' prices of the context's instrument.
    </Field>

    <Field name="close" type="indie.Series[float]">
      Series of 'close' prices of the context's instrument.
    </Field>

    <Field name="volume" type="indie.Series[float]">
      Series of 'volume' values of the context's instrument.
    </Field>

    <Field name="hl2" type="indie.Series[float]">
      Series of '(high + low) / 2' values of the context's instrument.
    </Field>

    <Field name="hlc3" type="indie.Series[float]">
      Series of '(high + low + close) / 3' values of the context's instrument.
    </Field>

    <Field name="ohlc4" type="indie.Series[float]">
      Series of '(open + high + low + close) / 4' values of the context's instrument.
    </Field>

    <Field name="info" type="indie.SymbolInfo">
      Information about the context's instrument.
    </Field>

    <Field name="bar_index" type="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.
    </Field>

    <Field name="bar_count" type="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`.
    </Field>

    <Field name="is_closed_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a final update for a realtime bar.
    </Field>

    <Field name="is_history" type="bool">
      Flag that is `True` if the current bar is a historical bar.
    </Field>

    <Field name="is_last_bar" type="bool">
      Flag that is `True` if the current bar is the last bar in the history or it is a realtime bar.
    </Field>

    <Field name="is_last_history_bar" type="bool">
      Flag that is `True` if the current bar is the last bar of the historical part of prices data.
    </Field>

    <Field name="is_new_bar" type="bool">
      Flag that is `True` if the current bar is a historical bar or it is a first update for a realtime bar.
    </Field>

    <Field name="is_realtime" type="bool">
      Flag that is `True` if the last (current) bar is a realtime bar.
    </Field>

    <Field name="time_frame" type="indie.TimeFrame">
      Time frame of the context's instrument.
    </Field>

    <Field name="trading_session" type="indie.TradingSession">
      Trading session of the context's instrument.
    </Field>
  </Step>

  <Step title="Inherited methods" icon="gift">
    <Field name="calc_on" type="(sec_context, exchange, ticker, time_frame, *, 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.

      <Expandable title="parameters info">
        <Field name="sec_context" type="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).
        </Field>

        <Field name="exchange" type="indie.Optional[str]" defaultVal="None">
          Alias for exchange of additional instrument. If omitted, then the exchange of the current context's instrument will be used.
        </Field>

        <Field name="ticker" type="indie.Optional[str]" defaultVal="None">
          Ticker of an additional instrument. If omitted, then the ticker of the current context's instrument will be used.
        </Field>

        <Field name="time_frame" type="indie.Optional[indie.TimeFrame]" defaultVal="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.
        </Field>

        <Field name="lookahead" type="bool" defaultVal="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.
        </Field>
      </Expandable>

      <Note>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](/indie/Request-additional-instruments) chapter.</Note>
      <Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context) [`SecContext`](/indie/Library-reference/package-indie#class_SecContext)</Info>
    </Field>

    <Field name="new_mut_series_f" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="indie.Optional[float]" defaultVal="None">
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>

      <Info>See also: [`MutSeriesF`](/indie/Library-reference/package-indie#class_MutSeriesF)</Info>
    </Field>

    <Field name="new_mut_series" type="(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).

      <Expandable title="parameters info">
        <Field name="default" type="T" required>
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="size" type="int" defaultVal="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.
        </Field>
      </Expandable>
    </Field>

    <Field name="new_var" type="(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.

      <Expandable title="parameters info">
        <Field name="init" type="T" required>
          Value that is written into `Var` object only once after the `Var` object was created.
        </Field>
      </Expandable>
    </Field>

    <Field name="is_first_in_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_first_in_regular_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_last_in_session" type="() -> 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).</Note>
    </Field>

    <Field name="is_last_in_regular_session" type="() -> 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>
    </Field>
  </Step>
</Steps>

<Info>See also: [`@sec_context()`](/indie/Library-reference/package-indie#decor_sec_context) [`MainContext`](/indie/Library-reference/package-indie#class_MainContext) [`Algorithm`](/indie/Library-reference/package-indie#class_Algorithm)</Info>

***

<Anchor id="class_Series" />

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

<Steps>
  <Step title="Aliases" icon="copyright">
    <Anchor id="class_SeriesF" />

    ```py theme={null}
    SeriesF = Series[float]
    ```
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_Series_get" name="get" type="(offset, default, neg_offset_ok) -> T">
      Returns value of `Series[T]` object at the specified index or given `default` if the value is missing.

      <Expandable title="parameters info">
        <Field name="offset" type="int" required>
          Offset to extract value at.
        </Field>

        <Field name="default" type="T" required>
          Default value that will be used if an element at the specified index cannot be extracted.
        </Field>

        <Field name="neg_offset_ok" type="bool" defaultVal="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`.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Series_request_size" name="request_size" type="(size) -> None">
      Expands the capacity of `Series[T]` object (number of elements that `Series[T]` object should store in memory).

      <Expandable title="parameters info">
        <Field name="size" type="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.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Series_getitem" name="__getitem__" type="(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).

      <Expandable title="parameters info">
        <Field name="i" type="int" required>
          Index to extract value at.
        </Field>
      </Expandable>

      ```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.</Note>
    </Field>

    <Field id="method_Series_len" name="__len__" type="() -> 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>
    </Field>
  </Step>
</Steps>

<Info>See also: [`MutSeries[T]`](/indie/Library-reference/package-indie#class_MutSeries) [`Context`](/indie/Library-reference/package-indie#class_Context)</Info>

***

<Anchor id="class_SymbolInfo" />

### `SymbolInfo`

*type*

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

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_SymbolInfo_ticker" name="ticker" type="str">
      Ticker of the context's instrument.
    </Field>

    <Field id="field_SymbolInfo_exchange_code" name="exchange_code" type="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'`.
    </Field>

    <Field id="field_SymbolInfo_exchange_aliases" name="exchange_aliases" type="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).
    </Field>

    <Field id="field_SymbolInfo_price_precision" name="price_precision" type="int">
      Price precision of the context's instrument. For example, price precision of `2` means that prices have two digits after the floating point.
    </Field>

    <Field id="field_SymbolInfo_tick_size" name="tick_size" type="float">
      Absolute value of a minimal movement of a price of the context's instrument in corresponding currency.
    </Field>

    <Field id="field_SymbolInfo_timezone" name="timezone" type="str">
      Name of the exchange timezone of the context's instrument. For example, `'America/New_York'`.
    </Field>
  </Step>
</Steps>

<Info>See also: [`Context`](/indie/Library-reference/package-indie#class_Context)</Info>

***

<Anchor id="class_TimeFrame" />

### `TimeFrame`

*type*

Data type that represents time frame.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_TimeFrame_init" name="__init__" type="(count, unit) -> None">
      Class constructor (initializer for the data type).

      <Expandable title="parameters info">
        <Field name="count" type="int" required>
          Numeric part of time frame.
        </Field>

        <Field name="unit" type="indie.time_frame_unit" required>
          Unit of time frame, can be 'm', 'h', 'D', 'W' or 'M'.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_TimeFrame_to_minutes" name="to_minutes" type="() -> 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.
    </Field>

    <Field id="method_TimeFrame_eq" name="__eq__" type="(other) -> bool">
      Returns `True` if the TimeFrame objects are equal.

      <Expandable title="parameters info">
        <Field name="other" type="indie.TimeFrame" required>
          Other value to compare.
        </Field>
      </Expandable>

      <Note>Method `__eq__` should never be called directly, instead `obj1 == obj2` syntax should be used.</Note>
    </Field>

    <Field id="method_TimeFrame_lt" name="__lt__" type="(other) -> bool">
      Returns `True` if the TimeFrame object is less than another TimeFrame object.

      <Expandable title="parameters info">
        <Field name="other" type="indie.TimeFrame" required>
          Other value to compare.
        </Field>
      </Expandable>

      <Note>Method `__lt__` should never be called directly, instead `obj1 < obj2` syntax should be used.</Note>
    </Field>

    <Field id="method_TimeFrame_le" name="__le__" type="(other) -> bool">
      Returns `True` if the TimeFrame object is less or equal than another TimeFrame object.

      <Expandable title="parameters info">
        <Field name="other" type="indie.TimeFrame" required>
          Other value to compare.
        </Field>
      </Expandable>

      <Note>Method `__le__` should never be called directly, instead `obj1 <= obj2` syntax should be used.</Note>
    </Field>
  </Step>

  <Step title="Static methods" icon="cubes">
    <Field id="method_TimeFrame_from_str" name="from_str" type="(tf_str) -> indie.TimeFrame">
      Converts string representation of time frame to `TimeFrame` type. String representation of `TimeFrame` has a form of `<number>[m|h|D|W|M|Y]` where suffixes mean: `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.

      <Expandable title="parameters info">
        <Field name="tf_str" type="str" required>
          String representation of time frame.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_TradingSession" />

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

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_TradingSession_pre_market" name="pre_market" type="indie.schedule.Schedule">
      Schedule instance that defines the rules and exceptions for the pre-market trading session.
    </Field>

    <Field id="field_TradingSession_regular" name="regular" type="indie.schedule.Schedule">
      Schedule instance that defines the rules and exceptions for the regular trading session.
    </Field>

    <Field id="field_TradingSession_after_hours" name="after_hours" type="indie.schedule.Schedule">
      Schedule instance that defines the rules and exceptions for the after-hours trading session.
    </Field>

    <Field id="field_TradingSession_extended" name="extended" type="indie.schedule.Schedule">
      Schedule instance that defines the rules and exceptions for the extended session (pre-market + after-hours).
    </Field>
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_TradingSession_contains" name="__contains__" type="(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`.

      <Expandable title="parameters info">
        <Field name="t" type="float" required>
          Timestamp to check in defined trading session.
        </Field>
      </Expandable>
    </Field>

    <Field name="__contains__" type="(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`.

      <Expandable title="parameters info">
        <Field name="d" type="datetime.datetime" required>
          Datetime to check in defined trading session.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_TradingSession_is_same_period" name="is_same_period" type="(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.

      <Expandable title="parameters info">
        <Field name="timestamp1" type="float" required>
          First timestamp to check.
        </Field>

        <Field name="timestamp2" type="float" required>
          Second timestamp to check.
        </Field>
      </Expandable>

      <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.</Note>
    </Field>

    <Field id="method_TradingSession_is_regular" name="is_regular" type="(timestamp) -> bool">
      Determines whether a given timestamp falls within a regular trading session.

      <Expandable title="parameters info">
        <Field name="timestamp" type="float" required>
          Timestamp to check against the specific part of trading sessions.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_TradingSession_is_extended" name="is_extended" type="(timestamp) -> bool">
      Determines whether a given timestamp falls within an extended trading session (either pre-market or after-hours).

      <Expandable title="parameters info">
        <Field name="timestamp" type="float" required>
          Timestamp to check against the specific part of trading sessions.
        </Field>
      </Expandable>

      <Note>Returns `True` if the provided timestamp falls within either the pre-market or after-hours session. Returns `False` otherwise.</Note>
    </Field>

    <Field id="method_TradingSession_is_pre_market" name="is_pre_market" type="(timestamp) -> bool">
      Determines whether a given timestamp falls within a pre-market trading session.

      <Expandable title="parameters info">
        <Field name="timestamp" type="float" required>
          Timestamp to check against the specific part of trading sessions.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_TradingSession_is_after_hours" name="is_after_hours" type="(timestamp) -> bool">
      Determines whether a given timestamp falls within a after-hours trading session.

      <Expandable title="parameters info">
        <Field name="timestamp" type="float" required>
          Timestamp to check against the specific part of trading sessions.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

<Info>See also: [`Context`](/indie/Library-reference/package-indie#class_Context) [`Schedule`](/indie/Library-reference/package-indie-schedule#class_Schedule) [`ScheduleRule`](/indie/Library-reference/package-indie-schedule#class_ScheduleRule)</Info>

***

<Anchor id="class_Var" />

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

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_Var_get" name="get" type="() -> T">
      Returns value of `Var[T]` object.
    </Field>

    <Field id="method_Var_set" name="set" type="(new_value) -> None">
      Sets value of `Var[T]` object.

      <Expandable title="parameters info">
        <Field name="new_value" type="T" required>
          New value that will be put to `Var` object.
        </Field>
      </Expandable>
    </Field>
  </Step>

  <Step title="Static methods" icon="cubes">
    <Field id="method_Var_new" name="new" type="(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.

      <Expandable title="parameters info">
        <Field name="init" type="T" required>
          Value that is written into `Var` object only once after the `Var` object was created.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

<Info>See also: [`Context.new_var()`](/indie/Library-reference/package-indie#method_Context_new_var) [`MutSeries[T]`](/indie/Library-reference/package-indie#class_MutSeries)</Info>

***

## Enums

<Anchor id="enum_format" />

### `format`

*enum*

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

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_format_INHERITED" name="INHERITED" type="indie.format">
      Indicator output values are formatted same as values of the main chart instrument.
    </Field>

    <Field id="const_format_PRICE" name="PRICE" type="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.
    </Field>

    <Field id="const_format_VOLUME" name="VOLUME" type="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`.
    </Field>
  </Step>
</Steps>

<Info>See also: [`@indicator()`](/indie/Library-reference/package-indie#decor_indicator)</Info>

***

<Anchor id="enum_line_style" />

### `line_style`

*enum*

Enum-like class with constants of line styles.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_line_style_SOLID" name="SOLID" type="indie.line_style">
      Built-in line style constant that determines how the line is rendered.
    </Field>

    <Field id="const_line_style_DASHED" name="DASHED" type="indie.line_style">
      Built-in line style constant that determines how the line is rendered.
    </Field>

    <Field id="const_line_style_DOTTED" name="DOTTED" type="indie.line_style">
      Built-in line style constant that determines how the line is rendered.
    </Field>
  </Step>
</Steps>

<Info>See also: [`@line()`](/indie/Library-reference/package-indie-plot#decor_line) [`@level()`](/indie/Library-reference/package-indie#decor_level) [`@fill()`](/indie/Library-reference/package-indie-plot#decor_fill)</Info>

***

<Anchor id="enum_source" />

### `source`

*enum*

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

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_source_OPEN" name="OPEN" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_HIGH" name="HIGH" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_LOW" name="LOW" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_CLOSE" name="CLOSE" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_VOLUME" name="VOLUME" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_HL2" name="HL2" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_HLC3" name="HLC3" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>

    <Field id="const_source_OHLC4" name="OHLC4" type="indie.source">
      Built-in source kind constant which corresponds to `Context`'s series field and is used to initialize source input parameter.
    </Field>
  </Step>
</Steps>

<Info>See also: [`@param.source()`](/indie/Library-reference/package-indie#decor_param_source)</Info>

***

<Anchor id="enum_time_frame_unit" />

### `time_frame_unit`

*enum*

Enum-like class with constants for time frame units.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_time_frame_unit_MINUTE" name="MINUTE" type="indie.time_frame_unit">
      Built-in constants that represent time frame units.
    </Field>

    <Field id="const_time_frame_unit_HOUR" name="HOUR" type="indie.time_frame_unit">
      Built-in constants that represent time frame units.
    </Field>

    <Field id="const_time_frame_unit_DAY" name="DAY" type="indie.time_frame_unit">
      Built-in constants that represent time frame units.
    </Field>

    <Field id="const_time_frame_unit_WEEK" name="WEEK" type="indie.time_frame_unit">
      Built-in constants that represent time frame units.
    </Field>

    <Field id="const_time_frame_unit_MONTH" name="MONTH" type="indie.time_frame_unit">
      Built-in constants that represent time frame units.
    </Field>
  </Step>
</Steps>

<Info>See also: [`TimeFrame`](/indie/Library-reference/package-indie#class_TimeFrame)</Info>

***
