Skip to content

ta ​

How do you compute an indicator on each bar? Call a ta.* function at the top level of your script, once per bar. Each call keeps its own state and sees every bar. The answers are TradingView's, except where an entry's warning says how they differ.

pine
//@version=6
indicator("Two averages", overlay = true)
fast = ta.ema(close, 9)
slow = ta.sma(close, 21)
plot(fast, "EMA 9", color.orange)
plot(slow, "SMA 21", color.blue)
// called on every bar, so the cross compares this bar with the one before
plotshape(ta.crossover(fast, slow), "Cross up", shape.triangleup, location.belowbar, color.green)

Four rules hold for every function on this page.

  • One state per call. Each ta.* call in your text keeps its own window. Two calls of ta.sma(close, 20) on two lines are two averages, and a call inside your own function keeps one state for each place that function is called from.
  • A call in a branch sees only the bars it runs on. Most functions count only their calls, so a bar the call skipped isn't in the window: ta.sma, ta.ema, ta.rma, ta.rsi, ta.highest, ta.stdev and every entry that says nothing about branches. The rest say how they read a skipped bar. Those that read their source bar by bar (ta.wma, ta.swma, ta.alma, ta.change, ta.mom, ta.roc, ta.percentrank, ta.hma, and the inner loops of ta.dev, ta.cci and ta.cog) treat it as holding the last value the call read. See functions and branches.
  • na in the middle of a series. Some functions skip a na and read the last length numbers; others read na while the hole is in their window. Each window function's entry says which. An infinity counts as na in every window.
  • Lengths are whole bars. A fractional length or offset is cut toward zero, so ta.wma(close, 15 / 2) is a 7-bar average. A length of 0 or less reads na.

ta.accdist ​

pine
series float ta.accdist

The accumulation/distribution line: the running sum of each bar's close location within its range, times its volume.

A bar with no range adds 0. A bar with a na price or volume reads na and adds nothing. It is a value, not a call: every read on one bar gives that bar's first answer, so read it on every bar. In a branch it sums only the bars where it runs.

ta.alma ​

pine
ta.alma(series, length, offset, sigma, floor) → series float

The Arnaud Legoux moving average: a Gaussian-weighted average whose peak sits at offset along the window.

The window always holds the last length bars, so a na in it makes the result na until the na leaves. In a branch, a skipped bar counts as the value the call last read.

ParameterDefaultDescription
series
series int/float
The values to average.
length
series int
9AmenoScript onlyHow many bars.
offset
simple int/float
0.85AmenoScript onlyWhere the weights peak, from 0 (the oldest bar) to 1 (the newest).
sigma
simple int/float
6AmenoScript onlyHow sharp the peak is. A larger value narrows it.
floor
simple bool
falsetrue rounds the peak's position down to a whole bar.

ta.atr ​

pine
ta.atr(length) → series float

The average true range: Wilder's moving average (ta.rma) of the true range.

On the first bar the true range is the bar's high minus its low. After bars the call skipped, the true range still reads the close of the bar just before.

ParameterDescription
length
simple int
How many bars to smooth over. It must be fixed for the run.

ta.barssince ​

pine
ta.barssince(condition) → series int

The number of bars since condition was last true: 0 on a bar where it is true, and na before it has ever been true.

The count goes up by one for each call, so a call inside a branch counts the bars it runs on.

ParameterDescription
condition
series bool
The test to look back for.
pine
//@version=6
indicator("Bars since the last up close")
since = ta.barssince(close > open) // 0 on an up bar, na before the first one
plot(since)

ta.bb ​

pine
ta.bb(series, length, mult) → [series float, series float, series float]

Bollinger Bands: [middle, upper, lower], the length-bar simple moving average and that average plus and minus mult standard deviations.

A na leaves the window as it was, as ta.sma and ta.stdev do.

ParameterDefaultDescription
series
series int/float
The values to measure.
length
series int
20AmenoScript onlyHow many bars.
mult
simple int/float
2AmenoScript onlyHow many standard deviations each band sits from the middle.
pine
//@version=6
indicator("Bollinger Bands", overlay = true)
[middle, upper, lower] = ta.bb(close, 20, 2) // a tuple of three series
plot(middle, "Basis", color.orange)
p1 = plot(upper, "Upper", color.blue)
p2 = plot(lower, "Lower", color.blue)
fill(p1, p2, color.new(color.blue, 90))

