Skip to main content
Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: ta · Entries: 65

ta (library)

Definition ta is an alias for talib. The same functions are available under either namespace and may be used interchangeably. Sixty-two named indicator and series functions: moving averages, oscillators, channels, ranges, pivots, window statistics and the volume indices. Some take a source and a length; several — the volume indices, the true-range and channel functions among them — take no source and read the chart’s own bars instead. Example

ta.alma (function)

Definition An Arnaud Legoux moving average of source over length bars. Two further arguments, offset and sigma, shape the weighting. Both accept an int or a float. Syntax
Parameters Returns series float Example

ta.atr (function)

Definition Average true range over length bars. Read it as a measure of how far the market has been travelling, not as a price level. There is no source argument. The reading is built from the chart’s own bars. Syntax
Parameters Returns series float Example

ta.barssince (function)

Definition Counts the bars that have gone by since condition was last true. condition may be a bool, an int or a float expression; a number counts as true when it is not zero. The result is -1, not na, when the condition has not been true on any bar so far or is na. Syntax
Parameters Returns series int Example

ta.bb (function)

Definition Bollinger bands for source over length bars, with mult setting how far the outer bands sit from the middle one. mult is a float series, so whole numbers and values such as 2.5 are both valid. Syntax
Parameters Returns [series float, series float, series float] Example

ta.bbw (function)

Definition Bollinger band width: the same calculation as talib.bb, delivered as one number instead of three bands. Its arguments match talib.bb exactly, including mult as a float series. Syntax
Parameters Returns series float Notes
  • A length above 500 bars passes the editor’s check but is refused when the script is added to the chart, with “The script is trying to access historical data outside allowed range (501). The allowed range is 0 to 500.” (for 501). Other ta functions accept such a length when compiled and stop when the script runs.
Example

ta.cci (function)

Definition Commodity Channel Index for source over length bars. The source is an argument rather than a fixed price, so the index can be run on anything a script computes. Syntax
Parameters Returns series float Example

ta.change (function, overload 1)

Definition The difference between the current value of source and its value length bars back. Three overloads exist, one each for an int, a float and a bool source, and the returned type follows the source you pass. length is optional in all three. Syntax
Parameters Returns series int Example

ta.change (function, overload 2)

Definition The difference between the current value of source and its value length bars back. Three overloads exist, one each for an int, a float and a bool source, and the returned type follows the source you pass. length is optional in all three. Syntax
Parameters Returns series float Example

ta.change (function, overload 3)

Definition The difference between the current value of source and its value length bars back. Three overloads exist, one each for an int, a float and a bool source, and the returned type follows the source you pass. length is optional in all three. Syntax
Parameters Returns series bool Example

ta.cmo (function)

Definition Chande Momentum Oscillator for source over length bars. Two arguments in, one series float out — the same call shape as talib.rsi. Syntax
Parameters Returns series float Example

ta.cog (function)

Definition Centre of gravity of source across a window of length bars. Syntax
Parameters Returns series float Example

ta.correlation (function)

Definition Correlation between two series, source1 and source2, measured over length bars. Both series are ordinary arguments, so you can correlate anything a script can compute — not only prices. Syntax
Parameters Returns series float Example

ta.cross (function)

Definition True on a bar where source1 and source2 cross, in either direction. When the direction of the cross matters, reach for talib.crossover or talib.crossunder instead. Syntax
Parameters Returns series bool Example

ta.crossover (function)

Definition Flags the bar on which source1 crosses above source2. Crosses the other way are ignored. Syntax
Parameters Returns series bool Example

ta.crossunder (function)

Definition The mirror of talib.crossover: true on the bar where source1 crosses below source2. Syntax
Parameters Returns series bool Example

ta.cum (function)

Definition Accumulates source as the script advances through the chart. There is no length argument: this is a running total rather than a moving window. For a window, use talib.sum. Syntax
Parameters Returns series float Example

ta.dc (function)

