# Vex reference: Indicators

| Name | What |
| --- | --- |
| [`rsi`](#rsi) | Wilder's relative strength index, 0 to 100. |
| [`atr`](#atr) | Average true range over n bars (Wilder smoothing). |
| [`cci`](#cci) | Commodity channel index on hlc3. |
| [`mfi`](#mfi) | Money flow index on hlc3 and volume, 0 to 100. |
| [`bands`](#bands) | Bollinger bands: the SMA, and mult standard deviations above and below. |
| [`macd`](#macd) | MACD: fast EMA minus slow EMA, its EMA signal, and the gap between them. |
| [`stoch`](#stoch) | Stochastic: where the close sits in the n-bar range (0 to 100), smoothed, and its average. |
| [`donchian`](#donchian) | Donchian channel: the highest high and lowest low of the last n bars, and their middle. |
| [`pivot_high`](#pivot-high) | A pivot high: x of the bar `right` bars back when it is higher than the `left` bars before it and the `right` bars after it; empty elsewhere. It is given on the bar that confirms it (`right` bars later); plot it with offset = -right to draw it on the pivot bar. |
| [`pivot_low`](#pivot-low) | A pivot low: x of the bar `right` bars back when it is lower than the `left` bars before it and the `right` bars after it; empty elsewhere. Given on the bar that confirms it. |
| [`ichimoku`](#ichimoku) | Ichimoku: the conversion and base lines (the middle of the n-bar high-low range) and the leading spans as worked out on each bar. Draw the spans 25 bars ahead with offset = 25, and the lagging line as plot(close, offset = -25). |
| [`keltner`](#keltner) | Keltner channel: an EMA, and mult ATRs above and below it. |
| [`williams_r`](#williams-r) | Williams %R: where the close sits in the n-bar range, -100 at the low to 0 at the high. |
| [`stochrsi`](#stochrsi) | Stochastic RSI: the stochastic of the RSI, smoothed, and its average. |
| [`cmf`](#cmf) | Chaikin money flow: where closes sit in their bars, weighted by volume, over n bars (-1 to 1). |
| [`dmi`](#dmi) | Directional movement: +DI, -DI and the ADX trend strength. |
| [`supertrend`](#supertrend) | Supertrend on hl2: a trailing line under the price in an up trend (dir 1), over it in a down trend (dir -1). |
| [`psar`](#psar) | Parabolic SAR: a stop that accelerates with the trend; dir 1 when it sits under the price. |

## rsi

```vex
rsi(x, n)
```

Wilder's relative strength index, 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.rsi(source, length)`

**Example**

```vex
r = rsi(close, 14)
plot(r, "RSI")
level(70, 30)
```

## atr

```vex
atr(n)
```

Average true range over n bars (Wilder smoothing).

**Arguments**

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

**Returns:** a number per bar

**In Pine Script:** `ta.atr(length)`

**Example**

```vex
plot(atr(14))
```

See also: [tr](/documentation/vex/reference/bar-values#tr), [keltner](/documentation/vex/reference/indicators#keltner)

## cci

```vex
cci(n)
```

Commodity channel index on hlc3.

**Arguments**

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

**Returns:** a number per bar

**In Pine Script:** `ta.cci(hlc3, length)`

**Example**

```vex
plot(cci(20))
```

## mfi

```vex
mfi(n)
```

Money flow index on hlc3 and volume, 0 to 100.

**Arguments**

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

**Returns:** a number per bar

**In Pine Script:** `ta.mfi(hlc3, length)`

**Example**

```vex
plot(mfi(14))
```

## bands

```vex
bands(x, n, mult = 2)
```

Bollinger bands: the SMA, and mult standard deviations above and below.

Pine's ta.bb gives [middle, upper, lower]; here they are .mid, .upper and .lower.

**Arguments**

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

**Returns:** several parts: .upper .mid .lower

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

**Example**

```vex
name("Bollinger", where = chart)

b = bands(close, 20, 2)
plot(b.upper, "Upper")
plot(b.mid, "Middle")
plot(b.lower, "Lower")
fill(b.upper, b.lower)
```

## macd

```vex
macd(x, fast = 12, slow = 26, signal = 9)
```

MACD: fast EMA minus slow EMA, its EMA signal, and the gap between them.

**Arguments**

- `x`: a number per bar
- `fast`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 12 when left out
- `slow`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 26 when left out
- `signal`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 9 when left out

**Returns:** several parts: .line .signal .hist

**In Pine Script:** `ta.macd(source, fast, slow, signal)`

**Example**

```vex
m = macd(close, 12, 26, 9)
plot(m.hist, "Histogram", style = bars, color = m.hist > 0 ? up : down)
plot(m.line, "MACD", color = blue)
plot(m.signal, "Signal", color = orange)
level(0)
```

## stoch

```vex
stoch(n = 14, ksmooth = 1, dsmooth = 3)
```

Stochastic: where the close sits in the n-bar range (0 to 100), smoothed, and its average.

**Arguments**

- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left out
- `ksmooth`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 1 when left out
- `dsmooth`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 3 when left out

**Returns:** several parts: .k .d

**In Pine Script:** `ta.sma(ta.stoch(close, high, low, n), ksmooth)`

**Example**

```vex
s = stoch(14, 1, 3)
plot(s.k, "%K")
plot(s.d, "%D")
level(80, 20)
```

## donchian

```vex
donchian(n = 20)
```

Donchian channel: the highest high and lowest low of the last n bars, and their middle.

**Arguments**

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

**Returns:** several parts: .upper .mid .lower

**Example**

```vex
d = donchian(20)
plot(d.upper, "upper")
plot(d.mid, "mid")
plot(d.lower, "lower")
```

## pivot_high

```vex
pivot_high(x, left = 5, right = 5)
```

A pivot high: x of the bar `right` bars back when it is higher than the `left` bars before it and the `right` bars after it; empty elsewhere. It is given on the bar that confirms it (`right` bars later); plot it with offset = -right to draw it on the pivot bar.

Like Pine's, the value comes on the bar that confirms the pivot, `right` bars after it, so it never repaints. `offset = -right` draws it on the pivot bar itself.

**Arguments**

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

**Returns:** a number per bar

**In Pine Script:** `ta.pivothigh(source, leftbars, rightbars)`

**Example**

```vex
name("Pivots", where = chart)

ph = pivot_high(high, 5, 5)
pl = pivot_low(low, 5, 5)
plot(ph, "Pivot high", style = dots, width = 3, color = red, offset = -5)
plot(pl, "Pivot low", style = dots, width = 3, color = green, offset = -5)
```

See also: [pivot_low](/documentation/vex/reference/indicators#pivot-low), [plot](/documentation/vex/reference/drawing#plot)

## pivot_low

```vex
pivot_low(x, left = 5, right = 5)
```

A pivot low: x of the bar `right` bars back when it is lower than the `left` bars before it and the `right` bars after it; empty elsewhere. Given on the bar that confirms it.

**Arguments**

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

**Returns:** a number per bar

**In Pine Script:** `ta.pivotlow(source, leftbars, rightbars)`

**Example**

```vex
name("Pivot lows", where = chart)

pl = pivot_low(low, 5, 5)
plot(pl, "Pivot low", style = dots, width = 3, color = green, offset = -5)
plot(when(not empty(pl), pl), "Last pivot low", style = steps, color = grey)
```

See also: [pivot_high](/documentation/vex/reference/indicators#pivot-high), [when](/documentation/vex/reference/events#when)

## ichimoku

```vex
ichimoku(conversion = 9, base = 26, span_b = 52)
```

Ichimoku: the conversion and base lines (the middle of the n-bar high-low range) and the leading spans as worked out on each bar. Draw the spans 25 bars ahead with offset = 25, and the lagging line as plot(close, offset = -25).

The spans are worked out on each bar and drawn 25 bars ahead with `offset = 25` (a displacement of 26 less one); the lagging line is the close drawn 25 bars back.

**Arguments**

- `conversion`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 9 when left out
- `base`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 26 when left out
- `span_b`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 52 when left out

**Returns:** several parts: .conversion .base .span_a .span_b

**Example**

```vex
name("Ichimoku", where = chart)

ich = ichimoku(9, 26, 52)
plot(ich.conversion, "Conversion", color = blue)
plot(ich.base, "Base", color = maroon)
plot(ich.span_a, "Span A", color = green, offset = 25)
plot(ich.span_b, "Span B", color = red, offset = 25)
fill(ich.span_a, ich.span_b, opacity = 15)
plot(close, "Lagging", color = teal, offset = -25)
```

See also: [plot](/documentation/vex/reference/drawing#plot), [fill](/documentation/vex/reference/drawing#fill), [donchian](/documentation/vex/reference/indicators#donchian)

## keltner

```vex
keltner(x, n = 20, atr_n = 10, mult = 2)
```

Keltner channel: an EMA, and mult ATRs above and below it.

**Arguments**

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

**Returns:** several parts: .upper .mid .lower

**Example**

```vex
k = keltner(close, 20, 10, 2)
plot(k.upper, "upper")
plot(k.mid, "mid")
plot(k.lower, "lower")
```

## williams_r

```vex
williams_r(n = 14)
```

Williams %R: where the close sits in the n-bar range, -100 at the low to 0 at the high.

**Arguments**

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

**Returns:** a number per bar

**In Pine Script:** `ta.wpr(length)`

**Example**

```vex
plot(williams_r(14))
```

## stochrsi

```vex
stochrsi(x, rsi_n = 14, stoch_n = 14, ksmooth = 3, dsmooth = 3)
```

Stochastic RSI: the stochastic of the RSI, smoothed, and its average.

**Arguments**

- `x`: a number per bar
- `rsi_n`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left out
- `stoch_n`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 14 when left out
- `ksmooth`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 3 when left out
- `dsmooth`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 3 when left out

**Returns:** several parts: .k .d

**Example**

```vex
s = stochrsi(close, 14, 14, 3, 3)
plot(s.k, "k")
plot(s.d, "d")
```

## cmf

```vex
cmf(n = 20)
```

Chaikin money flow: where closes sit in their bars, weighted by volume, over n bars (-1 to 1).

**Arguments**

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

**Returns:** a number per bar

**Example**

```vex
plot(cmf(20))
```

## dmi

```vex
dmi(n = 14, smooth = 14)
```

Directional movement: +DI, -DI and the ADX trend strength.

**Arguments**

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

**Returns:** several parts: .plus .minus .adx

**In Pine Script:** `ta.dmi(diLength, adxSmoothing)`

**Example**

```vex
m = dmi(14, 14)
plot(m.plus, "+DI", color = green)
plot(m.minus, "-DI", color = red)
plot(m.adx, "ADX", color = blue)
```

## supertrend

```vex
supertrend(n = 10, factor = 3)
```

Supertrend on hl2: a trailing line under the price in an up trend (dir 1), over it in a down trend (dir -1).

Pine's arguments are the other way round (factor first), and its direction is -1 in an up trend; here `.dir` is 1 up and -1 down.

**Arguments**

- `n`: a whole number of bars, 1 to 5000, fixed: a number or a setting; 10 when left out
- `factor`: a number fixed when the script runs: a number or a setting; 3 when left out

**Returns:** several parts: .line .dir

**In Pine Script:** `ta.supertrend(factor, atrPeriod)`

**Example**

```vex
name("Supertrend", where = chart)

st = supertrend(10, 3)
plot(st.line, "Supertrend", color = st.dir > 0 ? up : down)
```

## psar

```vex
psar(start = 0.02, inc = 0.02, max = 0.2)
```

Parabolic SAR: a stop that accelerates with the trend; dir 1 when it sits under the price.

**Arguments**

- `start`: a number fixed when the script runs: a number or a setting; 0.02 when left out
- `inc`: a number fixed when the script runs: a number or a setting; 0.02 when left out
- `max`: a number fixed when the script runs: a number or a setting; 0.2 when left out

**Returns:** several parts: .value .dir

**In Pine Script:** `ta.sar(start, inc, max)`

**Example**

```vex
name("SAR", where = chart)

sar = psar(0.02, 0.02, 0.2)
plot(sar.value, "SAR", style = dots, color = sar.dir > 0 ? up : down)
```
