# Vex reference: Windows

| Name | What |
| --- | --- |
| [`highest`](#highest) | The highest x over the last n bars. |
| [`lowest`](#lowest) | The lowest x over the last n bars. |
| [`sum`](#sum) | The total of x over the last n bars. |
| [`stdev`](#stdev) | Standard deviation of x over the last n bars (population). |
| [`change`](#change) | How much x moved over n bars: x - prev(x, n). |
| [`roc`](#roc) | Rate of change: percent move of x over n bars. |
| [`total`](#total) | Running total of x from the first bar (empty values add nothing). |
| [`median`](#median) | The middle value of x over the last n bars. |
| [`dev`](#dev) | Mean absolute deviation of x from its n-bar average. |
| [`percentrank`](#percentrank) | Percent of the previous n values of x at or below this one (0 to 100). |
| [`linreg`](#linreg) | Linear regression: the least-squares line through the last n values of x, at this bar. |
| [`correlation`](#correlation) | Correlation of a and b over the last n bars (-1 to 1). |
| [`loop_score`](#loop-score) | The for-loop score: for each bar back from `from` to `to`, +1 if x is above it now, -1 if not (or if either is empty). |
| [`prev`](#prev) | x as it was n bars ago (empty before the first bar, unless x has a starts line). |

## highest

```vex
highest(x, n)
```

The highest x over the last n bars.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.highest(source, length)`

**Example**

```vex
plot(highest(high, 20))
```

See also: [lowest](/documentation/vex/reference/windows#lowest), [donchian](/documentation/vex/reference/indicators#donchian)

## lowest

```vex
lowest(x, n)
```

The lowest x over the last n bars.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.lowest(source, length)`

**Example**

```vex
plot(lowest(low, 20))
```

See also: [highest](/documentation/vex/reference/windows#highest), [donchian](/documentation/vex/reference/indicators#donchian)

## sum

```vex
sum(x, n)
```

The total of x over the last n bars.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `math.sum(source, length)`

**Example**

```vex
plot(sum(volume, 24))
```

See also: [total](/documentation/vex/reference/windows#total), [count](/documentation/vex/reference/events#count)

## stdev

```vex
stdev(x, n)
```

Standard deviation of x over the last n bars (population).

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.stdev(source, length)`

**Example**

```vex
plot(stdev(close, 20))
```

## change

```vex
change(x, n = 1)
```

How much x moved over n bars: x - prev(x, n).

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 1 when left out

**Returns:** a number per bar

**In Pine Script:** `ta.change(source, length)`

**Example**

```vex
plot(change(close))
```

## roc

```vex
roc(x, n)
```

Rate of change: percent move of x over n bars.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.roc(source, length)`

**Example**

```vex
plot(roc(close, 10))
```

## total

```vex
total(x)
```

Running total of x from the first bar (empty values add nothing).

**Arguments**

- `x`: a number per bar

**Returns:** a number per bar

**In Pine Script:** `ta.cum(source)`

**Example**

```vex
plot(total(volume))
```

## median

```vex
median(x, n)
```

The middle value of x over the last n bars.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.median(source, length)`

**Example**

```vex
plot(median(close, 20))
```

## dev

```vex
dev(x, n)
```

Mean absolute deviation of x from its n-bar average.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.dev(source, length)`

**Example**

```vex
plot(dev(close, 20))
```

## percentrank

```vex
percentrank(x, n)
```

Percent of the previous n values of x at or below this one (0 to 100).

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.percentrank(source, length)`

**Example**

```vex
plot(percentrank(volume, 100))
```

## linreg

```vex
linreg(x, n)
```

Linear regression: the least-squares line through the last n values of x, at this bar.

**Arguments**

- `x`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.linreg(source, length, 0)`

**Example**

```vex
plot(linreg(close, 50))
```

## correlation

```vex
correlation(a, b, n)
```

Correlation of a and b over the last n bars (-1 to 1).

**Arguments**

- `a`: a number per bar
- `b`: a number per bar
- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `ta.correlation(source1, source2, length)`

**Example**

```vex
plot(correlation(close, volume, 50))
```

## loop_score

```vex
loop_score(x, from, to)
```

The for-loop score: for each bar back from `from` to `to`, +1 if x is above it now, -1 if not (or if either is empty).

For each bar back from `from` to `to`: +1 when x is above that bar's value now, -1 when it isn't (or either is empty). It is the for-loop many Pine trend scores use, done without a loop.

**Arguments**

- `x`: a number per bar
- `from`: a whole number, 0 to 5000, fixed: a number or a setting
- `to`: a whole number of bars, 1 to 5000, fixed: a number or a setting

**Returns:** a number per bar

**In Pine Script:** `for i = from to to: score += x > x[i] ? 1 : -1`

**Example**

```vex
plot(loop_score(rsi(close, 14), 1, 45))
```

See also: [Your own functions](/documentation/vex/your-own-functions)

## prev

```vex
prev(x, n = 1)
```

x as it was n bars ago (empty before the first bar, unless x has a starts line).

**Arguments**

- `x`: a number per bar
- `n`: a whole number, 0 to 5000, fixed: a number or a setting; 1 when left out

**Returns:** a number per bar

**In Pine Script:** `source[n]`

**Example**

```vex
plot(close - prev(close), "Change")
plot(close - prev(close, 10), "10-bar change")
```

See also: [Looking back: prev](/documentation/vex/looking-back-prev), [Values that carry over: starts](/documentation/vex/values-that-carry-over-starts)