Definition Donchian channel over length bars. length is the only argument. The channel is taken from the chart’s own bars rather than from a series you supply. Syntax
Parameters Returns [series float, series float, series float] Notes
  • The values come in the order middle, upper, lower, as with talib.bb. Bind them in that order: the compiler cannot tell a wrong order, so a script that swaps them compiles and plots the wrong band.
Example

ta.dcw (function)

Definition Donchian channel width over length bars, as a single figure. Where talib.dc gives you the channel, this gives you how wide it is. Syntax
Parameters Returns series float Example

ta.dev (function)

Definition A deviation measure for source over length bars. It is not the same function as ta.stdev. Syntax
Parameters Returns series float Example

ta.dmi (function)

Definition The directional movement family in one call, calculated from the chart’s own bars. It takes two lengths rather than one: diLength for the directional readings and adxSmoothing for the strength reading built on them. Syntax
Parameters Returns [series float, series float, series float] Example

ta.ema (function)

Definition Exponential moving average of source over length bars, weighted so that recent bars count for more than older ones. It takes the same two arguments as talib.sma, so swapping one for the other is a one-word change. Syntax
Parameters Returns series float Notes
  • A length above 500 bars passes the editor’s check but is refused when the script is added to the chart, with “The script is trying to access historical data outside allowed range (501). The allowed range is 0 to 500.” (for 501). Other ta functions accept such a length when compiled and stop when the script runs.
Example

ta.falling (function)

Definition Asks the same question as talib.rising in the other direction: has source been falling across length bars? The answer is a bool, not a number. Syntax
Parameters Returns series bool Example

ta.highest (function)

Definition The highest value source reached in the last length bars. Any series can be passed, so this is not limited to the bar’s high. Syntax
Parameters Returns series float Example

ta.highestbars (function)

Definition Locates the highest value of source within the last length bars and returns its position rather than its value. It returns a series int, which makes it the companion to talib.highest. Syntax
Parameters Returns series int Example

ta.hma (function)

Definition Hull moving average of source over length bars. Syntax
Parameters Returns series float Example

ta.kc (function)

Definition Keltner channels for source over length bars, with mult setting the distance to the outer bands. An optional useTrueRange flag selects true range for the width calculation. mult is a float series, like talib.bb and talib.supertrend’s multiplier. Syntax
Parameters Returns [series float, series float, series float] Notes
  • The values come in the order middle, upper, lower, as with talib.bb. Bind them in that order: the compiler cannot tell a wrong order, so a script that swaps them compiles and plots the wrong band.
  • A length above 500 bars passes the editor’s check but is refused when the script is added to the chart, with “The script is trying to access historical data outside allowed range (501). The allowed range is 0 to 500.” (for 501), because the middle line is an ema. (2.7: FACTS F-218; probes MF-645-C to MF-648-C; source ema.go:52-55.)
Example

ta.kcw (function)

Definition Keltner channel width for source over length bars: one figure in place of the three the channel call returns. The argument list matches talib.kc, useTrueRange included. The width is the distance between the upper and the lower band divided by the middle line. Syntax
Parameters Returns series float Notes
  • A length above 500 bars passes the editor’s check but is refused when the script is added to the chart, with “The script is trying to access historical data outside allowed range (501). The allowed range is 0 to 500.” (for 501). Other ta functions accept such a length when compiled and stop when the script runs.
Example

ta.linreg (function)

Definition Fits a linear regression to source across length bars and returns a value from that fit. The offset argument shifts which point of the fit you get back. Syntax
Parameters Returns series float Example

ta.lowest (function)

Definition The lowest value source reached in the last length bars. It is the counterpart of talib.highest and takes the same two arguments. Syntax
Parameters Returns series float Example

ta.lowestbars (function)

Definition Gives the position of the lowest value of source within the last length bars, not the value itself. Use talib.lowest when you want the value. Syntax
Parameters Returns series int Example

ta.macd (function)