ta.bbw ​

pine
ta.bbw(series, length, mult) → series float

The Bollinger Band width: the distance between the bands as a percentage of the middle band.

It is (upper - lower) / middle * 100, and na where the middle is 0.

ParameterDefaultDescription
series
series int/float
The values to measure.
length
series int
20AmenoScript onlyHow many bars.
mult
simple int/float
2AmenoScript onlyHow many standard deviations each band sits from the middle.

ta.beta ​

AmenoScript only
ameno
ta.beta(y, x, length) → series float

The slope of y on x over the last length bars: their covariance divided by the variance of x. See the cross-section.

A bar where either value is na is left out, so the window is the last length bars where both were numbers. It reads na while the window fills, and where x didn't move.

ParameterDescription
y
series int/float
The series to explain, such as a coin's returns.
x
series int/float
The series it moves with, such as the market's returns.
length
series int
How many bars.
ameno
indicator("Beta to its own past")
r = close / close[1] - 1
plot(ta.beta(r, r[1], 30)) // AmenoScript only

ta.cci ​

pine
ta.cci(source, length) → series float

The commodity channel index: how far the source sits from its length-bar average, in units of 0.015 times the mean absolute deviation.

It reads na while a na is in the window. Where the deviation is 0, as on a flat window, it repeats its last value. In a branch, the average counts only the calls, and the deviation treats a skipped bar as the value the call last read.

ParameterDefaultDescription
source
series int/float
The values to measure.
length
series int
20AmenoScript onlyHow many bars.

ta.change ​

pine
ta.change(source, length) → series float

The source minus its value length bars ago.

The window always holds the last length + 1 bars, so a na at either end reads na. In a branch, a skipped bar counts as the value the call last read.

A bool source returns a number here

On a bool source this engine returns 1, 0 or -1, reading true as 1, where TradingView returns whether the value changed. Write cond != cond[1] for TradingView's answer.

ParameterDefaultDescription
source
series int/float/bool
The values to compare.
length
series int
1How many bars back to compare with.

ta.cmo ​

pine
ta.cmo(series, length) → series float

The Chande momentum oscillator: the sum of up moves minus the sum of down moves, over their total, times 100.

Each move is from one bar to the next, so a na takes the moves on both sides of it out of the sums. A window with no move reads na.

ParameterDefaultDescription
series
series int/float
The values to measure.
length
series int
9AmenoScript onlyHow many bars.

ta.cog ​

pine
ta.cog(source, length) → series float

The centre of gravity: a weighted sum of the last length values, newest weighted least, over their plain sum, negated.

It reads na while a na is in the window. In a branch, its weighted sum treats a skipped bar as the value the call last read.

ParameterDefaultDescription
source
series int/float
The values to measure.
length
series int
10AmenoScript onlyHow many bars.

ta.correlation ​

pine
ta.correlation(source1, source2, length) → series float

The Pearson correlation of two series over the last length bars, from -1 to 1.

Each mean skips its own na, so a hole in one series moves only that series' means. A window where either series is flat reads 0.

ParameterDescription
source1
series int/float
The first series.
source2
series int/float
The second series.
length
series int
How many bars.

ta.cov ​

AmenoScript only
ameno
ta.cov(source1, source2, length) → series float

The covariance of two series over the last length bars, dividing by length. See the cross-section.

A bar where either value is na is left out, so the window is the last length bars where both were numbers.

ParameterDescription
source1
series int/float
The first series.
source2
series int/float
The second series.
length
series int
How many bars.

ta.cross ​

pine
ta.cross(source1, source2) → series bool

Whether the two series crossed in either direction since the last call.

A bar where either value is na returns false and doesn't count, so the next bar compares with the last bar where both were numbers.

ParameterDescription
source1
series int/float
The first series.
source2
series int/float
The second series.

ta.crossover ​

pine
ta.crossover(source1, source2) → series bool

Whether source1 crossed above source2: it is above now, and was at or below on the last call.

A bar where either value is na returns false and doesn't count, so the next bar compares with the last bar where both were numbers.

ParameterDescription
source1
series int/float
The series that crosses.
source2
series int/float
The series it crosses.

ta.crossunder ​

pine
ta.crossunder(source1, source2) → series bool

Whether source1 crossed below source2: it is below now, and was at or above on the last call.

