Skip to content
Nexus Prop LLC

NexuScript 1.5

Technical analysis

Averages, oscillators and signals. Each call keeps its own memory, so it must run on every bar (the call-site rule).

ta.true_rangeHow far price really moved on this bar, gaps from the previous close included.ta.smaThe simple moving average: the plain mean of the last length values.ta.emaThe exponential moving average, which follows recent prices more closely than a simple average.ta.rmaWilder's moving average, a slower exponential average used inside RSI and ATR.ta.wmaThe weighted moving average, where newer values count more.ta.vwmaThe volume-weighted moving average: bars with more volume count more.ta.linregThe value of the best straight line through the last length values, at the newest bar.ta.highestThe highest of the last length values, this bar included.ta.lowestThe lowest of the last length values, this bar included.ta.since_highestHow many bars ago the highest of the last length values was.ta.since_lowestHow many bars ago the lowest of the last length values was.ta.stdevHow spread out the last length values are (the standard deviation).ta.mean_devThe average distance of the last length values from their mean.ta.sumThe total of the last length values.ta.rocThe rate of change: how many percent x moved over length bars.ta.percent_rankWhere x stands against the previous length values, from 0 to 100.ta.rsiThe Relative Strength Index, a 0 to 100 measure of how strong recent gains are against recent losses.ta.swmaA short smoothing over the last four values, with the middle two counted twice.ta.cumsumA running total of every value since the first bar.ta.changeHow much x changed since length bars ago.ta.atrThe Average True Range: how far price typically moves per bar.ta.stochThe stochastic oscillator: where x sits inside the high to low range of the last length bars.ta.macdThe MACD: the gap between a fast and a slow EMA, with a signal line and a histogram.ta.bandsBands around a moving average, set a number of standard deviations above and below it.ta.crossoverTrue on the bar where a moves from at or below b to above it.ta.crossunderTrue on the bar where a moves from at or above b to below it.ta.crossTrue on the bar where a crosses b in either direction.ta.bars_sinceHow many bars ago a condition was last true.ta.value_whenThe value x had the last time a condition was true.ta.cciThe Commodity Channel Index: how far x is from its mean, in units of its mean deviation.ta.mfiThe Money Flow Index: a 0 to 100 measure of buying against selling pressure, weighted by volume.ta.almaThe Arnaud Legoux moving average: a Gaussian-weighted average that can lean towards the newest bars.ta.pivot_highA swing high: the value right bars ago when it is above the left values before it and the right values after it.ta.pivot_lowA swing low: the value right bars ago when it is below the left values before it and the right values after it.ta.fill_missingThe latest value of x that was not missing: gaps are filled with the value before them.ta.demaThe double exponential moving average, which lags less than ta.ema.ta.temaThe triple exponential moving average, which lags even less than ta.dema.ta.t3Tillson's T3: a very smooth average built from six exponential averages.ta.psarThe Parabolic SAR: a trailing stop that follows the trend and speeds up as it runs.ta.cummaxThe highest value x has had so far on the chart.ta.cumminThe lowest value x has had so far on the chart.ml.lorentzian_knnA nearest-neighbour vote: how the bars whose features looked most like this bar's were labelled.

ta.true_range

functionNexuScript 1.0

How far price really moved on this bar, gaps from the previous close included.

Syntax

ta.true_range() -> Number

Returns

Number The largest of high - low, the distance from the previous close to high, and the distance from the previous close to low. On the first bar it is high - low.

Details

Worked out as max(high - low, abs(high - prev_close), abs(low - prev_close)). It keeps no memory of its own, so unlike the other ta functions it may be called anywhere in on bar, inside an if too.

Units and time zones

Price points, in the symbol's quote currency.

Missing values

