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

# Input parameters

> Input parameters in Indie: the @param decorator, the types a parameter can take, and how each one appears in the settings dialog, how to add a help tooltip, and how to show a parameter only when a condition holds.

*Input parameters* provide a convenient way to change indicator's algorithm parameters without the need to change its
source code. For example, here is a simple indicator that calculates SMA with two parameters `src` and `length`:

```py theme={null}
# indie:lang_version = 5
from indie import indicator, param, source
from indie.algorithms import Sma

@indicator('Example')
@param.source('src', default=source.CLOSE, title='Source')
@param.int('length', default=12, min=1, title='Length')
def Main(self, src, length):
    sma = Sma.new(src, length)
    return sma[0]
```

Once this indicator is added to a chart, the values for the `length` and `source` parameters can be easily changed
in the indicator's *Settings* dialog:

![Figure 7.1. The Settings dialog of indicator.](https://mintcdn.com/takeprofit-a5dc0462/G8Lo_-_8Elf7cBMe/images/indie/Input-parameters/01-Settings_dialog.png?fit=max\&auto=format\&n=G8Lo_-_8Elf7cBMe\&q=85\&s=7a6385b89c734c5dafcb7aa7be7da286)

## How to add a parameter to an indicator

There are a few simple steps for adding an input parameter to an indicator:

* Add one of the `@param.*` decorators (e.g. `@param.int`) to the `Main` entry point of the indicator.
* Pass values for the two required arguments to the decorator:
  * `id` — which is unique string identifier of the parameter (the very first argument of any `@param.*` decorator),
  * `default` — which is a default value of the parameter.
* Pass values to optional arguments of the decorator if needed (this depends on the decorator type, they
  could differ). In the example above there are optional arguments `title` and `min`.
* Add a parameter to the `Main` function (after the `self` parameter) with the name matching the `id` of the
  parameter.

## Available parameter types

Indie supports several types of input parameters, they are:

* `int`, created with decorator [`@param.int`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_int)
* `bool`, created with decorator [`@param.bool`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_bool)
* `float`, created with decorator [`@param.float`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_float)
* `str`, created with decorator [`@param.str`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_str)
* source of type [`SeriesF`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_SeriesF), created with decorator [`@param.source`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_source)
* time frame of type [`TimeFrame`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_TimeFrame), created with decorator [`@param.time_frame`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_time_frame)
* calculation time frame, created with decorator [`@param.calc_time_frame`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_calc_time_frame)
* color of type [`Color`](https://takeprofit.com/docs/indie/Library-reference/package-indie#class_Color), created with decorator [`@param.color`](https://takeprofit.com/docs/indie/Library-reference/package-indie#decor_param_color)

## Grouping parameters

Every `@param.*` decorator takes an optional `group` keyword. Parameters that share the same `group` string are shown together under a section header in the *Settings* dialog:

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

@indicator('Example')
@param.int('fast_len', default=10, min=1, title='Fast length', group='Moving averages')
@param.int('slow_len', default=20, min=1, title='Slow length', group='Moving averages')
def Main(self, fast_len, slow_len):
    return self.close[0]
```

## Adding a help tooltip

Every `@param.*` decorator takes an optional `tooltip` keyword. When it is set, the *Settings* dialog shows an info icon
right after the parameter's title, and hovering it shows the text. Use it to explain what the parameter does or how
its options differ, without making the title long:

```py theme={null}
# indie:lang_version = 5
from indie import indicator, param, source
from indie.algorithms import Sma

@indicator('Example')
@param.source('src', default=source.CLOSE, title='Source')
@param.int('length', default=12, min=1, title='Length', tooltip='Number of bars the average is taken over')
def Main(self, src, length):
    sma = Sma.new(src, length)
    return sma[0]
```

The text must be a non-empty single line of at most 512 characters. A parameter without a `tooltip` shows no icon.

## Showing a parameter only when it applies

Every `@param.*` decorator takes an optional `show_if` keyword. The parameter then appears in the *Settings* dialog
only while the condition holds, which keeps the dialog short: show a few inputs by default and reveal the advanced ones
when the user asks for them.

A common pattern is a *Preset* select with a `Custom` option that reveals the inputs the presets set:

```py theme={null}
# indie:lang_version = 5
from indie import indicator, param, plot
from indie.algorithms import Sma, StdDev

@indicator('Adaptive Bands', overlay_main_pane=True)
@param.str('preset', default='Standard', options=['Standard', 'Wide', 'Custom'], title='Preset')
@param.int('length', default=20, min=1, title='Length', show_if='preset == Custom')
@param.float('mult', default=2.0, min=0.1, title='Width', show_if='preset == Custom')
@param.bool('smooth', default=False, title='Smooth the basis', show_if='preset == Custom')
@param.int('smooth_len', default=5, min=1, title='Smoothing length', show_if='smooth')
@plot.line('upper', 'Upper')
@plot.line('basis', 'Basis')
@plot.line('lower', 'Lower')
def Main(self, preset, length, mult, smooth, smooth_len):
    if preset == 'Standard':
        length, mult, smooth = 20, 2.0, False
    elif preset == 'Wide':
        length, mult, smooth = 20, 3.0, False
    basis = Sma.new(self.close, length)
    if smooth:
        basis = Sma.new(basis, smooth_len)
    dev = StdDev.new(self.close, length)
    return basis[0] + mult * dev[0], basis[0], basis[0] - mult * dev[0]
```

With the default preset the dialog shows only **Preset**. Choosing **Custom** reveals **Length**, **Width** and
**Smooth the basis**, and turning on **Smooth the basis** reveals **Smoothing length**.

### Condition forms

| Condition | Shows the parameter when | Referenced parameter |
| - | - | - |
| `'flag'` | `flag` is on | `@param.bool` |
| `'not flag'` | `flag` is off | `@param.bool` |
| `'p == A'` | `p` is `A` | `@param.str` with `options` |
| `'p == A \| B'` | `p` is `A` or `B` | `@param.str` with `options` |
| `'p != A'` | `p` is anything but `A` | `@param.str` with `options` |

Option names are written without quotes inside the condition. To reuse a condition on several parameters, put it in a
module-level constant, for example `CUSTOM = 'preset == Custom'`, and pass `show_if=CUSTOM`.

Conditions chain: a parameter is shown only if its own condition holds **and** the parameter it refers to is shown.
In the example, **Smoothing length** refers to `smooth`, so it stays hidden under the `Standard` and `Wide` presets
even if **Smooth the basis** was turned on earlier.

> [!WARNING]
>
> A hidden parameter keeps its value and is still passed to `Main`. Hiding it does not reset it to the default. If a
> preset should override the hidden inputs, `Main` has to do it, as the example does for `Standard` and `Wide`. Otherwise
> values the user set under `Custom` keep affecting the result after switching back to another preset.

### Compilation errors

The compiler checks every condition. It reports an error if the condition:

* refers to a parameter that does not exist, or to the parameter itself;
* creates a cycle, for example `a` depends on `b` and `b` depends on `a`;
* uses the `'flag'` or `'not flag'` form with a parameter that is not a `@param.bool`;
* uses `==` or `!=` with a parameter that is not a `@param.str` with `options`, or with a value that is not one of
  its options;
* uses `!=` in a way that excludes every option, so the parameter could never be shown;
* uses a word of the condition syntax, such as `not`, as a parameter id;
* is empty or longer than 256 characters.


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