A bar where either value is na returns false and doesn't count.

ParameterDescription
source1
series int/float
The series that crosses.
source2
series int/float
The series it crosses.

ta.cum ​

pine
ta.cum(source) → series float

The running total of the source since the first bar.

A na bar reads na and adds nothing, and the total carries on after it.

ParameterDescription
source
series int/float
The values to add up.

ta.dev ​

pine
ta.dev(source, length) → series float

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

It reads na while a na is in the window. In a branch, a skipped bar counts as the value the call last read.

ParameterDescription
source
series int/float
The values to measure.
length
series int
How many bars.

ta.dmi ​

pine
ta.dmi(diLength, adxSmoothing) → [series float, series float, series float]

The directional movement index: [plusDI, minusDI, adx].

The first bar adds no movement, since each move is a change from the bar before. Where the smoothed true range is 0, each DI repeats its last value.

ParameterDefaultDescription
diLength
simple int
14AmenoScript onlyThe bars that smooth the directional movement and the true range.
adxSmoothing
simple int
14AmenoScript onlyThe bars that smooth the ADX.
pine
//@version=6
indicator("DMI")
[plusDI, minusDI, adx] = ta.dmi(14, 14)
plot(plusDI, "+DI", color.green)
plot(minusDI, "-DI", color.red)
plot(adx, "ADX", color.blue)

ta.ema ​

pine
ta.ema(source, length) → series float

The exponential moving average, which weights each bar 2 / (length + 1) against the average before it.

It reads na for the first length - 1 bars and starts from the simple average of the first length values. A na bar reads na and leaves the average as it was.

ParameterDescription
source
series int/float
The values to average.
length
simple int
How many bars. It must be fixed for the run: a length that changes keeps the first bar's.

ta.falling ​

pine
ta.falling(source, length) → series bool

Whether the source fell from each bar to the next over the last length bars.

A step with a na on either side leaves the count as it was.

ParameterDescription
source
series int/float
The values to test.
length
series int
How many falls in a row it takes.

ta.highest ​

pine
ta.highest(source, length) → series float
ta.highest(length) → series float

The highest value of the last length bars.

With one argument it reads high. The window is the last length numbers, read from the lengthth call on, so a na leaves it as it was. A length that changes from bar to bar reads the window of the new length.

ParameterDescription
source
series int/float
The values to search. With one argument, high.
length
series int
How many bars.

ta.highestbars ​

pine
ta.highestbars(source, length) → series int
ta.highestbars(length) → series int

How many bars back the highest of the last length bars was, as 0 or a negative number.

With one argument it reads high. Of equal highs, the newest wins. The offset counts bars, so a na hole or bars the call skipped push it further back.

ParameterDescription
source
series int/float
The values to search. With one argument, high.
length
series int
How many bars.

ta.hma ​

pine
ta.hma(source, length) → series float

The Hull moving average: ta.wma(2 * ta.wma(source, length / 2) - ta.wma(source, length), floor(sqrt(length))).

Both inner lengths are rounded down. Each weighted average treats a na, and a bar a branch skipped, as ta.wma does.

ParameterDescription
source
series int/float
The values to average.
length
simple int
How many bars. It must be fixed for the run.

ta.ichimoku ​

AmenoScript only
ameno
ta.ichimoku(conversionPeriods, basePeriods, laggingSpan2Periods, displacement) → [series float, series float, series float, series float, series float]

The Ichimoku lines: [conversion, base, leadA, leadB, lagging]. See AmenoScript's built-ins.

conversion and base are the midpoints of the highest high and lowest low over their periods, leadA is their mean, and leadB is the midpoint over laggingSpan2Periods. The leads come unshifted, so plot them with offset = displacement - 1 to draw the cloud ahead, as the chart's Ichimoku Cloud does. lagging is the close of displacement - 1 bars ago.

ParameterDefaultDescription
conversionPeriods
simple int
9Bars for the conversion line.
basePeriods
simple int
26Bars for the base line.
laggingSpan2Periods
simple int
52Bars for the second lead.
displacement
simple int
26How far the leads are meant to sit ahead, and the lagging line behind.
ameno
indicator("Ichimoku", overlay = true)
[conv, base, leadA, leadB, lag] = ta.ichimoku(9, 26, 52, 26) // AmenoScript only
plot(conv, "Conversion", color.blue)
plot(lag, "Lagging close", color.gray)
plot(base, "Base", color.red)
plot(leadA, "Lead A", color.green, offset = 25) // displacement - 1
plot(leadB, "Lead B", color.orange, offset = 25)

