# Functions and methods

> Write your own functions with =>, return several values as a tuple, and call functions as methods. Libraries and import are not available.

## Your own functions

A function is a name, its parameters, `=>`, and a body. One line:

```pine
pct(a, b) => (a - b) / b * 100
```

Or several lines, indented; the last line is the result:

```pine
//@version=6
indicator("Band position")
bandPos(src, len, mult) =>
    [mid, up, lo] = ta.bb(src, len, mult)
    (src - lo) / (up - lo)
plot(bandPos(close, 20, 2), "%B", color = color.purple)
hline(1)
hline(0)
```

Each call keeps its own history, so calling a function that uses `ta.*` inside it twice with different arguments gives two independent results.

## Returning several values

Return a tuple and destructure it at the call:

```pine
//@version=6
indicator("Range stats", overlay = true)
rangeOf(len) =>
    hi = ta.highest(high, len)
    lo = ta.lowest(low, len)
    [hi, lo, (hi + lo) / 2]
[h, l, m] = rangeOf(30)
plot(h, "High", color = color.teal)
plot(l, "Low", color = color.red)
plot(m, "Mid", color = color.gray)
```

## Methods

A function declared with `method` can be called with a dot on its first argument. Built-in functions for arrays and drawings can be called the same way: `arr.push(x)` is `array.push(arr, x)`.

```pine
method spread(float a, float b) => a - b
d = close.spread(open)
```

## Libraries

Pine **libraries** (`library()` and `import user/name/1`) are not available on Tradequix: there is no library resolver. Copy the functions you need into your script. The [checker](/docs/check) flags imports for you.
