Ta

ta.alma

Definition: Arnaud Legoux Moving Average. It uses Gaussian distribution as weights for moving average.

Syntax:

ta.alma(series, length, offset, sigma) β†’ series float
ta.alma(series, length, offset, sigma, floor) β†’ series float

Returns: Arnaud Legoux Moving Average.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

series int

Number of bars (length).

offset

simple int/float

Controls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0).

sigma

simple int/float

Changes the smoothness of ALMA. The larger sigma, the smoother ALMA.

floor

simple bool (optional)

An optional parameter. Specifies whether the offset calculation is floored before ALMA is calculated. Default value is false.


ta.atr

Definition: Function atr (average true range) returns the RMA of true range. True range is max(high - low, abs(high - close[1]), abs(low - close[1])).

Syntax:

ta.atr(length) β†’ series float

Returns: Average true range.

Arguments:

Name
Type
Description

length

simple int

Length (number of bars back).

Example (Pine Script):


ta.barssince

Definition: Counts the number of bars since the last time the condition was true.

Syntax:

Returns: Number of bars since condition was true.

Arguments:

Name
Type
Description

condition

condition

The condition to check.

Example (Pine Script):


ta.bb

Definition: Bollinger Bands. A Bollinger Band is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of the security's price, but can be adjusted to user preferences.

Syntax:

Returns: Bollinger Bands.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

series int

Number of bars (length).

mult

simple int/float

Standard deviation factor.

Example (Pine Script):


ta.bbw

Definition: Bollinger Bands Width. The Bollinger Band Width is the difference between the upper and the lower Bollinger Bands divided by the middle band.

Syntax:

Returns: Bollinger Bands Width.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

series int

Number of bars (length).

mult

simple int/float

Standard deviation factor.

Example (Pine Script):


ta.cci

Definition: The CCI (commodity channel index) is calculated as the difference between the typical price of a commodity and its simple moving average, divided by the mean absolute deviation of the typical price. The index is scaled by an inverse factor of 0.015 to provide more readable numbers.

Syntax:

Returns: Commodity channel index of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.change

Definition: Compares the current source value to its value length bars ago and returns the difference.

Syntax:

Returns: The difference between the values when they are numerical. When a 'bool' source is used, returns true when the current source is different from the previous source.

Arguments:

Name
Type
Description

source

series int/float/bool

Source series.

length

series int (optional)

How far the past source value is offset from the current one, in bars. Optional. The default is 1.

Example (Pine Script):


ta.cmo

Definition: Chande Momentum Oscillator. Calculates the difference between the sum of recent gains and the sum of recent losses and then divides the result by the sum of all price movement over the same period.

Syntax:

Returns: Chande Momentum Oscillator.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

series int

Number of bars (length).

Example (Pine Script):


ta.cog

Definition: The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.

Syntax:

Returns: Center of Gravity.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

Example (Pine Script):


ta.correlation

Definition: Correlation coefficient. Describes the degree to which two series tend to deviate from their ta.sma values.

Syntax:

Returns: Correlation coefficient.

Arguments:

Name
Type
Description

source1

series int/float

Source series.

source2

series int/float

Target series.

length

series int

Length (number of bars back).


ta.cross

Definition: Checks if two series have crossed each other.

Syntax:

Returns: True if two series have crossed each other, otherwise false.

Arguments:

Name
Type
Description

source1

series int/float

First data series.

source2

series int/float

Second data series.


ta.crossover

Definition: Checks if the source1 series has crossed over the source2 series.

Syntax:

Returns: True if source1 crossed over source2, otherwise false.

Arguments:

Name
Type
Description

source1

series int/float

First data series.

source2

series int/float

Second data series.


ta.crossunder

Definition: Checks if the source1 series has crossed under the source2 series.

Syntax:

Returns: True if source1 crossed under source2, otherwise false.

Arguments:

Name
Type
Description

source1

series int/float

First data series.

source2

series int/float

Second data series.


ta.cum

Definition: Cumulative (total) sum of source. In other words, it's the sum of all elements of source.

Syntax:

Returns: Total sum series.

Arguments:

Name
Type
Description

source

series int/float

Source used for the calculation.


ta.dev

Definition: Measure of difference between the series and its ta.sma.

Syntax:

Returns: Deviation of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

Example (Pine Script):


ta.dmi

Definition: The dmi function returns the directional movement index.

Syntax:

Returns: Tuple of three DMI series: Positive Directional Movement (+DI), Negative Directional Movement (-DI), and Average Directional Movement Index (ADX).

Arguments:

Name
Type
Description

diLength

simple int

DI Period.

adxSmoothing

simple int

ADX Smoothing Period.

Example (Pine Script):


ta.ema

Definition: The ema function returns the exponentially weighted moving average. In ema weighting factors decrease exponentially. It calculates by using a formula: EMA = alpha * source + (1 - alpha) * EMA[1], where alpha = 2 / (length + 1).

Syntax:

Returns: Exponential moving average of source with alpha = 2 / (length + 1).

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

simple int

Number of bars (length).

Example (Pine Script):

ta.falling

Definition: Test if the source series is now falling for length bars long.