ta.iii ​

pine
series float ta.iii

The intraday intensity index: (2 * close - high - low) / (high - low) * volume.

A bar with no range reads na.

ta.kc ​

pine
ta.kc(series, length, mult, useTrueRange) → [series float, series float, series float]

Keltner Channels: [middle, upper, lower], the exponential average of the source and that average plus and minus mult times the exponential average of the range.

The range is the true range, or the plain high minus low with useTrueRange = false. On the first bar the true range is na, so the bands start a bar after the middle. After bars the call skipped, the true range still reads the close of the bar just before.

ParameterDefaultDescription
series
series int/float
The values to average.
length
series int
20AmenoScript onlyHow many bars, for both averages.
mult
simple int/float
2AmenoScript onlyHow many ranges each band sits from the middle.
useTrueRange
simple bool
truefalse measures each bar's high minus low.

ta.kcw ​

pine
ta.kcw(series, length, mult, useTrueRange) → series float

The Keltner Channel width: (upper - lower) / middle, as a ratio, not a percentage.

It reads na where the middle is 0. After bars the call skipped, the true range still reads the close of the bar just before.

ParameterDefaultDescription
series
series int/float
The values to average.
length
series int
20AmenoScript onlyHow many bars.
mult
simple int/float
2AmenoScript onlyHow many ranges each band sits from the middle.
useTrueRange
simple bool
truefalse measures each bar's high minus low.

ta.linreg ​

pine
ta.linreg(source, length, offset) → series float

The value of the least-squares line through the last length values, at offset bars back from the newest.

The window always holds the last length bars, so a na in it reads na. In a branch, the call keeps a ring of length + 1 slots by bar index: a slot no call wrote reads 0, and after skipped bars a slot keeps what a call length + 1 bars earlier wrote.

ParameterDefaultDescription
source
series int/float
The values to fit.
length
series int
How many bars.
offset
simple int
0AmenoScript onlyHow many bars back from the newest to read the line at.

ta.lowest ​

pine
ta.lowest(source, length) → series float
ta.lowest(length) → series float

The lowest value of the last length bars.

With one argument it reads low. A na leaves the window as it was, as in ta.highest.

ParameterDescription
source
series int/float
The values to search. With one argument, low.
length
series int
How many bars.

ta.lowestbars ​

pine
ta.lowestbars(source, length) → series int
ta.lowestbars(length) → series int

How many bars back the lowest of the last length bars was, as 0 or a negative number.

With one argument it reads low. Of equal lows, the newest wins. The offset counts bars, so a na hole or bars the call skipped push it further back.

ParameterDescription
source
series int/float
The values to search. With one argument, low.
length
series int
How many bars.

ta.macd ​

pine
ta.macd(source, fastlen, slowlen, siglen) → [series float, series float, series float]

The moving average convergence divergence: [macd, signal, histogram].

macd is the fast exponential average minus the slow one, signal is the exponential average of macd, and histogram is their difference. A na source reads na in all three and moves nothing.

ParameterDefaultDescription
source
series int/float
The values to average.
fastlen
simple int
12AmenoScript onlyBars for the fast average.
slowlen
simple int
26AmenoScript onlyBars for the slow average.
siglen
simple int
9AmenoScript onlyBars for the signal line.
pine
//@version=6
indicator("MACD")
[macdLine, signal, hist] = ta.macd(close, 12, 26, 9)
plot(hist, "Histogram", color.gray, style = plot.style_columns)
plot(macdLine, "MACD", color.blue)
plot(signal, "Signal", color.orange)

ta.max ​

pine
ta.max(source) → series float

The highest value the source has had since the first bar.

A na or an infinity is skipped. It reads na until the first number.

ParameterDescription
source
series int/float
The values to track.

ta.md ​

AmenoScript only
ameno
ta.md(source, length) → series float

ta.dev under a second name, MD for mean deviation. See AmenoScript's built-ins.

It gives what ta.dev gives with the same arguments, and each call keeps its own state like any other. It exists only so a script can use the short name; in Pine, write ta.dev.

ParameterDescription
source
series int/float
The values to measure.
length
series int
How many bars.