Gives missing when a price it needs (this bar's high or low, or the previous close) is missing.

Example

plot("True range", ta.true_range(), style = "histogram")

See also

ta.atrhighlowclose

ta.sma

functionNexuScript 1.0

The simple moving average: the plain mean of the last length values.

Syntax

ta.sma(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The sum of the last length values, added oldest first, divided by length.

Details

Every value in the window counts the same. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let slow = ta.sma(close, 50)
plot("SMA 50", slow, color = color.orange)

See also

ta.emata.wmata.sum

ta.ema

functionNexuScript 1.0

The exponential moving average, which follows recent prices more closely than a simple average.

Syntax

ta.ema(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The smoothed value.

Details

It starts with ta.sma of its first length values. After that each bar is a * x + (1 - a) * previous, with a = 2 / (length + 1). It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the seeding again from scratch.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let fast = ta.ema(close, 9)
plot("Fast EMA", fast, color = color.blue)

See also

ta.smata.rmata.macd

ta.rma

functionNexuScript 1.0

Wilder's moving average, a slower exponential average used inside RSI and ATR.

Syntax

ta.rma(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The smoothed value.

Details

The same as ta.ema, but with a = 1 / length: it starts with ta.sma of its first length values, then each bar is a * x + (1 - a) * previous. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the seeding again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let smooth = ta.rma(close, 14)
plot("RMA 14", smooth)

See also

ta.emata.rsita.atr

ta.wma

functionNexuScript 1.0

The weighted moving average, where newer values count more.

Syntax

ta.wma(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The weighted mean of the last length values.

Details

The oldest value has weight 1 and the newest has weight length. The weighted sum is divided by length * (length + 1) / 2. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let weighted = ta.wma(close, 20)
plot("WMA 20", weighted, color = color.purple)

See also

ta.smata.emata.swma

ta.vwma

functionNexuScript 1.0

The volume-weighted moving average: bars with more volume count more.

Syntax

ta.vwma(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The average price weighted by volume.

Details

Worked out as ta.sum(x * volume, length) / ta.sum(volume, length). It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length bars in a row where both x and volume are valid. A missing value starts the warm-up again. It is also missing when the volume in the window adds up to 0.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let vw = ta.vwma(close, 20)
plot("VWMA 20", vw, color = color.teal)

See also

ta.smavolumeta.sum

ta.linreg

functionNexuScript 1.0

The value of the best straight line through the last length values, at the newest bar.

Syntax

ta.linreg(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number Where the least-squares line through the window sits on the current bar.

Details

It fits the straight line that is closest to the last length values (least squares) and gives that line's value on this bar. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let line = ta.linreg(close, 25)
plot("Regression", line, color = color.yellow)

See also

ta.smata.stdev

ta.highest

functionNexuScript 1.0

The highest of the last length values, this bar included.

Syntax

ta.highest(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The largest value in the window.

Details

The window is this bar and the length - 1 bars before it. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let top = ta.highest(high, 20)
plot("20 bar high", top, style = "step")

See also

ta.lowestta.since_highestmax

ta.lowest

functionNexuScript 1.0

The lowest of the last length values, this bar included.

Syntax

ta.lowest(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The smallest value in the window.

Details

The window is this bar and the length - 1 bars before it. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let bottom = ta.lowest(low, 20)
plot("20 bar low", bottom, style = "step")

See also

ta.highestta.since_lowestmin

ta.since_highest

functionNexuScript 1.0

How many bars ago the highest of the last length values was.

Syntax

ta.since_highest(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number A whole number from 0 (this bar) to length - 1. When two bars tie for the highest, the newer one counts.

Details

It looks at the same window as ta.highest. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

Bars.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let ago = ta.since_highest(high, 20)
plot("Bars since 20 bar high", ago)

See also

ta.highestta.since_lowestta.bars_since

ta.since_lowest

functionNexuScript 1.0

How many bars ago the lowest of the last length values was.

Syntax

ta.since_lowest(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number A whole number from 0 (this bar) to length - 1. When two bars tie for the lowest, the newer one counts.

Details

It looks at the same window as ta.lowest. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

Bars.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let ago = ta.since_lowest(low, 20)
plot("Bars since 20 bar low", ago)

See also

ta.lowestta.since_highestta.bars_since

ta.stdev

functionNexuScript 1.0

How spread out the last length values are (the standard deviation).

Syntax

ta.stdev(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The population standard deviation of the window.

Details

It takes the mean of the window, adds up the squared distance of each value from it, divides by length (not length - 1) and takes the square root. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let spread = ta.stdev(close, 20)
plot("Std dev 20", spread)

See also

ta.bandsta.mean_devta.sma

ta.mean_dev

functionNexuScript 1.0

The average distance of the last length values from their mean.

Syntax

ta.mean_dev(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The mean absolute deviation of the window.

Details

It takes the mean of the window, then the average of how far each value is from it, ignoring the sign. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let typical = ta.mean_dev(hlc3, 20)
plot("Mean deviation", typical)

See also

ta.stdevta.smaabs

ta.sum

functionNexuScript 1.0

The total of the last length values.

Syntax

ta.sum(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The sum of the window, added oldest first.

Details

Use ta.cumsum for a running total that never forgets. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let vol = ta.sum(volume, 12)
plot("Volume, last hour", vol, style = "columns")

See also

ta.cumsumta.smasum

ta.roc

functionNexuScript 1.0

The rate of change: how many percent x moved over length bars.

Syntax

ta.roc(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number 100 * (x - before) / before, where before is the value length bars ago.

Details

A positive number means x is higher than it was, a negative one that it is lower. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

Percent.

Missing values

Gives missing for the first length bars, when x or its value length bars ago is missing, and when that earlier value is 0.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let pct = ta.roc(close, 12)
plot("Change, percent", pct, style = "histogram")

See also

ta.change%

ta.percent_rank

functionNexuScript 1.0

Where x stands against the previous length values, from 0 to 100.

Syntax

ta.percent_rank(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The share of the previous length values that are at or below x, as a percent.

Details

The current value is compared with the length values before it; it is not part of the window itself. 100 means x is at least as high as all of them. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

Percent, 0 to 100.

Missing values

Gives missing until it has seen length + 1 values, and whenever x or any of the previous length values is missing.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let rank = ta.percent_rank(close, 50)
plot("Percent rank", rank)

See also

ta.highestta.lowestta.stoch

ta.rsi

functionNexuScript 1.0

The Relative Strength Index, a 0 to 100 measure of how strong recent gains are against recent losses.

Syntax

ta.rsi(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number A number from 0 to 100. It is 100 when there were no losses at all.

Details

Each bar's change is split into a gain (or 0) and a loss (or 0). Both are smoothed with ta.rma over length, and the result is 100 - 100 / (1 + gains / losses). It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

A 0 to 100 scale.

Missing values

Gives missing until it has seen length + 1 valid values in a row (the first bar has no change yet). A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let strength = ta.rsi(close, 14)
plot("RSI", strength, color = color.purple)

See also

ta.rmata.stochta.change

ta.swma

functionNexuScript 1.0

A short smoothing over the last four values, with the middle two counted twice.

Syntax

ta.swma(x::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.

Returns

Number (a + 2b + 2c + d) / 6, where a is the value three bars ago and d is this bar's.

Details

The window is always four bars, so there is no length to give. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing for the first three bars, and whenever any of the four values is missing.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let smooth = ta.swma(close)
plot("Smoothed close", smooth)

See also

ta.wmata.sma

ta.cumsum

functionNexuScript 1.0

A running total of every value since the first bar.

Syntax

ta.cumsum(x::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.

Returns

Number The sum of every valid x so far.

Details

It never forgets. Use ta.sum for a total over a fixed number of bars. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Missing values are skipped and do not reset the total. It gives missing only until the first valid value arrives.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let balance = ta.cumsum(close > open ? volume : -volume)
plot("Running volume balance", balance)

See also

ta.sumsum

ta.change

functionNexuScript 1.0

How much x changed since length bars ago.

Syntax

ta.change(x::Number, length::Number = 1) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixed1How many bars back to compare with. A fixed whole number from 1 to 20,000; 1 compares with the previous bar.

Returns

Number x minus its value length bars ago.

Details

ta.change(close) is the same as close - close[1], but it works on any number worked out in the script, not only on named series. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing for the first length bars, and when x or its value length bars ago is missing.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Examples

let move = ta.change(close)
plot("Bar change", move, style = "histogram")
let hour_move = ta.change(close, length = 12)
plot("Change over an hour", hour_move)

See also

ta.roc-bar.history

ta.atr

functionNexuScript 1.0

The Average True Range: how far price typically moves per bar.

Syntax

ta.atr(length::Number) -> Number

Parameters

NameTypeDefaultDescription
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number The smoothed true range.

Details

Worked out as ta.rma(ta.true_range(), length). It reads the chart's own high, low and close, so it takes no series. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

Price points, in the symbol's quote currency.

Missing values

Gives missing until it has seen length valid true ranges in a row. A missing price starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let range = ta.atr(14)
plot("ATR", range)
plot("Stop below", close - 2 * range, color = color.red)

See also

ta.true_rangeta.rmata.stdev

ta.stoch

functionNexuScript 1.0

The stochastic oscillator: where x sits inside the high to low range of the last length bars.

Syntax

ta.stoch(x::Number, high::Number, low::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe value to place in the range, usually close.
highNumberrequiredThe series whose highest value is the top of the range, usually high.
lowNumberrequiredThe series whose lowest value is the bottom of the range, usually low.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number A number from 0 (at the lowest low) to 100 (at the highest high). It is 50 when the range is 0.

Details

Worked out as 100 * (x - lowest(low)) / (highest(high) - lowest(low)) over the last length bars. Smooth it with ta.sma for the usual slow line. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

A 0 to 100 scale.

Missing values

Gives missing until high and low have each had length valid values in a row, and whenever x is missing. A missing high or low starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let k = ta.stoch(close, high, low, 14)
let d = ta.sma(k, 3)
plot("%K", k, color = color.blue)
plot("%D", d, color = color.orange)

See also

ta.highestta.lowestta.rsi

ta.macd

functionNexuScript 1.0

The MACD: the gap between a fast and a slow EMA, with a signal line and a histogram.

Syntax

ta.macd(x::Number, fast::Number, slow::Number, signal::Number) -> (macd = Number, signal = Number, hist = Number)

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
fastNumberfixedrequiredBars for the fast EMA. A fixed whole number from 1 to 20,000, usually 12.
slowNumberfixedrequiredBars for the slow EMA. A fixed whole number from 1 to 20,000, usually 26.
signalNumberfixedrequiredBars for the EMA of the MACD line. A fixed whole number from 1 to 20,000, usually 9.

Returns

(macd = Number, signal = Number, hist = Number) A tuple of three numbers: macd is ta.ema(x, fast) - ta.ema(x, slow), signal is the EMA of macd over signal bars, and hist is macd - signal.

Details

Read the parts by name (m.hist) or take them in order: let (line, sig, hist) = ta.macd(close, 12, 26, 9). It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Each part is missing until it has warmed up: macd after slow valid values in a row (when slow is the longer length), signal and hist after signal - 1 more. A missing input starts all three again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302one of the lengths is not fixed (it changes from bar to bar)
  • NS420one of the lengths is outside 1 to 20,000 when the script runs

Examples

let (line, sig, hist) = ta.macd(close, 12, 26, 9)
plot("MACD", line, color = color.blue)
plot("Signal", sig, color = color.orange)
plot("Histogram", hist, style = "histogram")
let m = ta.macd(close, 12, 26, 9)
plot("Histogram", m.hist, style = "columns", color = m.hist >= 0 ? color.green : color.red)

See also

ta.ematuplelet

ta.bands

functionNexuScript 1.0

Bands around a moving average, set a number of standard deviations above and below it.

Syntax

ta.bands(x::Number, length::Number, mult::Number = 2) -> (basis = Number, upper = Number, lower = Number)

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.
multNumber2How many standard deviations the upper and lower bands sit from the middle.

Returns

(basis = Number, upper = Number, lower = Number) A tuple of three numbers: basis is ta.sma(x, length), upper is basis + mult * ta.stdev(x, length), and lower is basis - mult * ta.stdev(x, length).

Details

Read the parts by name (b.upper) or take them in order with let (basis, upper, lower) = ta.bands(close, 20). The standard deviation is the population one, as in ta.stdev. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

All three parts are missing until it has seen length valid values in a row, or when mult is missing. A missing input starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302the length is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420the length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Examples

let (basis, upper, lower) = ta.bands(close, 20)
plot("Basis", basis, color = color.gray)
plot("Upper", upper, color = color.blue)
plot("Lower", lower, color = color.blue)
band("Upper", "Lower", color = color.fade(color.blue, 85))
let wide = ta.bands(close, 20, mult = 3)
if close > wide.upper
    marker("Stretched")
end

See also

ta.smata.stdevbandtuple

ta.crossover

functionNexuScript 1.0

True on the bar where a moves from at or below b to above it.

Syntax

ta.crossover(a::Number, b::Number) -> Bool

Parameters

NameTypeDefaultDescription
aNumberrequiredThe series that crosses, such as a fast average.
bNumberrequiredThe series it crosses, such as a slow average or a fixed level.

Returns

Bool true when a was at or below b on the previous call and is above it now.

Details

It remembers both values from the previous bar. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives false when a or b is missing now or was missing on the previous bar.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let fast = ta.ema(close, 9)
let slow = ta.ema(close, 21)
if ta.crossover(fast, slow)
    marker("Up", position = "below", shape = "arrow_up", color = color.green)
end

See also

ta.crossunderta.cross>

ta.crossunder

functionNexuScript 1.0

True on the bar where a moves from at or above b to below it.

Syntax

ta.crossunder(a::Number, b::Number) -> Bool

Parameters

NameTypeDefaultDescription
aNumberrequiredThe series that crosses, such as a fast average.
bNumberrequiredThe series it crosses, such as a slow average or a fixed level.

Returns

Bool true when a was at or above b on the previous call and is below it now.

Details

It remembers both values from the previous bar. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives false when a or b is missing now or was missing on the previous bar.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let strength = ta.rsi(close, 14)
let down = ta.crossunder(strength, 70)
if down
    marker("Off the top", shape = "arrow_down", color = color.red)
end

See also

ta.crossoverta.cross<

ta.cross

functionNexuScript 1.0

True on the bar where a crosses b in either direction.

Syntax

ta.cross(a::Number, b::Number) -> Bool

Parameters

NameTypeDefaultDescription
aNumberrequiredThe first series.
bNumberrequiredThe second series, or a fixed level.

Returns

Bool true when ta.crossover(a, b) or ta.crossunder(a, b) would be true on this bar.

Details

It remembers both values from the previous bar. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives false when a or b is missing now or was missing on the previous bar.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let mid = ta.sma(close, 20)
let crossed = ta.cross(close, mid)
if crossed
    background(color.fade(color.yellow, 85))
end

See also

ta.crossoverta.crossunder

ta.bars_since

functionNexuScript 1.0

How many bars ago a condition was last true.

Syntax

ta.bars_since(cond::Bool) -> Number

Parameters

NameTypeDefaultDescription
condBoolrequiredThe condition to watch, true or false on each bar.

Returns

Number 0 on a bar where cond is true, then 1, 2, 3 and so on until it is true again.

Details

It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Units and time zones

Bars.

Missing values

Gives missing until cond has been true at least once. A Bool is never missing, so nothing else restarts it.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let since_up = ta.bars_since(close > open)
plot("Bars since an up bar", since_up)

See also

ta.value_whenta.since_highestBool

ta.value_when

functionNexuScript 1.0

The value x had the last time a condition was true.

Syntax

ta.value_when(cond::Bool, x::Number, occurrence::Number = 0) -> Number

Parameters

NameTypeDefaultDescription
condBoolrequiredThe condition to watch, true or false on each bar.
xNumberrequiredThe value to remember on the bars where cond is true.
occurrenceNumberfixed0NexuScript 1.5: which match to give, counting back from the newest: 0 the latest, 1 the one before it, up to 100. Fixed.

Returns

Number The value of x on the most recent bar where cond was true, this bar included (or, with occurrence, on an earlier match).

Details

Only the latest occurrence + 1 matches are kept. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Compute first, decide after. Each place you write it keeps its own memory.

Missing values

Gives missing until cond has been true at least once. If x was missing on that bar, the remembered value is missing until cond is true again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let fast = ta.ema(close, 9)
let slow = ta.ema(close, 21)
let up = ta.crossover(fast, slow)
let entry = ta.value_when(up, close)
plot("Price at last cross up", entry, style = "step")

See also

ta.bars_sinceta.crossover

ta.cci

functionNexuScript 1.5

The Commodity Channel Index: how far x is from its mean, in units of its mean deviation.

Syntax

ta.cci(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number (x - mean) / (0.015 * deviation) over the window.

Details

The mean is ta.sma(x, length) and the deviation ta.mean_dev(x, length), worked out from the same window. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row, and on a bar where every value of the window is the same (the deviation is 0).

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let cci = ta.cci(hlc3, 20)
plot("CCI", cci)

See also

ta.mean_devta.smata.rsi

ta.mfi

functionNexuScript 1.5

The Money Flow Index: a 0 to 100 measure of buying against selling pressure, weighted by volume.

Syntax

ta.mfi(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number A number from 0 to 100; 100 when there was no selling flow in the window.

Details

Each bar's flow is x * volume; it counts as buying when x rose from the previous bar and as selling when it fell. The result is 100 - 100 / (1 + buying / selling) over the last length bars. Pass the typical price hlc3 for the usual index. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Units and time zones

A 0 to 100 scale.

Missing values

Gives missing until it has seen length + 1 bars with a value and a volume in a row; a missing volume starts it again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let flow = ta.mfi(hlc3, 14)
plot("MFI", flow)

See also

ta.rsivolumehlc3

ta.alma

functionNexuScript 1.5

The Arnaud Legoux moving average: a Gaussian-weighted average that can lean towards the newest bars.

Syntax

ta.alma(x::Number, length::Number, offset::Number = 0.85, sigma::Number = 6) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.
offsetNumberfixed0.85Where the weight peaks across the window, from 0 (the oldest bar) to 1 (the newest). Fixed; 0.85 by default.
sigmaNumberfixed6How wide the bell of weights is: a larger sigma flattens it. Fixed, above 0; 6 by default.

Returns

Number The weighted mean of the last length values.

Details

The weight of the value at position k (0 the oldest) is exp(-(k - m)^2 / (2 * s^2)) with m = offset * (length - 1) and s = length / sigma; the weighted sum is divided by the sum of the weights. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing until it has seen length valid values in a row. A missing input gives missing and starts the warm-up again.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)
  • NS420offset is outside 0 to 1, or sigma is not above 0

Example

let smooth = ta.alma(close, 9, offset = 0.85, sigma = 6)
plot("ALMA 9", smooth, color = color.teal)

See also

ta.emata.wmata.sma

ta.pivot_high

functionNexuScript 1.5

A swing high: the value right bars ago when it is above the left values before it and the right values after it.

Syntax

ta.pivot_high(x::Number, left::Number, right::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to look for swings in, usually high.
leftNumberfixedrequiredHow many values before the swing must be lower. A fixed whole number from 1 to 20,000.
rightNumberfixedrequiredHow many values after the swing must be lower; the swing is known that many bars later. A fixed whole number from 1 to 20,000.

Returns

Number The swing's value, on the bar right bars after it; missing on every other bar.

Details

A value equal to the swing on either side means no swing. The answer comes right bars late, because only then are the later values known: read the swing's own bar with [right], such as high[2]. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing on bars that are not right bars after a swing, before left + right + 1 values were seen, and when any value of the window is missing.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let swing = ta.pivot_high(high, 2, 2)
if !ismissing(swing)
    marker("H", position = "above", price = swing, time = time[2], shape = "triangle_down", color = color.red)
end

See also

ta.pivot_lowta.value_whenta.highest

ta.pivot_low

functionNexuScript 1.5

A swing low: the value right bars ago when it is below the left values before it and the right values after it.

Syntax

ta.pivot_low(x::Number, left::Number, right::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to look for swings in, usually low.
leftNumberfixedrequiredHow many values before the swing must be higher. A fixed whole number from 1 to 20,000.
rightNumberfixedrequiredHow many values after the swing must be higher; the swing is known that many bars later. A fixed whole number from 1 to 20,000.

Returns

Number The swing's value, on the bar right bars after it; missing on every other bar.

Details

A value equal to the swing on either side means no swing. The answer comes right bars late. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing on bars that are not right bars after a swing, before left + right + 1 values were seen, and when any value of the window is missing.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let swing = ta.pivot_low(low, 3, 3)
let last_swing = ta.value_when(!ismissing(swing), swing)
plot("Last swing low", last_swing, style = "step")

See also

ta.pivot_highta.value_whenta.lowest

ta.fill_missing

functionNexuScript 1.5

The latest value of x that was not missing: gaps are filled with the value before them.

Syntax

ta.fill_missing(x::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.

Returns

Number x when it has a value, otherwise the last value it had.

Details

It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing only until x has had a value once.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let ratio = (close - low) / (high - low)
plot("Close in range", ta.fill_missing(ratio))

See also

coalesceismissingta.value_when

ta.dema

functionNexuScript 1.5

The double exponential moving average, which lags less than ta.ema.

Syntax

ta.dema(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number 2 * e - ta.ema(e, length), where e = ta.ema(x, length).

Details

Both averages are seeded like ta.ema. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing until both averages are seeded (about 2 * length - 1 valid values in a row).

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let fast = ta.dema(close, 20)
plot("DEMA 20", fast)

See also

ta.emata.temata.t3

ta.tema

functionNexuScript 1.5

The triple exponential moving average, which lags even less than ta.dema.

Syntax

ta.tema(x::Number, length::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.

Returns

Number 3 * e1 - 3 * e2 + e3: the average, the average of it, and the average of that.

Details

All three averages are seeded like ta.ema. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing until the three averages are seeded (about 3 * length - 2 valid values in a row).

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)

Example

let quick = ta.tema(close, 13)
plot("TEMA 13", quick)

See also

ta.emata.demata.t3

ta.t3

functionNexuScript 1.5

Tillson's T3: a very smooth average built from six exponential averages.

Syntax

ta.t3(x::Number, length::Number, factor::Number = 0.7) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.
lengthNumberfixedrequiredHow many bars to look back. A fixed whole number from 1 to 20,000.
factorNumberfixed0.7The volume factor from 0 to 1: higher follows the price more closely. Fixed; 0.7 by default.

Returns

Number The generalised double average ema(y) * (1 + factor) - ema(ema(y)) * factor, applied three times in a row.

Details

It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing until all six averages are seeded (about 6 * length - 5 valid values in a row).

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)
  • NS420the factor is not a number

Example

let t3 = ta.t3(close, 5, factor = 0.7)
plot("T3", t3, color = t3 > t3[1] ? color.green : color.red)

See also

ta.temata.demata.ema

ta.psar

functionNexuScript 1.5

The Parabolic SAR: a trailing stop that follows the trend and speeds up as it runs.

Syntax

ta.psar(start::Number = 0.02, increment::Number = 0.02, max::Number = 0.2) -> Number

Parameters

NameTypeDefaultDescription
startNumberfixed0.02The acceleration at the start of each trend. Fixed, above 0; 0.02 by default.
incrementNumberfixed0.02How much the acceleration grows each time the trend makes a new extreme. Fixed, above 0; 0.02 by default.
maxNumberfixed0.2The most the acceleration can reach. Fixed, above 0; 0.2 by default.

Returns

Number The stop for this bar: below the price in an uptrend, above it in a downtrend.

Details

It reads high, low and close. The second bar starts the trend from the direction of the closes; then each bar moves the stop by acceleration * (extreme - stop), never inside the previous two bars' range, and a bar that crosses the stop turns the trend and puts the stop at the old extreme. It gives exactly what the built-in Parabolic SAR draws. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing on the first bar only.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420start, increment or max is not above 0

Example

let sar = ta.psar(0.02, 0.02, 0.2)
plot("SAR", sar, style = "dots", color = close > sar ? color.green : color.red)

See also

ta.atrta.highestta.lowest

ta.cummax

functionNexuScript 1.5

The highest value x has had so far on the chart.

Syntax

ta.cummax(x::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.

Returns

Number The running maximum, from the first bar to this one.

Details

Missing values are skipped. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing only until x has had a value once.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let top = ta.cummax(high)
plot("All-time high on the chart", top, style = "step")

See also

ta.cumminta.highestta.cumsum

ta.cummin

functionNexuScript 1.5

The lowest value x has had so far on the chart.

Syntax

ta.cummin(x::Number) -> Number

Parameters

NameTypeDefaultDescription
xNumberrequiredThe series to work on, such as close or any number worked out on each bar.

Returns

Number The running minimum, from the first bar to this one.

Details

Missing values are skipped. Together with ta.cummax it scales a series to 0 to 1 over everything seen so far. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

Gives missing only until x has had a value once.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar

Example

let osc = ta.rsi(close, 14) - 50
let lo = ta.cummin(osc)
let hi = ta.cummax(osc)
plot("Scaled", (osc - lo) / max(hi - lo, 1e-9))

See also

ta.cummaxta.lowestta.cumsum

ml.lorentzian_knn

functionNexuScript 1.5

A nearest-neighbour vote: how the bars whose features looked most like this bar's were labelled.

Syntax

ml.lorentzian_knn(features::Array{Number}, label::Number, neighbors::Number = 8, window::Number = 2000, stride::Number = 4, training::String = "recent") -> Number

Parameters

NameTypeDefaultDescription
featuresArray{Number}requiredThis bar's features: 1 to 10 numbers, the same number on every bar, usually scaled to 0 to 1, such as [rsi / 100, cci_scaled].
labelNumberrequiredThis bar's label, usually -1, 0 or 1 (what price did over the last few bars). It is stored with this bar's features.
neighborsNumberfixed8How many neighbours vote. Fixed; 8 by default.
windowNumberfixed2000How many bars of features and labels it keeps to compare with. Fixed; 2,000 by default.
strideNumberfixed4It compares every stride-th stored bar, so neighbours are spread out in time. Fixed; 4 by default.
trainingStringfixed"recent""recent" (the default) keeps the latest window bars; "earliest" keeps the first window bars of the chart and never replaces them. Fixed. One of "recent", "earliest".

Returns

Number The sum of the neighbours' labels: above 0 when most neighbours were labelled up, below 0 when most were labelled down.

Details

Each bar first stores its own features and label. Then it walks the stored bars, oldest first, every stride-th one, and works out the Lorentzian distance to each: the sum of log(1 + |a - b|) over the features, which lets one wild feature count less than a squared distance would. A stored bar at least as far as the last one accepted joins the neighbours; once there are more than neighbors, the oldest leaves and the bar for acceptance becomes the distance three quarters down the list. The neighbours carry over from one bar to the next. It counts one step for each stored bar it compares, so a 2,000-bar window fits the step budget on long one-minute charts. It keeps its own memory, so it must run on every bar: write it straight in on bar (or in a higher block or a function), never inside a for loop or an if whose condition changes from bar to bar. Each place you write it keeps its own memory.

Missing values

A bar whose features include missing never joins the neighbours. Gives 0 before any bar has joined.

Errors

  • NS300the call is inside a for loop, or inside an if or ? : whose condition changes from bar to bar
  • NS302a length or setting is not fixed (it changes from bar to bar); use a number, an input or a constant
  • NS420a length is outside 1 to 20,000 when the script runs (for example from an input without limits)
  • NS420fewer than 1 or more than 10 features, or a different number of features than on an earlier bar

Example

let f1 = ta.rsi(close, 14) / 100
let f2 = ta.rsi(close, 9) / 100
let label = close[4] < close ? -1 : close[4] > close ? 1 : 0
let vote = ml.lorentzian_knn([f1, f2], label, neighbors = 8)
plot("Vote", vote, style = "histogram")

See also

ta.rsilogArray