Syntax:

Returns: True if the current source value is less than any previous source value for length bars back, false otherwise.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.highest

Definition: Highest value for a given number of bars back.

Syntax:

Returns: Highest value in the series.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

Remarks:

  • Two args version: source is a series and length is the number of bars back.

  • One arg version: length is the number of bars back. Algorithm uses high as a source series.


ta.highestbars

Definition: Highest value offset for a given number of bars back.

Syntax:

Returns: Offset to the highest bar.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.hma

Definition: The hma function returns the Hull Moving Average.

Syntax:

Returns: Hull moving average of 'source' for 'length' bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

simple int

Number of bars.


ta.kc

Definition: Keltner Channels. Keltner channel is a technical analysis indicator showing a central moving average line plus channel lines at a distance above and below.

Syntax:

Returns: Keltner Channels.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

series int

Number of bars (length).

mult

series int/float

Standard deviation factor.

useTrueRange

series bool

An optional parameter. Specifies if True Range is used; default is true. If the value is false, the range will be calculated with the expression (high - low).


ta.kcw

Definition: Keltner Channels Width. The Keltner Channels Width is the difference between the upper and the lower Keltner Channels divided by the middle channel.

Syntax:

Returns: Keltner Channels Width.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

simple int

Number of bars (length).

mult

simple int/float

Standard deviation factor.

useTrueRange

simple bool

An optional parameter. Specifies if True Range is used; default is true. If the value is false, the range will be calculated with the expression (high - low).


ta.linreg

Definition: Linear regression curve. A line that best fits the prices specified over a user-defined time period. It is calculated using the least squares method.

Syntax:

Returns: Linear regression curve.

Arguments:

Name
Type
Description

source

series int/float

Source series.

length

series int

Number of bars (length).

offset

simple int

Offset.


ta.lowest

Definition: Lowest value for a given number of bars back.

Syntax:

Returns: Lowest value in the series.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

Remarks:

  • Two args version: source is a series and length is the number of bars back.

  • One arg version: length is the number of bars back. Algorithm uses low as a source series.


ta.lowestbars

Definition: Lowest value offset for a given number of bars back.

Syntax:

Returns: Offset to the lowest bar.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.macd

Definition: Moving average convergence/divergence. It is supposed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock's price.

Syntax:

Returns: Tuple of three MACD series: MACD line, signal line, and histogram line.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

fastlen

simple int

Fast Length parameter.

slowlen

simple int

Slow Length parameter.

siglen

simple int

Signal Length parameter.


ta.max

Definition: Returns the all-time high value of source from the beginning of the chart up to the current bar.

Syntax:

Returns: The all-time high value in the series.

Arguments:

Name
Type
Description

source

series int/float

Source used for the calculation.


ta.median

Definition: Returns the median of the series.

Syntax:

Returns: The median of the series.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.mfi

Definition: Money Flow Index. The Money Flow Index (MFI) is a technical oscillator that uses price and volume for identifying overbought or oversold conditions in an asset.

Syntax:

Returns: Money Flow Index.

Arguments:

Name
Type
Description

series

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.min

Definition: Returns the all-time low value of source from the beginning of the chart up to the current bar.

Syntax:

Returns: The all-time low value in the series.

Arguments:

Name
Type
Description

source

series int/float

Source used for the calculation.


ta.mode

Definition: Returns the mode of the series. If there are several values with the same frequency, it returns the smallest value.

Syntax:

Returns: The most frequently occurring value from the source. If none exists, returns the smallest value instead.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.mom

Definition: Momentum of source price and source price length bars ago. This is simply a difference: source - source[length].

Syntax:

Returns: Momentum of source price and source price length bars ago.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Offset from the current bar to the previous bar.


ta.percentile_linear_interpolation

Definition: Calculates percentile using the method of linear interpolation between the two nearest ranks.

Syntax:

Returns: P-th percentile of source series for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process (source).

length

series int

Number of bars back (length).

percentage

simple int/float

Percentage, a number from the range 0..100.


ta.percentile_nearest_rank

Definition: Calculates percentile using the method of Nearest Rank.

Syntax:

Returns: P-th percentile of source series for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process (source).

length

series int

Number of bars back (length).

percentage

simple int/float

Percentage, a number from the range 0..100.


ta.percentrank

Definition: Percent rank is the percents of how many previous values were less than or equal to the current value of the given series.

Syntax:

Returns: Percent rank of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars back (length).


ta.psar

Definition: Parabolic SAR (parabolic stop and reverse) is a method devised by J. Welles Wilder, Jr., to find potential reversals in the market price direction of traded goods.

Syntax:

Returns: Parabolic SAR.

Arguments:

Name
Type
Description

start

simple int/float

Start.

inc

simple int/float

Increment.

max

simple int/float

Maximum.


ta.pvt

Definition: Price-volume trend indicator (PVT) shows the relationship between price and volume and is designed to confirm price trends.

Syntax:

Returns: Price-volume trend indicator.

Arguments:

Name
Type
Description

close

series int/float

Close price series.

volume

series int/float

Volume series.


ta.rma

Definition: Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.