ta.median ​

pine
ta.median(source, length) → series int/float

The median of the last length values.

A na leaves the window as it was, so it reads the median of the last length numbers.

ParameterDescription
source
series int/float
The values to measure.
length
series int
How many bars.

ta.mfi ​

pine
ta.mfi(series, length) → series float

The money flow index: the share of the last length bars' money flow that came on rising bars, from 0 to 100.

Each bar's flow is its source times its volume, counted as rising or falling by the change from the bar before. A window with no falling flow reads 100.

ParameterDefaultDescription
series
series int/float
The typical price.
length
series int
14AmenoScript onlyHow many bars.

ta.min ​

pine
ta.min(source) → series float

The lowest value the source has had since the first bar.

A na or an infinity is skipped. It reads na until the first number.

ParameterDescription
source
series int/float
The values to track.

ta.mode ​

pine
ta.mode(source, length) → series int/float

The most frequent of the last length values, the smallest of them on a tie.

A na leaves the window as it was.

ParameterDescription
source
series int/float
The values to count.
length
series int
How many bars.

ta.mom ​

pine
ta.mom(source, length) → series float

The momentum: the source minus its value length bars ago.

The window always holds the last length + 1 bars, so a na at either end reads na. In a branch, a skipped bar counts as the value the call last read.

ParameterDefaultDescription
source
series int/float
The values to compare.
length
series int
10AmenoScript onlyHow many bars back.

ta.nvi ​

pine
series float ta.nvi

The negative volume index: from 1, it moves by the close's percentage change on each bar whose volume fell.

ta.obv ​

pine
series float ta.obv

The on-balance volume: the running sum of volume, added on an up close and taken away on a down close.

It reads na on the first bar.

ta.percentile_linear_interpolation ​

pine
ta.percentile_linear_interpolation(source, length, percentage) → series float

The value below which percentage percent of the last length values fall, interpolating between the two nearest.

The window keeps na values, and a na sorts above every number, so a na in the window can be the answer near the top.

ParameterDescription
source
series int/float
The values to rank.
length
series int
How many bars.
percentage
simple int/float
The percentile, from 0 to 100.

ta.percentile_nearest_rank ​

pine
ta.percentile_nearest_rank(source, length, percentage) → series float

The value at percentage percent of the last length values, sorted, by the nearest-rank method.

It always returns one of the window's values. The window keeps na values sorted above every number, as in ta.percentile_linear_interpolation.

ParameterDescription
source
series int/float
The values to rank.
length
series int
How many bars.
percentage
simple int/float
The percentile, from 0 to 100.

ta.percentrank ​

pine
ta.percentrank(source, length) → series float

The percentage of the previous length values that are at or below the current one.

A na in the window counts as not at or below, and a na source reads 0. In a branch, a skipped bar counts as the value the call last read.

ParameterDescription
source
series int/float
The values to rank.
length
series int
How many earlier bars to compare with.

ta.pivot_point_levels ​

pine
ta.pivot_point_levels(type, anchor, developing) → array<float>

The classic pivot levels of the current bar, as an array of seven: [pivot, s1, r1, s2, r2, s3, r3].

This engine's levels differ from TradingView's

This engine reads type, anchor and developing but uses none of them: every call returns the classic levels from the current bar's high, low and close. TradingView returns eleven levels of the chosen type, from the last anchor period. Compute the levels you need from request.security until this changes.

ParameterDescription
type
series string
The kind of pivots TradingView would compute, such as "Traditional". Ignored here.
anchor
series bool
When TradingView would start a new period. Ignored here.
developing
series bool
Whether TradingView would update the levels as the period forms. Ignored here.

ta.pivothigh ​

pine
ta.pivothigh(source, leftbars, rightbars) → series float
ta.pivothigh(leftbars, rightbars) → series float

The value of a pivot high, returned rightbars bars after the pivot bar, and na on every other bar.

A pivot high is higher than each of the rightbars bars after it and no lower than each of the leftbars bars before it, so an earlier bar can tie it and a later one can't. With two arguments it reads high. The value arrives late by design: on the bar it returns, the pivot is rightbars bars back. It counts those bars by bar index, so in a branch the bars the call skipped count too.

