Reference: Windows

Vex reference: windows.

For AI tools: this page as Markdown · the whole language in one file

NameWhat
highestThe highest x over the last n bars.
lowestThe lowest x over the last n bars.
sumThe total of x over the last n bars.
stdevStandard deviation of x over the last n bars (population).
changeHow much x moved over n bars: x - prev(x, n).
rocRate of change: percent move of x over n bars.
totalRunning total of x from the first bar (empty values add nothing).
medianThe middle value of x over the last n bars.
devMean absolute deviation of x from its n-bar average.
percentrankPercent of the previous n values of x at or below this one (0 to 100).
linregLinear regression: the least-squares line through the last n values of x, at this bar.
correlationCorrelation of a and b over the last n bars (-1 to 1).
loop_scoreThe 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).
prevx as it was n bars ago (empty before the first bar, unless x has a starts line).

highest

1highest(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

1plot(highest(high, 20))

See also: lowest, donchian

lowest

1lowest(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

1plot(lowest(low, 20))

See also: highest, donchian

sum

1sum(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

1plot(sum(volume, 24))

See also: total, count

stdev

1stdev(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

1plot(stdev(close, 20))

change

1change(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

1plot(change(close))

roc

1roc(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

1plot(roc(close, 10))

total

1total(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

1plot(total(volume))

median

1median(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

1plot(median(close, 20))

dev

1dev(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

1plot(dev(close, 20))

percentrank

1percentrank(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

1plot(percentrank(volume, 100))

linreg

1linreg(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

1plot(linreg(close, 50))

correlation

1correlation(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

1plot(correlation(close, volume, 50))

loop_score

1loop_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

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

See also: Your own functions

prev

1prev(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

1plot(close - prev(close), "Change")2plot(close - prev(close, 10), "10-bar change")

See also: Looking back: prev, Values that carry over: starts