Syntax:

Returns: Exponential moving average of source with alpha = 1 / length.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

simple int

Number of bars (length).


ta.roc

Definition: Calculates the percentage of change (rate of change) between the current value of source and its value length bars ago.

Syntax:

Returns: The rate of change of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.rsi

Definition: Relative strength index. It is calculated using the ta.rma() of upward and downward changes of source over the last length bars.

Syntax:

Returns: Relative strength index.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

simple int

Number of bars (length).


ta.sar

Definition: Parabolic SAR (parabolic stop and reverse) is a method devised by J. Welles Wilder, Jr., to find potential reversals in the market price direction of traded goods.

Syntax:

Returns: Parabolic SAR.

Arguments:

Name
Type
Description

start

simple int/float

Start.

inc

simple int/float

Increment.

max

simple int/float

Maximum.


ta.sma

Definition: The sma function returns the moving average, that is the sum of the last length values of source, divided by length.

Syntax:

Returns: Simple moving average of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.stdev

Definition: Standard deviation.

Syntax:

Returns: Standard deviation.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

biased

series bool

Determines which estimate should be used. Optional. The default is true.

ta.stoch

Definition: Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length)).

Syntax:

Returns: Stochastic.

Arguments:

Name
Type
Description

source

series int/float

Source series.

high

series int/float

Series of high.

low

series int/float

Series of low.

length

series int

Length (number of bars back).


ta.supertrend

Definition: The Supertrend Indicator. The Supertrend is a trend following indicator.

Syntax:

Returns: Tuple of two supertrend series: supertrend line and direction of trend. Possible values are 1 (down direction) and -1 (up direction).

Arguments:

Name
Type
Description

factor

series int/float

The multiplier by which the ATR will get multiplied.

atrPeriod

simple int

Length of ATR.


ta.swma

Definition: Symmetrically weighted moving average with fixed length: 4. Weights: [1/6, 2/6, 2/6, 1/6].

Syntax:

Returns: Symmetrically weighted moving average.

Arguments:

Name
Type
Description

source

series int/float

Source series.


ta.tr

Definition: True range. It is math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]).

Syntax:

Returns: True range.

Arguments:

Name
Type
Description

handle_na

simple bool

How NaN values are handled. If true, and the previous day's close is NaN, then tr would be calculated as the current day's high - low. Otherwise (if false), tr would return NaN in such cases. Also note that ta.atr uses ta.tr(true).


ta.tsi

Definition: True strength index. It uses moving averages of the underlying momentum of a financial instrument.

Syntax:

Returns: True strength index. A value in the range [-1, 1].

Arguments:

Name
Type
Description

source

series int/float

Source series.

short_length

simple int

Short length.

long_length

simple int

Long length.


ta.valuewhen

Definition: Returns the value of the source series on the bar where the condition was true on the nth most recent occurrence.

Syntax:

Returns: The value of the source series on the bar where the condition was true on the nth most recent occurrence.

Arguments:

Name
Type
Description

condition

series bool

The condition to search for.

source

series int/float/bool/color

The value to be returned from the bar where the condition is met.

occurrence

simple int

The occurrence of the condition. The numbering starts from 0 and goes back in time, so '0' is the most recent occurrence of condition, '1' is the second most recent, and so forth. Must be an integer >= 0.


ta.variance

Definition: Variance is the expectation of the squared deviation of a series from its mean (ta.sma), and it informally measures how far a set of numbers are spread out from their mean.

Syntax:

Returns: Variance of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).

biased

series bool

Determines which estimate should be used. Optional. The default is true.


ta.vwap

Definition: Volume weighted average price.

Syntax:

Returns: A VWAP series or a tuple [vwap, upper_band, lower_band] if stdev_mult is specified.

Arguments:

Name
Type
Description

source

series int/float

Source used for the VWAP calculation.

anchor

series bool

The condition that triggers the reset of VWAP calculations. When true, calculations reset; when false, calculations proceed using the values accumulated since the previous reset. Optional. The default is equivalent to passing timeframe.change with '1D' as its argument.

stdev_mult

series int/float

If specified, the function will calculate the standard deviation bands based on the main VWAP series and return a [vwap, upper_band, lower_band] tuple. The upper_band/lower_band values are calculated using the VWAP to which the standard deviation multiplied by this argument is added/subtracted. Optional. The default is na, in which case the function returns a single value, not a tuple.


ta.vwma

Definition: The vwma function returns volume-weighted moving average of source for length bars back. It is the same as: sma(source * volume, length) / sma(volume, length).

Syntax:

Returns: Volume-weighted moving average of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.wma

Definition: The wma function returns weighted moving average of source for length bars back. In wma, weighting factors decrease in arithmetical progression.

Syntax:

Returns: Weighted moving average of source for length bars back.

Arguments:

Name
Type
Description

source

series int/float

Series of values to process.

length

series int

Number of bars (length).


ta.wpr

Definition: Williams %R. The oscillator shows the current closing price in relation to the high and low of the past 'length' bars.

Syntax:

Returns: Williams %R.

Arguments:

Name
Type
Description

length

series int

Number of bars.

Last updated