ParameterDescription
source
series int/float
The values to search. With two arguments, high.
leftbars
series int/float
How many bars before the pivot it is compared with.
rightbars
series int/float
How many bars after the pivot it must beat, and so how late the value comes.
pine
//@version=6
indicator("Pivot highs", overlay = true)
ph = ta.pivothigh(high, 3, 3)
// the pivot was 3 bars ago, so draw it there; live, the mark appears 3 bars after its bar
plotshape(not na(ph), "Pivot", shape.triangledown, location.abovebar, color.red, offset = -3)

ta.pivotlow ​

pine
ta.pivotlow(source, leftbars, rightbars) → series float
ta.pivotlow(leftbars, rightbars) → series float

The value of a pivot low, returned rightbars bars after the pivot bar, and na on every other bar.

A pivot low is lower than each of the rightbars bars after it and no higher than each of the leftbars bars before it, so an earlier bar can tie it and a later one can't. With two arguments it reads low. It counts rightbars by bar index, so in a branch the bars the call skipped count too.

ParameterDescription
source
series int/float
The values to search. With two arguments, low.
leftbars
series int/float
How many bars before the pivot it is compared with.
rightbars
series int/float
How many bars after the pivot it must beat, and so how late the value comes.

ta.pvi ​

pine
series float ta.pvi

The positive volume index: from 1, it moves by the close's percentage change on each bar whose volume rose.

ta.pvt ​

pine
series float ta.pvt

The price-volume trend: the running sum of each bar's percentage change in close times its volume.

It reads na on the first bar.

ta.range ​

pine
ta.range(source, length) → series float

The highest minus the lowest of the last length values.

A na leaves the window as it was, and it reads na until the window holds length numbers.

ParameterDescription
source
series int/float
The values to measure.
length
series int
How many bars.

ta.rci ​

pine
ta.rci(source, length) → series float

The rank correlation index: 100 times the correlation between the bars' order in time and the order of their values, from -100 to 100.

A steady rise reads about 100. Equal values share their average rank. A na bar repeats the last answer. In a branch, the call reads a ring of length + 1 slots by bar index, where a slot no call wrote reads 0.

ParameterDefaultDescription
source
series int/float
The values to rank.
length
simple int
9AmenoScript onlyHow many bars. It must be fixed for the run.

ta.rising ​

pine
ta.rising(source, length) → series bool

Whether the source rose from each bar to the next over the last length bars.

A step with a na on either side leaves the count as it was.

ParameterDescription
source
series int/float
The values to test.
length
series int
How many rises in a row it takes.

ta.rma ​

pine
ta.rma(source, length) → series float

Wilder's moving average, which weights each bar 1 / length against the average before it.

It starts from the simple average of the first length values. A na bar reads na and leaves the average as it was.

ParameterDescription
source
series int/float
The values to average.
length
simple int
How many bars. It must be fixed for the run.

ta.roc ​

pine
ta.roc(source, length) → series float

The rate of change: the percentage change of the source from length bars ago.

It reads na where the value length bars ago is 0. The window always holds the last length + 1 bars, so a na at either end reads na. In a branch, a skipped bar counts as the value the call last read.

ParameterDefaultDescription
source
series int/float
The values to compare.
length
series int
1AmenoScript onlyHow many bars back.

ta.rsi ​

pine
ta.rsi(source, length) → series float

The relative strength index, from 0 to 100: Wilder's average of the gains over that of the losses.

It reads 100 where the losses' average is 0, a flat window included, and 0 where only the gains' average is. Each gain or loss is the change from one bar to the next, so a na takes the changes on both sides of it out of the averages.

ParameterDescription
source
series int/float
The values to measure.
length
simple int
How many bars. It must be fixed for the run.

ta.sar ​

pine
ta.sar(start, increment, maximum) → series float

The parabolic stop and reverse: a trailing level that speeds up as the trend runs and flips side when price crosses it.

It starts on the run's second bar, so a call inside a branch that misses that bar reads na for good.

TradingView's keyword names don't reach it

This engine names the last two parameters increment and maximum. TradingView names them inc and max, and a call written ta.sar(0.02, inc = 0.1, max = 0.5) runs here on the defaults. Pass them by position.

ParameterDefaultDescription
start
simple int/float
0.02AmenoScript onlyThe step the speed starts from on each new trend.
increment
simple int/float
0.02AmenoScript onlyHow much the speed grows with each new extreme.
maximum
simple int/float
0.2AmenoScript onlyThe highest the speed can go.

ta.sma ​