Definition Moving average convergence/divergence for source, from three lengths: fastlen, slowlen and siglen. One call covers the whole study, including the signal line that siglen sizes. Syntax
Parameters Returns [series float, series float, series float] Notes
  • A length above 500 bars passes the editor’s check but is refused when the script is added to the chart, with “The script is trying to access historical data outside allowed range (501). The allowed range is 0 to 500.” (for 501). Other ta functions accept such a length when compiled and stop when the script runs.
Example

ta.median (function)

Definition The middle value of the last length values of source. It sits alongside talib.mode and the two percentile functions: all four summarise a window of values rather than average it. Syntax
Parameters Returns series float Example

ta.mfi (function)

Definition Money Flow Index for source over length bars. There is no volume argument in the signature. Syntax
Parameters Returns series float Example

ta.mode (function)

Definition Of the last length values of source, this reports the one that recurs most often. It is a statistical mode over a moving window, and it returns a series float like the other window functions here. Syntax
Parameters Returns series float Example

ta.nvi (function)

Definition Negative volume index for the chart’s bars. It takes no arguments at all. Syntax
Returns series float Example

ta.obv (function)

Definition On-balance volume for the chart’s bars. Like the other volume indices in this namespace, it is called with an empty argument list. Syntax
Returns series float Example

ta.percentile_linear_interpolation (function)

Definition The requested percentile of source over length bars, interpolating between the two values that straddle the rank. Because it interpolates, the result need not be a value that actually occurred in the window. Syntax
Parameters Returns series float Example

ta.percentile_nearest_rank (function)

Definition Takes the requested percentile of source over length bars at the nearest rank, without interpolating. The result is therefore one of the values in the window. Where you would rather have a smoother figure, use the linear-interpolation function. Syntax
Parameters Returns series float Example

ta.percentrank (function)

Definition Ranks where source now stands against the last length bars of itself. It answers the question the other way round from the percentile functions: they take a rank and give a value, this takes the value and gives its rank. Syntax
Parameters Returns series float Example

ta.pivothigh (function)

Definition Looks for a pivot high in source, as this build implements it. On each bar it takes the last leftBars + rightBars - 1 bars of source, the current bar included. When the highest value in that window is leftBars bars back, it returns the current bar’s source; otherwise it returns na. This is not a conventional pivot test. The value returned is the current bar’s, not the pivot bar’s, and with rightBars = 1 the window is too short for the highest value ever to be leftBars bars back, so the result is always na. source is optional; the two bar counts are not. Syntax
Parameters Returns series float Example

ta.pivotlow (function)

Definition Looks for a pivot low in source, as this build implements it. On each bar it takes the last leftBars + rightBars - 1 bars of source, the current bar included. When the lowest value in that window is leftBars bars back, it returns the current bar’s source; otherwise it returns na. This is not a conventional pivot test. The value returned is the current bar’s, not the pivot bar’s, and with rightBars = 1 the window is too short for the lowest value ever to be leftBars bars back, so the result is always na. source is optional; the two bar counts are not. Syntax
Parameters Returns series float Example

ta.psar (function)

Definition Parabolic SAR, controlled by three numbers rather than a bar count: where the calculation starts, how much it moves on each step, and how far it is allowed to go. All three accept an int or a float. Syntax
Parameters Returns series float Example

ta.pvi (function)

Definition Positive volume index for the chart’s bars, the counterpart of talib.nvi. No arguments. Syntax
Returns series float Example

ta.pvt (function)

Definition Price-volume trend for the chart’s bars. It is called with no arguments, and reads a series float back. Syntax
Returns series float Example

ta.range (function)

Definition How much ground source covered over the last length bars, expressed as one figure. Any series is accepted, so the window need not be a price window. Syntax
Parameters Returns series float Example

ta.rising (function)

Definition Tests whether source has been rising across length bars. It returns a bool, so it drops straight into a condition. Syntax
Parameters Returns series bool Example

