**"ta"**

█

**OVERVIEW**

This library holds technical analysis functions calculating values for which no Pine built-in exists.

Look first. Then leap.

█

**FUNCTIONS**

**cagr(entryTime, entryPrice, exitTime, exitPrice)**

It calculates the "Compound Annual Growth Rate" between two points in time. The CAGR is a notional, annualized growth rate that assumes all profits are reinvested. It only takes into account the prices of the two end points — not drawdowns, so it does not calculate risk. It can be used as a yardstick to compare the performance of two instruments. Because it annualizes values, the function requires a minimum of one day between the two end points (annualizing returns over smaller periods of times doesn't produce very meaningful figures).

Parameters:

**entryTime**: The starting timestamp.

**entryPrice**: The starting point's price.

**exitTime**: The ending timestamp.

**exitPrice**: The ending point's price.

Returns: CAGR in % (50 is 50%). Returns `na` if there is not >=1D between `entryTime` and `exitTime`, or until the two time points have not been reached by the script.

█

**v2, Mar. 8, 2022**

Added functions `allTimeHigh()` and `allTimeLow()` to find the highest or lowest value of a source from the first historical bar to the current bar. These functions will not look ahead; they will only return new highs/lows on the bar where they occur.

**allTimeHigh(src)**

Tracks the highest value of `src` from the first historical bar to the current bar.

Parameters:

**src**: (series int/float) Series to track. Optional. The default is `high`.

Returns: (float) The highest value tracked.

**allTimeLow(src)**

Tracks the lowest value of `src` from the first historical bar to the current bar.

Parameters:

**src**: (series int/float) Series to track. Optional. The default is `low`.

Returns: (float) The lowest value tracked.

█

**v3, Sept. 27, 2022**

**ema2(src, length)**

An alternate ema function to the `ta.ema()` built-in, which allows a "series float" length argument.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (series int/float) Number of bars (length).

Returns: (float) The exponentially weighted moving average of the `src`.

**dema(src, length)**

Calculates the value of the Double Exponential Moving Average (Dema).

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The double exponentially weighted moving average of the `src`.

**dema2(src, length)**

An alternate Double Exponential Moving Average (Dema) function to `dema()`, which allows a "series float" length argument.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (series int/float) Number of bars (length).

Returns: (float) The double exponentially weighted moving average of the `src`.

**tema(src, length)**

Calculates the value of the Triple Exponential Moving Average (Tema).

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The triple exponentially weighted moving average of the `src`.

**tema2(src, length)**

An alternate Triple Exponential Moving Average (Tema) function to `tema()`, which allows a "series float" length argument.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (series int/float) Number of bars (length).

Returns: (float) The triple exponentially weighted moving average of the `src`.

**trima(src, length)**

Calculates the value of the Triangular Moving Average (TRIMA).

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The triangular moving average of the `src`.

**trima2(src, length)**

An alternate Triangular Moving Average (TRIMA) function to `trima()`, which allows a "series int" length argument.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (series int) Number of bars (length).

Returns: (float) The triangular moving average of the `src`.

**t3(src, length, alpha)**

Calculates the value of the Tilson Moving Average (T3).

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

**alpha**: (simple float) Volume factor. Affects the responsiveness.

Returns: (float) The tilson moving average of the `src`.

**t3Alt(src, length, alpha)**

An alternate Tilson Moving Average (T3) function to `t3()`, which allows a "series int" length argument.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (series int/float) Number of bars (length).

**alpha**: (simple float) Volume factor. Affects the responsiveness.

Returns: (float) The tilson moving average of the `src`.

**frama(src, length)**

The Fractal Adaptive Moving Average (frama), developed by John Ehlers, is an adaptive moving average that dynamically adjusts its lookback period based on fractal geometry.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (series int) Number of bars (length).

Returns: (float) The fractal adaptive moving average of the `src`.

**donchian(length)**

Calculates the center point of a donchian Channel of the `high` and `low` over the specified `length`.

Parameters:

**length**: (series int) Number of bars (length).

Returns: (float) The mid-point of a donchian Channel.

**ichimoku(conLength, baseLength, senkouLength)**

Calculates values of the Ichimoku Cloud strategy, such as tenkan, kijun, senkouSpan1, senkouSpan2, and chikou. NOTE: offsets forward or backward can be accomplished using the `offset` argument in `plot()`.

Parameters:

**conLength**: (series int) Length for the Conversion Line (Tenkan). The default is 9 periods, which returns the mid-point of the 9 period donchian Channel.

**baseLength**: (series int) Length for the Base Line (Kijun-sen). The default is 26 periods, which returns the mid-point of the 26 period donchian Channel.

**senkouLength**: (series int) Length for the Senkou Span 2 (Leading Span B). The default is 52 periods, which returns the mid-point of the 52 period donchian Channel.

Returns: () A tuple of the Tenkan, Kijun, Senkou Span 1, Senkou Span 2, and Chikou Span values. NOTE: by default, the senkouSpan1 and senkouSpan2 values should be plotted 26 periods in the future, and the Chikou Span plotted 26 days in the past.

**stochFull(periodK, smoothK, periodD)**

Calculates the %K and %D values of the Full Stochastic indicator.

Parameters:

**periodK**: (simple int) Length used for stochastic calculation. (number of bars back).

**smoothK**: (simple int) Length used for smoothing of the %K value (number of bars back).

**periodD**: (simple int) Length used for smoothing of the %D value (number of bars back).

Returns: () A tuple of the slow %K and the %D moving average values.

**stochrsi(lengthRsi, periodK, smoothK, periodD, src)**

Calculates the %K and %D values of the Stochastic RSI indicator.

Parameters:

**lengthRsi**: (simple int) Length used for RSI calculation (number of bars back).

**periodK**: (simple int) Length used for stochastic calculation (number of bars back).

**smoothK**: (simple int) Length used for smoothing of the %K value (number of bars back).

**periodD**: (simple int) Length used for smoothing of the %D value (number of bars back).

**src**: (series int/float) Series of values to process. Optional. The default is `close`.

Returns: () A tuple of the slow %K and the %D moving average values.

**dm(length)**

Calculates the value of the Demarker™ indicator.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**uo(fastLen, midLen, slowLen)**

Calculates the value of the Ultimate Oscillator.

Parameters:

**fastLen**: (simple int) Number of bars for the fast smoothing average (length).

**midLen**: (simple int) Number of bars for the middle smoothing average (length).

**slowLen**: (simple int) Number of bars for the slow smoothing average (length).

Returns: (float) The Oscillator value.

**kvo(fastLen, slowLen, trigLen)**

Calculates the values of the Klinger Volume Oscillator.

Parameters:

**fastLen**: (simple int) Number of bars for the fast smoothing average (length).

**slowLen**: (simple int) Number of bars for the slow smoothing average (length).

**trigLen**: (simple int) Number of bars for the trigger smoothing average (length).

Returns: () A tuple of the KVO value, and the trigger value.

**vhf(src, length)**

Calculates the value of the Vertical Horizontal filter.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**stc(src, fast, slow, cycle, d1, d2)**

Calculates the value of the Schaff Trend Cycle indicator.

Parameters:

**src**: (series int/float) Series of values to process.

**fast**: (simple int) Number of bars for the fast MACD value (length).

**slow**: (simple int) Number of bars for the slow MACD value (length).

**cycle**: (simple int) Number of bars for the stochastic value (length).

**d1**: (simple int) Number of bars for the smoothing of the initial %D value (length).

**d2**: (simple int) Number of bars for the smoothing of the final %D value (length).

Returns: (float) The Oscillator value.

**vi(length)**

Calculates the values of the Vortex Indicator.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: () A tuple of the viPlus and viMinus values.

**rwi(length)**

Calculates the values of the Random Walk Index.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: () A tuple of the rwiHigh and rwiLow values.

**vzo(length)**

Calculates the value of the Volume Zone Oscillator.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**pzo(length)**

Calculates the value of the Price Zone Oscillator.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**szo(src, length)**

Calculates the value of the Sentiment Zone Oscillator.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**wpo(length)**

Calculates the value of the Wave Period Oscillator.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**coppock(src, longLength, shortLength, smoothLength)**

Calculates the value of the Coppock Curve indicator.

Parameters:

**src**: (series int/float) Series of values to process.

**longLength**: (simple int) Number of bars for the fast ROC value (length).

**shortLength**: (simple int) Number of bars for the slow ROC value (length).

**smoothLength**: (simple int) Number of bars for the weigted moving average value (length).

Returns: (float) The Oscillator value.

**trix(src, length, signalLength, exponential)**

Calculates the values of the trix indicator.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars for smoothing (length).

**signalLength**: (simple int) Number of bars for smoothing the signal line (length).

**exponential**: (simple bool) Condition to determine whether exponential or simple smoothing is used. Optional. The default is `true` (exponential smoothing).

Returns: () A tuple of the trix value, the signal value, and the histogram.

**aroon(length)**

Calculates the values of the Aroon indicator.

Parameters:

**length**: (simple int) Number of bars (length).

Returns: () A tuple of the Aroon-Up and Aroon-Down values.

**eom(length, div)**

Calculates the value of the ease of Movement indicator.

Parameters:

**length**: (simple int) Number of bars (length).

**div**: (simple int) divisor used for normalzing values. Optional. The default is 10000.

Returns: (float) The Oscillator value.

**ft(src, length)**

Calculates the value of the Fisher transform indicator.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The Oscillator value.

**ift(src)**

Calculates the value of the Inverse Fisher transform indicator.

Parameters:

**src**: (series int/float) Series of values to process.

Returns: (float) The Oscillator value.

**ht(src)**

Calculates the value of the Hilbert transform indicator.

Parameters:

**src**: (series int/float) Series of values to process.

Returns: (float) The Oscillator value.

**supertrend(factor, atrPeriod, wicks)**

Calculates the values of the Supertrend indicator with the ability to take candle wicks into account, rather than only the closing price.

Parameters:

**factor**: (series int/float) Multiplier for the ATR value.

**atrPeriod**: (simple int) Number of bars for ATR calculation (length).

**wicks**: (simple bool) Condition to determine whether to take candle wicks into account when reversing trend, or to use the close price. Optional. Default is false.

Returns: (float, int) A tuple of the superTrend value and trend direction.

**rms(src, length)**

Calculates the root mean square of the `src` over the `length`.

Parameters:

**src**: (series int/float) Series of values to process.

**length**: (simple int) Number of bars (length).

Returns: (float) The rms value.

**williamsFractal(period)**

Detects Williams Fractals.

Parameters:

**period**: (series int) Number of bars (length).

Returns: () A tuple of an up fractal and down fractal. Variables are true when detected.

A myriad of new technical analysis functions have been added. The original release documentation has been edited with the new functions under the "v3" section.

Credit goes to @everget for large portions of the updated code. Thank you for your valuable contributions.

Credit goes to @everget for large portions of the updated code. Thank you for your valuable contributions.

Release Notes:

v4

Updated `aroon()` calculation to match the built-in indicator values.

Updated `aroon()` calculation to match the built-in indicator values.

v5

The Ultimate Oscillator function has been fixed to correctly return `na` on early bars before a value is rendered. In addition, a function for the Awesome Oscillator has been implemented:

Calculates the value of the Awesome Oscillator.

Parameters:

Returns: (float) The oscillator value.

The Ultimate Oscillator function has been fixed to correctly return `na` on early bars before a value is rendered. In addition, a function for the Awesome Oscillator has been implemented:

**ao(src, shortLength, longLength)**Calculates the value of the Awesome Oscillator.

Parameters:

**src****shortLength**: (series int) Number of bars for the fast moving average (length).**longLength**: (series int) Number of bars for the slow moving average (length).Returns: (float) The oscillator value.

Get $30 worth of TradingView Coins for you and a friend: www.tradingview.com/share-your-love/

Read more about the new tools and features we're building for you: www.tradingview.com/blog/en/

Read more about the new tools and features we're building for you: www.tradingview.com/blog/en/