pine
ta.sma(source, length) → series float

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

A na leaves the window as it was, so the mean is of the last length numbers. A length that changes from bar to bar reads the window of the new length.

ParameterDescription
source
series int/float
The values to average.
length
series int
How many bars.

ta.stdev ​

pine
ta.stdev(source, length, biased) → series float

The standard deviation of the last length values.

A na leaves the window as it was. Rounding can't take it below 0.

ParameterDefaultDescription
source
series int/float
The values to measure.
length
series int
How many bars.
biased
series bool
truetrue divides by length, the population figure. false divides by length - 1, the sample figure.

ta.stoch ​

pine
ta.stoch(source, high, low, length) → series float

The stochastic: where the source sits between the lowest low and the highest high of the last length bars, from 0 to 100.

A flat window or a na source repeats the last value.

ParameterDescription
source
series int/float
The values to place, usually close.
high
series int/float
The highs to search.
low
series int/float
The lows to search.
length
series int
How many bars.
pine
//@version=6
indicator("Stochastic")
k = ta.sma(ta.stoch(close, high, low, 14), 3)
d = ta.sma(k, 3)
plot(k, "%K", color.blue)
plot(d, "%D", color.orange)

ta.supertrend ​

pine
ta.supertrend(factor, atrPeriod) → [series float, series float]

The supertrend: [supertrend, direction], a trailing band under price in an uptrend and over it in a downtrend.

direction is -1 in an uptrend and 1 in a downtrend. The band is hl2 plus or minus factor times the average true range, and it only moves in the trend's favour until price closes through it. After bars the call skipped, the true range still reads the close of the bar just before.

ParameterDescription
factor
series int/float
How many average true ranges the band sits from hl2.
atrPeriod
simple int
How many bars the average true range covers.
pine
//@version=6
indicator("Supertrend", overlay = true)
[st, dir] = ta.supertrend(3, 10)
plot(dir < 0 ? st : na, "Up", color.green, style = plot.style_linebr) // -1 is an uptrend
plot(dir > 0 ? st : na, "Down", color.red, style = plot.style_linebr)

ta.swma ​

pine
ta.swma(source) → series float

The symmetrically weighted moving average over 4 bars, weights 1, 2, 2, 1.

The window always holds the last 4 bars, so a na in it reads na. In a branch, a skipped bar counts as the value the call last read.

ParameterDescription
source
series int/float
The values to average.

ta.tr ​

pine
series float ta.tr
ta.tr(handle_na) → series float

The true range: the greatest of the bar's high minus low and the distances from the close before to the high and to the low.

On the first bar there is no close before, so it reads na, or the high minus the low with handle_na = true. Read bare as ta.tr, it is ta.tr(false). After bars the call skipped, it reads the close of the bar just before.

ParameterDescription
handle_na
simple bool
true reads the high minus the low where there is no close before, and false reads na there.

ta.ts_rank ​

AmenoScript only
ameno
ta.ts_rank(source, from, to) → series float

How the current value ranks against the values from to to bars ago: the number it is above minus the number it isn't. See the cross-section.

Values within 1e-10 of each other count as equal, as Pine's comparisons read them, and a na in the window is skipped. A window with nothing in it reads na.

ParameterDescription
source
series int/float
The values to rank.
from
series int
The nearest bar back to compare with.
to
series int
The furthest bar back to compare with.
ameno
indicator("Rank against the last 20 bars")
plot(ta.ts_rank(close, 1, 20)) // AmenoScript only: from -20 to 20

ta.tsi ​

pine
ta.tsi(source, short_length, long_length) → series float

The true strength index: the double-smoothed change of the source over the double-smoothed size of that change, from -1 to 1.

It gives the ratio itself, not a percentage. Each change is from one bar to the next.

ParameterDefaultDescription
source
series int/float
The values to measure.
short_length
simple int
13AmenoScript onlyBars for the second smoothing.
long_length
simple int
25AmenoScript onlyBars for the first smoothing.

ta.valuewhen ​

pine
ta.valuewhen(condition, source, occurrence) → series bool/color/float/int

The value source had on the occurrence-th most recent bar where condition was true, counting from 0.

occurrence = 0 is the latest such bar, which can be the current one. It reads na until the condition has been true occurrence + 1 times.