ta.rma (function)

Definition Rolling moving average of source over length bars. It is a function of its own, alongside ta.sma and ta.ema, and is not a synonym for either. Syntax
Parameters Returns series float Example

ta.roc (function)

Definition Rate of change of source measured across length bars. Where talib.change gives the difference, this gives the rate. Syntax
Parameters Returns series float Example

ta.rsi (function)

Definition Relative Strength Index for source over length bars. Two arguments and one series float back — the same shape as talib.cmo and talib.cci. Syntax
Parameters Returns series float Example

ta.sma (function)

Definition Simple moving average of source over length bars: every bar in the window counts for the same. Reach for this one unless you want a particular weighting, in which case see talib.ema, talib.wma or talib.vwma. Syntax
Parameters Returns series float Example

ta.stdev (function)

Definition Standard deviation of source over length bars. It is the population standard deviation: the squared differences from the mean are divided by length, not by length - 1. Unlike talib.variance, this signature carries no biased flag: there is one form of the calculation and no switch. Syntax
Parameters Returns series float Example

ta.stoch (function)

Definition Stochastic reading that places source inside the span set by high and low over length bars. The high and low series are arguments rather than assumptions, so you can drive the calculation from series of your own. Syntax
Parameters Returns series float Example

ta.sum (function)

Definition Adds up the last length values of source. It is a moving window, which is what separates it from talib.cum. math.sum is equivalent. Syntax
Parameters Returns series float Example

ta.supertrend (function)

Definition Supertrend from a multiplier and an atrLength, calculated on the chart’s own bars. multiplier is a float series, as is mult on talib.bb, talib.bbw, talib.kc, and talib.kcw. Syntax
Parameters Returns [series float, series float] Example

ta.swma (function)

Definition Symmetrically weighted moving average of source over the last four bars, with the weights 1/6, 2/6, 2/6 and 1/6. It is na until four values exist. There is no length argument: the window is fixed by the function, and you choose only what to feed it. Syntax
Parameters Returns series float Example

ta.tr (function)

Definition True range for the bar the script is on, taken from the chart’s own bars. The one argument, handle_na, is optional and selects how a missing value is treated. Syntax
Parameters Returns series float Example

ta.tsi (function)

Definition True Strength Index for source, smoothed by two lengths, r and s. Both are ints, and both are required. Syntax
Parameters Returns series float Example

ta.valuewhen (function)

Definition Reads source from the bar on which condition was true, going back as far as occurrence says. occurrence is a simple int, not a series, so it is fixed for the run of the script and cannot be varied bar by bar. Syntax
Parameters Returns series float Example

ta.variance (function)

Definition Variance of source over length bars. An optional biased flag chooses between the biased and unbiased forms of the calculation. talib.stdev has no such flag. Syntax
Parameters Returns series float Example

ta.vwap (function)

Definition Volume-weighted average price built on source. The signature has one argument. There is no volume argument and no length or anchor argument. Syntax
Parameters Returns series float Example

ta.vwma (function)

Definition Volume-weighted moving average of source over length bars: bars that traded more count for more. Volume is not an argument, so you pass only the series and the window. Syntax
Parameters Returns series float Example

ta.wma (function)

Definition Weighted moving average of source over length bars. For an average weighted by volume, use talib.vwma instead. Syntax
Parameters Returns series float Example

ta.wpr (function)

Definition Williams %R over length bars. In this build it is read from the previous bar’s high, low and close: the value on a bar is the %R as of the bar before it, so it lags the chart by one bar. length is the only argument; the reading comes from the chart’s own bars. Syntax
Parameters Returns series float Example

ta.wvad (function)

Definition Williams variable accumulation/distribution, calculated on the chart’s own bars. In this build length does not set a window and nothing is accumulated: the value on each bar is (close - open) / (high - low) * volume for that bar alone. One argument, and a single series float back. Syntax
Parameters Returns series float Example