Parameter types and qualifiers solve different problems
A type describes the data; a qualifier constrains when it can vary. The hierarchy is const < input < simple < series. A simple int parameter accepts an input.int value but rejects a bar-dependent integer. Declaring only int does not guarantee a simple result. Explicit series cannot be weakened by casting to int. Reference types always carry series.
- Define functions at global scope. Keep plot() calls outside their bodies.
- Use an explicit parameter type when its default is na, when it has a qualifier, for exported function parameters, and for the first parameter of a method.
| Parameter choice | Use in this page | Constraint |
|---|---|---|
| series float source | Price passed to the EMA helper | Allows close or hl2 to change on each update |
| simple int length | EMA lookback from input.int | A length calculated from bar_index is too strong |
| float percent = 1.0 | Optional band distance | Omitting the argument selects 1.0 percent |
| const int parameter | A compile-time-only argument | Available for non-exported functions; input values are not const |
| Untyped parameter | General helpers when inference is intended | Each written call must retain consistent argument and result types |