ParameterDefaultDescription
condition
series bool
The test that marks a bar.
source
series bool/color/int/float
The value to read on the marked bars.
occurrence
simple int
0AmenoScript onlyWhich marked bar, 0 for the latest. It must be fixed for the run.
pine
//@version=6
indicator("Close at the last two crosses", overlay = true)
cross = ta.crossover(close, ta.sma(close, 20))
plot(ta.valuewhen(cross, close, 0), "Last cross", color.blue)
plot(ta.valuewhen(cross, close, 1), "Cross before it", color.gray) // one cross further back

ta.variance ​

pine
ta.variance(source, length, biased) → series float

The variance of the last length values.

A na leaves the window as it was. Rounding can't take it below 0.

ParameterDefaultDescription
source
series int/float
The values to measure.
length
series int
How many bars.
biased
series bool
truetrue divides by length, the population figure. false divides by length - 1, the sample figure.

ta.vwap ​

pine
series float ta.vwap
ta.vwap(source) → series float
ta.vwap(source, anchor) → series float
ta.vwap(source, anchor, stdev_mult) → [series float, series float, series float]

The volume-weighted average price since the last anchor.

With no anchor, it starts again at the first bar of each UTC day. With stdev_mult it returns [vwap, upper, lower], the bands sitting that many volume-weighted standard deviations away. Read bare as ta.vwap, it is the daily average of hlc3.

The default anchor is the UTC day

TradingView restarts the average at each new trading day. For a symbol whose session crosses midnight UTC, such as a future that opens in the evening, the two differ. For the trading day, pass anchor = ta.change(time_tradingday) != 0.

ParameterDescription
source
series int/float
The price to average.
anchor
series bool
True on a bar where the average starts again.
stdev_mult
series int/float
How many standard deviations each band sits away. Passing it, even as na, returns the three-value tuple.
pine
//@version=6
indicator("Weekly VWAP with bands", overlay = true)
[vwap, upper, lower] = ta.vwap(hlc3, timeframe.change("1W"), 1) // restarts each week
plot(vwap, "VWAP", color.orange)
plot(upper, "Upper", color.gray)
plot(lower, "Lower", color.gray)

ta.vwma ​

pine
ta.vwma(source, length) → series float

The volume-weighted moving average: the average of source times volume over the average of volume, over length bars.

Each average skips its own na, so the two windows part where only the source has a hole. It reads na where the volume's average is 0.

ParameterDescription
source
series int/float
The values to average.
length
series int
How many bars.

ta.wad ​

pine
series float ta.wad

The Williams accumulation/distribution: the running sum of each bar's close against the true range's far end.

ta.wma ​

pine
ta.wma(source, length) → series float

The weighted moving average over length bars, weighting the newest bar length and the oldest 1.

A na bar reads na and holds the last number in its slot, and the average waits for length numbers. In a branch, a skipped bar counts as the value the call last read.

ParameterDescription
source
series int/float
The values to average.
length
series int
How many bars.

ta.wpr ​

pine
ta.wpr(length) → series float

Williams %R: where the close sits between the highest high and lowest low of the last length bars, from -100 to 0.

A flat window reads na.

ParameterDefaultDescription
length
series int
14AmenoScript onlyHow many bars.

ta.wvad ​

pine
series float ta.wvad

The Williams variable accumulation/distribution of one bar: (close - open) / (high - low) * volume.

A bar with no range reads na.

ta.zigzag ​

AmenoScript only
ameno
ta.zigzag(deviation, depth) → [series float, series float, series bool]

A zigzag of price swings: [pivot, direction, isHigh] on the bar a swing of at least deviation percent completes. See AmenoScript's built-ins.

pivot is the swing's extreme and reads na on other bars. direction is 1 after a swing up, -1 after a swing down, and na before the first. isHigh is true when the new pivot is a high. A new pivot waits at least depth bars after the last.

ParameterDefaultDescription
deviation
series int/float
5The smallest swing that counts, in percent.
depth
series int
10The fewest bars between two pivots.
ameno
indicator("Zigzag pivots", overlay = true)
[pivot, dir, isHigh] = ta.zigzag(5, 10) // AmenoScript only
plotshape(not na(pivot) and isHigh, "High", shape.circle, location.abovebar, color.red)
plotshape(not na(pivot) and not isHigh, "Low", shape.circle, location.belowbar, color.green)
plot(dir, "Direction", display = display.data_window)

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.