Ta
ta.alma
ta.almaDefinition: 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 floatReturns: Arnaud Legoux Moving Average.
Arguments:
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
ta.atrDefinition: 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 floatReturns: Average true range.
Arguments:
length
simple int
Length (number of bars back).
Example (Pine Script):
//@version=5
indicator("ta.atr")
plot(ta.atr(14))
// The same on Pine
pine_atr(length) =>
trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
// True range can also be calculated with ta.tr(true)
ta.rma(trueRange, length)
plot(pine_atr(14))ta.barssince
ta.barssinceDefinition: Counts the number of bars since the last time the condition was true.
Syntax:
ta.barssince(condition) → series intReturns: Number of bars since condition was true.
Arguments:
condition
condition
The condition to check.
Example (Pine Script):
//@version=5
indicator("ta.barssince")
// Get number of bars since last color.green bar
plot(ta.barssince(close >= open))ta.bb
ta.bbDefinition: 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:
ta.bb(series, length, mult) → [series float, series float, series float]Returns: Bollinger Bands.
Arguments:
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):
//@version=5
indicator("ta.bb")
[middle, upper, lower] = ta.bb(close, 5, 4)
plot(middle, color=color.yellow)
plot(upper, color=color.yellow)
plot(lower, color=color.yellow)
// The same on Pine
f_bb(src, length, mult) =>
float basis = ta.sma(src, length)
float dev = mult * ta.stdev(src, length)
[basis, basis + dev, basis - dev]
[pineMiddle, pineUpper, pineLower] = f_bb(close, 5, 4)
plot(pineMiddle)
plot(pineUpper)
plot(pineLower)ta.bbw
ta.bbwDefinition: Bollinger Bands Width. The Bollinger Band Width is the difference between the upper and the lower Bollinger Bands divided by the middle band.
Syntax:
ta.bbw(series, length, mult) → series floatReturns: Bollinger Bands Width.
Arguments:
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):
//@version=5
indicator("ta.bbw")
plot(ta.bbw(close, 5, 4), color=color.yellow)
// The same on Pine
f_bbw(src, length, mult) =>
float basis = ta.sma(src, length)
float dev = mult * ta.stdev(src, length)
((basis + dev) - (basis - dev)) / basis
plot(f_bbw(close, 5, 4))ta.cci
ta.cciDefinition: 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:
ta.cci(source, length) → series floatReturns: Commodity channel index of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.change
ta.changeDefinition: Compares the current source value to its value length bars ago and returns the difference.
Syntax:
ta.change(source) → series float
ta.change(source) → series bool
ta.change(source) → series int
ta.change(source, length) → series float
ta.change(source, length) → series bool
ta.change(source, length) → series intReturns: 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:
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):
//@version=5
indicator('Day and Direction Change', overlay=true)
dailyBarTime = time('1D')
isNewDay = ta.change(dailyBarTime)
bgcolor(isNewDay ? color.new(color.green, 80) : na)
isGreenBar = close >= open
colorChange = ta.change(isGreenBar)
plotshape(colorChange, 'Direction Change')ta.cmo
ta.cmoDefinition: 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:
ta.cmo(series, length) → series floatReturns: Chande Momentum Oscillator.
Arguments:
series
series int/float
Series of values to process.
length
series int
Number of bars (length).
Example (Pine Script):
pineCopy code//@version=5
indicator("ta.cmo")
plot(ta.cmo(close, 5), color=color.yellow)
// The same on Pine
f_cmo(src, length) =>
float mom = ta.change(src)
float sm1 = math.sum((mom >= 0) ? mom : 0.0, length)
float sm2 = math.sum((mom >= 0) ? 0.0 : -mom, length)
100 * (sm1 - sm2) / (sm1 + sm2)
plot(f_cmo(close, 5))ta.cog
ta.cogDefinition: The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.
Syntax:
ta.cog(source, length) → series floatReturns: Center of Gravity.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
Example (Pine Script):
//@version=5
indicator("ta.cog", overlay=true)
plot(ta.cog(close, 10))
// The same on Pine
pine_cog(source, length) =>
sum = math.sum(source, length)
num = 0.0
for i = 0 to length - 1
price = source[i]
num := num + price * (i + 1)
-num / sum
plot(pine_cog(close, 10))ta.correlation
ta.correlationDefinition: Correlation coefficient. Describes the degree to which two series tend to deviate from their ta.sma values.
Syntax:
ta.correlation(source1, source2, length) → series floatReturns: Correlation coefficient.
Arguments:
source1
series int/float
Source series.
source2
series int/float
Target series.
length
series int
Length (number of bars back).
ta.cross
ta.crossDefinition: Checks if two series have crossed each other.
Syntax:
ta.cross(source1, source2) → series boolReturns: True if two series have crossed each other, otherwise false.
Arguments:
source1
series int/float
First data series.
source2
series int/float
Second data series.
ta.crossover
ta.crossoverDefinition: Checks if the source1 series has crossed over the source2 series.
Syntax:
ta.crossover(source1, source2) → series boolReturns: True if source1 crossed over source2, otherwise false.
Arguments:
source1
series int/float
First data series.
source2
series int/float
Second data series.
ta.crossunder
ta.crossunderDefinition: Checks if the source1 series has crossed under the source2 series.
Syntax:
ta.crossunder(source1, source2) → series boolReturns: True if source1 crossed under source2, otherwise false.
Arguments:
source1
series int/float
First data series.
source2
series int/float
Second data series.
ta.cum
ta.cumDefinition: Cumulative (total) sum of source. In other words, it's the sum of all elements of source.
Syntax:
ta.cum(source) → series floatReturns: Total sum series.
Arguments:
source
series int/float
Source used for the calculation.
ta.dev
ta.devDefinition: Measure of difference between the series and its ta.sma.
Syntax:
ta.dev(source, length) → series floatReturns: Deviation of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
Example (Pine Script):
//@version=5
indicator("ta.dev")
plot(ta.dev(close, 10))
// The same on Pine
pine_dev(source, length) =>
mean = ta.sma(source, length)
sum = 0.0
for i = 0 to length - 1
val = source[i]
sum := sum + math.abs(val - mean)
dev = sum/length
plot(pine_dev(close, 10))ta.dmi
ta.dmiDefinition: The dmi function returns the directional movement index.
Syntax:
ta.dmi(diLength, adxSmoothing) → [series float, series float, series float]Returns: Tuple of three DMI series: Positive Directional Movement (+DI), Negative Directional Movement (-DI), and Average Directional Movement Index (ADX).
Arguments:
diLength
simple int
DI Period.
adxSmoothing
simple int
ADX Smoothing Period.
Example (Pine Script):
//@version=5
indicator(title="Directional Movement Index", shorttitle="DMI", format=format.price, precision=4)
len = input.int(17, minval=1, title="DI Length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = ta.dmi(len, lensig)
plot(adx, color=color.red, title="ADX")
plot(diplus, color=color.blue, title="+DI")
plot(diminus, color=color.orange, title="-DI")ta.ema
ta.emaDefinition: 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:
ta.ema(source, length) → series floatReturns: Exponential moving average of source with alpha = 2 / (length + 1).
Arguments:
source
series int/float
Series of values to process.
length
simple int
Number of bars (length).
Example (Pine Script):
//@version=5
indicator("ta.ema")
plot(ta.ema(close, 15))
// The same on Pine
pine_ema(src, length) =>
alpha = 2 / (length + 1)
sum = 0.0
sum := na(sum[1]) ? src : alpha * src + (1 - alpha) * nz(sum[1])
plot(pine_ema(close, 15))ta.falling
ta.fallingDefinition: Test if the source series is now falling for length bars long.
Syntax:
ta.falling(source, length) → series boolReturns: True if the current source value is less than any previous source value for length bars back, false otherwise.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.highest
ta.highestDefinition: Highest value for a given number of bars back.
Syntax:
ta.highest(source, length) → series float
ta.highest(length) → series floatReturns: Highest value in the series.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
Remarks:
Two args version:
sourceis a series andlengthis the number of bars back.One arg version:
lengthis the number of bars back. Algorithm uses high as asourceseries.
ta.highestbars
ta.highestbarsDefinition: Highest value offset for a given number of bars back.
Syntax:
ta.highestbars(source, length) → series int
ta.highestbars(length) → series intReturns: Offset to the highest bar.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.hma
ta.hmaDefinition: The hma function returns the Hull Moving Average.
Syntax:
ta.hma(source, length) → series floatReturns: Hull moving average of 'source' for 'length' bars back.
Arguments:
source
series int/float
Series of values to process.
length
simple int
Number of bars.
ta.kc
ta.kcDefinition: 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:
ta.kc(series, length, mult) → [series float, series float, series float]
ta.kc(series, length, mult, useTrueRange) → [series float, series float, series float]Returns: Keltner Channels.
Arguments:
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
ta.kcwDefinition: Keltner Channels Width. The Keltner Channels Width is the difference between the upper and the lower Keltner Channels divided by the middle channel.
Syntax:
ta.kcw(series, length, mult) → series float
ta.kcw(series, length, mult, useTrueRange) → series floatReturns: Keltner Channels Width.
Arguments:
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
ta.linregDefinition: 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:
ta.linreg(source, length, offset) → series floatReturns: Linear regression curve.
Arguments:
source
series int/float
Source series.
length
series int
Number of bars (length).
offset
simple int
Offset.
ta.lowest
ta.lowestDefinition: Lowest value for a given number of bars back.
Syntax:
ta.lowest(source, length) → series float
ta.lowest(length) → series floatReturns: Lowest value in the series.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
Remarks:
Two args version:
sourceis a series andlengthis the number of bars back.One arg version:
lengthis the number of bars back. Algorithm uses low as asourceseries.
ta.lowestbars
ta.lowestbarsDefinition: Lowest value offset for a given number of bars back.
Syntax:
ta.lowestbars(source, length) → series int
ta.lowestbars(length) → series intReturns: Offset to the lowest bar.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.macd
ta.macdDefinition: 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:
ta.macd(source, fastlen, slowlen, siglen) → [series float, series float, series float]Returns: Tuple of three MACD series: MACD line, signal line, and histogram line.
Arguments:
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
ta.maxDefinition: Returns the all-time high value of source from the beginning of the chart up to the current bar.
Syntax:
ta.max(source) → series floatReturns: The all-time high value in the series.
Arguments:
source
series int/float
Source used for the calculation.
ta.median
ta.medianDefinition: Returns the median of the series.
Syntax:
ta.median(source, length) → series float
ta.median(source, length) → series intReturns: The median of the series.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.mfi
ta.mfiDefinition: 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:
ta.mfi(series, length) → series floatReturns: Money Flow Index.
Arguments:
series
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.min
ta.minDefinition: Returns the all-time low value of source from the beginning of the chart up to the current bar.
Syntax:
ta.min(source) → series floatReturns: The all-time low value in the series.
Arguments:
source
series int/float
Source used for the calculation.
ta.mode
ta.modeDefinition: Returns the mode of the series. If there are several values with the same frequency, it returns the smallest value.
Syntax:
bashCopy codeta.mode(source, length) → series float
ta.mode(source, length) → series intReturns: The most frequently occurring value from the source. If none exists, returns the smallest value instead.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.mom
ta.momDefinition: Momentum of source price and source price length bars ago. This is simply a difference: source - source[length].
Syntax:
ta.mom(source, length) → series floatReturns: Momentum of source price and source price length bars ago.
Arguments:
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
ta.percentile_linear_interpolationDefinition: Calculates percentile using the method of linear interpolation between the two nearest ranks.
Syntax:
ta.percentile_linear_interpolation(source, length, percentage) → series floatReturns: P-th percentile of source series for length bars back.
Arguments:
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
ta.percentile_nearest_rankDefinition: Calculates percentile using the method of Nearest Rank.
Syntax:
ta.percentile_nearest_rank(source, length, percentage) → series floatReturns: P-th percentile of source series for length bars back.
Arguments:
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
ta.percentrankDefinition: Percent rank is the percents of how many previous values were less than or equal to the current value of the given series.
Syntax:
ta.percentrank(source, length) → series floatReturns: Percent rank of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars back (length).
ta.psar
ta.psarDefinition: 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:
ta.psar(start, inc, max) → series floatReturns: Parabolic SAR.
Arguments:
start
simple int/float
Start.
inc
simple int/float
Increment.
max
simple int/float
Maximum.
ta.pvt
ta.pvtDefinition: Price-volume trend indicator (PVT) shows the relationship between price and volume and is designed to confirm price trends.
Syntax:
ta.pvt(close, volume) → series floatReturns: Price-volume trend indicator.
Arguments:
close
series int/float
Close price series.
volume
series int/float
Volume series.
ta.rma
ta.rmaDefinition: Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.
Syntax:
ta.rma(source, length) → series floatReturns: Exponential moving average of source with alpha = 1 / length.
Arguments:
source
series int/float
Series of values to process.
length
simple int
Number of bars (length).
ta.roc
ta.rocDefinition: Calculates the percentage of change (rate of change) between the current value of source and its value length bars ago.
Syntax:
ta.roc(source, length) → series floatReturns: The rate of change of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.rsi
ta.rsiDefinition: Relative strength index. It is calculated using the ta.rma() of upward and downward changes of source over the last length bars.
Syntax:
ta.rsi(source, length) → series floatReturns: Relative strength index.
Arguments:
source
series int/float
Series of values to process.
length
simple int
Number of bars (length).
ta.sar
ta.sarDefinition: 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:
ta.sar(start, inc, max) → series floatReturns: Parabolic SAR.
Arguments:
start
simple int/float
Start.
inc
simple int/float
Increment.
max
simple int/float
Maximum.
ta.sma
ta.smaDefinition: The sma function returns the moving average, that is the sum of the last length values of source, divided by length.
Syntax:
ta.sma(source, length) → series floatReturns: Simple moving average of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.stdev
ta.stdevDefinition: Standard deviation.
Syntax:
ta.stdev(source, length, biased) → series floatReturns: Standard deviation.
Arguments:
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
ta.stochDefinition: Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length)).
Syntax:
ta.stoch(source, high, low, length) → series floatReturns: Stochastic.
Arguments:
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
ta.supertrendDefinition: The Supertrend Indicator. The Supertrend is a trend following indicator.
Syntax:
ta.supertrend(factor, atrPeriod) → [series float, series float]Returns: Tuple of two supertrend series: supertrend line and direction of trend. Possible values are 1 (down direction) and -1 (up direction).
Arguments:
factor
series int/float
The multiplier by which the ATR will get multiplied.
atrPeriod
simple int
Length of ATR.
ta.swma
ta.swmaDefinition: Symmetrically weighted moving average with fixed length: 4. Weights: [1/6, 2/6, 2/6, 1/6].
Syntax:
ta.swma(source) → series floatReturns: Symmetrically weighted moving average.
Arguments:
source
series int/float
Source series.
ta.tr
ta.trDefinition: True range. It is math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1]).
Syntax:
ta.tr(handle_na) → series floatReturns: True range.
Arguments:
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
ta.tsiDefinition: True strength index. It uses moving averages of the underlying momentum of a financial instrument.
Syntax:
ta.tsi(source, short_length, long_length) → series floatReturns: True strength index. A value in the range [-1, 1].
Arguments:
source
series int/float
Source series.
short_length
simple int
Short length.
long_length
simple int
Long length.
ta.valuewhen
ta.valuewhenDefinition: Returns the value of the source series on the bar where the condition was true on the nth most recent occurrence.
Syntax:
ta.valuewhen(condition, source, occurrence) → series float
ta.valuewhen(condition, source, occurrence) → series int
ta.valuewhen(condition, source, occurrence) → series bool
ta.valuewhen(condition, source, occurrence) → series colorReturns: The value of the source series on the bar where the condition was true on the nth most recent occurrence.
Arguments:
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
ta.varianceDefinition: 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:
ta.variance(source, length, biased) → series floatReturns: Variance of source for length bars back.
Arguments:
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
ta.vwapDefinition: Volume weighted average price.
Syntax:
ta.vwap(source) → series float
ta.vwap(source, anchor) → series float
ta.vwap(source, anchor, stdev_mult) → [series float, series float, series float]Returns: A VWAP series or a tuple [vwap, upper_band, lower_band] if stdev_mult is specified.
Arguments:
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
ta.vwmaDefinition: 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:
ta.vwma(source, length) → series floatReturns: Volume-weighted moving average of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.wma
ta.wmaDefinition: The wma function returns weighted moving average of source for length bars back. In wma, weighting factors decrease in arithmetical progression.
Syntax:
ta.wma(source, length) → series floatReturns: Weighted moving average of source for length bars back.
Arguments:
source
series int/float
Series of values to process.
length
series int
Number of bars (length).
ta.wpr
ta.wprDefinition: Williams %R. The oscillator shows the current closing price in relation to the high and low of the past 'length' bars.
Syntax:
ta.wpr(length) → series floatReturns: Williams %R.
Arguments:
length
series int
Number of bars.
Last updated