ta
Types
| Name | Description |
|---|---|
PivotType | Pivot point calculation method for ta.pivot_point_levels. |
Properties
accdist
Type: series float
Accumulation/Distribution Line (ADL).
It measures the cumulative flow of money into and out of a security.
iii
Type: series float
Intraday Intensity Index (III).
It measures the flow of volume into and out of a security.
nvi
Type: series float
Negative Volume Index (NVI).
It focuses on days when the volume decreases compared to the previous day.
obv
Type: const float
On-Balance Volume (OBV).
It measures buying and selling pressure as a cumulative indicator that adds volume on up days and subtracts volume on down days.
pvi
Type: const float
Positive Volume Index (PVI).
It focuses on days when the volume increases compared to the previous day.
pvt
Type: const float
Price Volume Trend (PVT).
It combines price and volume to determine the strength of price movements.
tr
Type: series float
True Range (TR) with na handling enabled.
Equivalent to ta.tr(handle_na = true).
vwap
Type: series float
Daily Volume Weighted Average Price using hlc3 as source.
Resets at the start of each day. This is the standard VWAP used on most trading platforms.
wad
Type: const float
Williams Accumulation/Distribution (WAD).
It measures buying and selling pressure by comparing the close price to the high-low range.
wvad
Type: const float
Williams Variable Accumulation/Distribution (WVAAD).
It adjusts the accumulation/distribution calculation by considering the position of the close price within the true range.
Functions
alma
ta.alma(
series: series float,
length: series int,
offset: simple float,
sigma: simple float,
floor: simple bool = false
): series floatArnaud Legoux Moving Average.
It uses Gaussian distribution as weights for moving average.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
series | series float | Series of values to process. | |
length | series int | Number of bars (length). | |
offset | simple float | Controls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0). | |
sigma | simple float | Changes the smoothness of ALMA. The larger sigma the smoother ALMA. | |
floor | simple bool | false | Specifies whether the offset calculation is floored before ALMA is calculated. |
Returns: series float
atr
ta.atr(length: simple int): series floatCalculates the Average True Range (ATR) of a financial instrument over a specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
length | simple int | The number of bars for the ATR calculation. |
Returns: series float
bars_since
ta.bars_since(condition: series bool): series intCounts the number of bars since the last time the condition was true.
If the condition has never been true, it returns na.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
condition | series bool | The boolean condition to check. |
Returns: series int — The number of bars since the condition was last true, or na if it has never been true.
bb
ta.bb(series: series float, length: series int, mult: simple float)Bollinger Bands (BB).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
series | series float | The input series for BB calculation. | |
length | series int | The number of bars for the calculation. | |
mult | simple float | The multiplier for the standard deviation bands. |
Returns: A tuple of [basis, upper, lower] where basis is the SMA, upper/lower are basis ± mult × stdev.
Examples
let (bbBasis, bbUpper, bbLower) = ta.bb(close, 20, 2.0);
plot(bbBasis, title: "BB Basis", color: color.ORANGE);
plot(bbUpper, title: "BB Upper", color: color.BLUE);
plot(bbLower, title: "BB Lower", color: color.BLUE);bbw
ta.bbw(
source: series float,
length: series int,
mult: simple float
): series floatBollinger Band Width (BBW).
It measures the width of the Bollinger Bands relative to the moving average.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for BBW calculation. | |
length | series int | The number of bars for the calculation. | |
mult | simple float | The multiplier for the standard deviation bands. |
Returns: series float — The bandwidth as a percentage: (upper - lower) / basis × 100.
cci
ta.cci(source: series float, length: series int): series floatCommodity Channel Index (CCI).
It measures the deviation of the series series from its statistical mean.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
change
Calculates the difference between the current source value and its value length bars ago.
Useful for measuring momentum or rate of change.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series int | The integer series to compare. | |
length | series int | 1 | Number of bars to look back. Defaults to 1 (previous bar). |
Returns: series int — source - source[length].
cmo
ta.cmo(series: series float, length: series int): series floatChande Momentum Oscillator (CMO).
It measures the momentum of the series series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
series | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float — A value between -100 and 100. Positive values indicate upward momentum, negative indicate downward.
cog
ta.cog(source: series float, length: series int): series floatCenter of Gravity (COG).
It identifies the center of gravity of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
correlation
ta.correlation(
source1: series float,
source2: series float,
length: series int
): series floatPearson Correlation Coefficient between two series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source1 | series float | The first input series. | |
source2 | series float | The second input series. | |
length | series int | The number of bars for the calculation. |
Returns: series float — A value between -1.0 (perfectly negatively correlated) and 1.0 (perfectly positively correlated). 0.0 indicates no linear correlation.
cross
ta.cross(source1: series float, source2: series float): series boolDetects if source1 has crossed source2 in either direction.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source1 | series float | The first series to compare. | |
source2 | series float | The second series to compare. |
Returns: series bool
cross_over
ta.cross_over(source1: series float, source2: series float): series boolDetects if source1 has crossed over source2.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source1 | series float | The first series to compare. | |
source2 | series float | The second series to compare. |
Returns: series bool
Examples
let fastEma = ta.ema(close, 9);
let slowEma = ta.ema(close, 21);
if ta.cross_over(fastEma, slowEma) {
label.new(bar_index, low, "Buy", style: LabelStyle.Up);
}cross_under
ta.cross_under(source1: series float, source2: series float): series boolDetects if source1 has crossed under source2.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source1 | series float | The first series to compare. | |
source2 | series float | The second series to compare. |
Returns: series bool
Examples
let fastEma = ta.ema(close, 9);
let slowEma = ta.ema(close, 21);
if ta.cross_under(fastEma, slowEma) {
label.new(bar_index, high, "Sell", style: LabelStyle.Down);
}cum
ta.cum(source: series float): series floatCumulative sum of the source series.
In other words it's a sum of all elements of the source series.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to accumulate. |
Returns: series float
dev
ta.dev(source: series float, length: series int): series floatMean Deviation of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
dmi
ta.dmi(di_length: simple int, adx_smoothing: simple int)Directional Movement Index (DMI).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
di_length | simple int | The length for Directional Indicator calculation. | |
adx_smoothing | simple int | The smoothing length for ADX calculation. |
Returns: A tuple of [plus_di, minus_di, adx], all expressed as percentages (0–100).
ema
ta.ema(source: series float, length: simple int): series floatExponential Moving Average (EMA).
It gives more weight to recent prices to make it more responsive to new information.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | simple int | The number of bars for the calculation. |
Returns: series float
Examples
let ema12 = ta.ema(close, 12);
let ema26 = ta.ema(close, 26);
plot(ema12, title: "EMA 12", color: color.GREEN);
plot(ema26, title: "EMA 26", color: color.RED);falling
ta.falling(source: series float, length: series int): series boolChecks if the source series is falling over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to check. | |
length | series int | The number of bars to check. |
Returns: series bool
highest
Returns the highest value of the high series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
length | series int | The number of bars to check. |
Returns: series float
highest_bars
Returns the number of bars since the highest value of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars to check. |
Returns: series int — A non-positive offset (0 if the highest is the current bar, negative otherwise), or na if any value in the window is na.
hma
ta.hma(source: series float, length: simple int): series floatHull Moving Average (HMA).
It aims to reduce lag while maintaining a smooth curve.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | simple int | The number of bars for the calculation. |
Returns: series float
kc
ta.kc(
series: series float,
length: simple int,
mult: simple float,
use_true_range: simple bool = true
)Keltner Channels (KC).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
series | series float | The input series for KC calculation. | |
length | simple int | The number of bars for the calculation. | |
mult | simple float | The multiplier for the channel bands. | |
use_true_range | simple bool | true | Whether to use True Range. |
Returns: A tuple of [basis, upper, lower] where basis is the EMA, upper/lower are basis ± mult × range EMA.
kcw
ta.kcw(
series: series float,
length: simple int,
mult: simple float,
use_true_range: simple bool = true
): series floatKeltner Channel Width (KCW).
It measures the width of the Keltner Channels relative to the moving average.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
series | series float | The input series for KCW calculation. | |
length | simple int | The number of bars for the calculation. | |
mult | simple float | The multiplier for the channel bands. | |
use_true_range | simple bool | true | Whether to use True Range. |
Returns: series float — The channel width as a ratio: (upper - lower) / basis.
linreg
ta.linreg(
source: series float,
length: series int,
offset: simple int
): series floatLinear Regression (LINREG).
It fits a linear regression line to the source series over the specified length and returns the value at the given offset.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the regression. | |
offset | simple int | The offset for the regression line (future bar offset). |
Returns: series float
lowest
Returns the lowest value of the low series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
length | series int | The number of bars to check. |
Returns: series float
lowest_bars
Returns the number of bars since the lowest value of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars to check. |
Returns: series int — A non-positive offset (0 if the lowest is the current bar, negative otherwise), or na if any value in the window is na.
macd
ta.macd(
source: series float,
fast_length: simple int,
slow_length: simple int,
signal_length: simple int
)Moving Average Convergence Divergence (MACD).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
fast_length | simple int | The length for the fast EMA. | |
slow_length | simple int | The length for the slow EMA. | |
signal_length | simple int | The length for the signal line EMA. |
Returns: A tuple of [macd_line, signal_line, histogram] where histogram = macd_line − signal_line.
Examples
let (macdLine, signalLine, histLine) = ta.macd(close, 12, 26, 9);
plot(macdLine, title: "MACD", color: color.BLUE);
plot(signalLine, title: "Signal", color: color.ORANGE);
plot(histLine, title: "Hist", color: color.GRAY, style: PlotStyle.Histogram);max
ta.max(source: series float): series floatReturns the maximum value of the source series.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. |
Returns: series float
median
ta.median(source: series float, length: series int): series floatReturns the median value of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars for the calculation. |
Returns: series float
mfi
ta.mfi(series: series float, length: series int): series floatMoney Flow Index (MFI).
It measures the inflow and outflow of money into an asset over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
series | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float — A value between 0 and 100. Values above 80 indicate overbought conditions, below 20 indicate oversold.
min
ta.min(source: series float): series floatReturns the minimum value of the source series.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. |
Returns: series float
mode
ta.mode(source: series float, length: series int): series floatReturns the mode (most frequently occurring value) of the series series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars for the calculation. |
Returns: series float
mom
ta.mom(source: series float, length: series int): series floatCalculates the momentum of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
percent_rank
ta.percent_rank(source: series float, length: series int): series floatReturns the percentile rank of the current value in the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars for the calculation. |
Returns: series float — A value between 0 and 100 indicating the percentage of values that are less than or equal to the current value.
percentile_linear_interpolation
ta.percentile_linear_interpolation(
source: series float,
length: series int,
percentage: simple float
): series floatReturns the percentile value of the source series over the specified length using linear interpolation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars for the calculation. | |
percentage | simple float | The percentile value (0-100). |
Returns: series float
percentile_nearest_rank
ta.percentile_nearest_rank(
source: series float,
length: series int,
percentage: simple float
): series floatReturns the percentile value of the source series over the specified length using the nearest-rank method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars for the calculation. | |
percentage | simple float | The percentile value (0-100). |
Returns: series float
pivot_high
Returns the price of the pivot high point.
It returns 'NaN', if there was no pivot high point.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to analyze. | |
left_bars | series int | The number of bars to the left to check. | |
right_bars | series int | The number of bars to the right to check. |
Returns: series float — The pivot high price (offset by right_bars), or na if no pivot is found at that point.
pivot_low
Returns the price of the pivot low point.
It returns 'NaN', if there was no pivot low point.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to analyze. | |
left_bars | series int | The number of bars to the left to check. | |
right_bars | series int | The number of bars to the right to check. |
Returns: series float — The pivot low price (offset by right_bars), or na if no pivot is found at that point.
pivot_point_levels
ta.pivot_point_levels(
type: series PivotType,
change: series bool
): series Array<float>Returns an array of pivot point levels for the specified pivot type.
The returned array contains up to 11 values in the order: [P, S1, R1, S2, R2, S3, R3, S4, R4, S5, R5]. Levels that do not apply for the chosen type are na.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
type | series PivotType | The pivot calculation method. | |
change | series bool | true on the first bar of a new pivot period. |
Returns: series Array<float>
range
ta.range(source: series float, length: series int): series floatReturns the range (difference between highest and lowest) of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to evaluate. | |
length | series int | The number of bars for the calculation. |
Returns: series float
rci
ta.rci(source: series float, length: simple int): series floatRank Correlation Index (RCI).
It measures the strength and direction of a linear relationship between the ranks of two variables over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | simple int | The number of bars for the calculation. |
Returns: series float — A value between -100 and 100. +100 means prices are perfectly rising, -100 means perfectly falling.
rising
ta.rising(source: series float, length: series int): series boolChecks if the source series is rising over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series to check. | |
length | series int | The number of bars to check. |
Returns: series bool
rma
ta.rma(source: series float, length: series int): series floatRecursive Moving Average (RMA).
It is similar to an Exponential Moving Average (EMA) but uses a different smoothing factor.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The length for the RMA calculation. |
Returns: series float
roc
ta.roc(source: series float, length: series int): series floatRate of Change (ROC).
It measures the percentage change between the current value and the value length bars ago.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the comparison. |
Returns: series float — The percentage change: 100 × (source − source[length]) / source[length].
rsi
ta.rsi(source: series float, length: series int): series floatRelative Strength Index (RSI).
It measures the speed and change of price movements over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float — A value between 0 and 100. Values above 70 typically indicate overbought, below 30 oversold.
Examples
let rsiValue = ta.rsi(close, 14);
plot(rsiValue, title: "RSI", color: color.PURPLE);
hline(70, "Overbought", color: color.RED);
hline(30, "Oversold", color: color.GREEN);sar
ta.sar(start: simple float, inc: simple float, max: simple float): series floatParabolic SAR.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
start | simple float | The starting acceleration factor. | |
inc | simple float | The increment for the acceleration factor. | |
max | simple float | The maximum acceleration factor. |
Returns: series float — The SAR value for the current bar.
sma
ta.sma(source: series float, length: series int): series floatSimple Moving Average (SMA).
Calculates the average of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
Examples
let sma20 = ta.sma(close, 20);
plot(sma20, title: "SMA 20", color: color.BLUE);stdev
ta.stdev(
source: series float,
length: series int,
biased: series bool = true
): series floatCalculates the standard deviation of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. | |
biased | series bool | true | If true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample. |
Returns: series float
stoch
ta.stoch(
source: series float,
high: series float,
low: series float,
length: series int
): series floatStochastic Oscillator (STOCH).
It compares the source series to its price range over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
high | series float | The high series for the range. | |
low | series float | The low series for the range. | |
length | series int | The number of bars for the calculation. |
Returns: series float — A value between 0 and 100 representing the position of the source within the high-low range.
supertrend
ta.supertrend(factor: series float, atr_period: simple int)SuperTrend indicator.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
factor | series float | The multiplier for ATR in the SuperTrend calculation. | |
atr_period | simple int | The period for ATR calculation. |
Returns: A tuple of [super_trend, direction] where direction is -1 (uptrend/bullish) or 1 (downtrend/bearish).
swma
ta.swma(source: series float): series floatSmoothed Weighted Moving Average (SWMA).
It applies weighted moving average smoothing to the source series.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. |
Returns: series float
tr
ta.tr(handle_na: simple bool): series floatTrue Range (TR).
Measures volatility by accounting for gaps between bars. TR is the greatest of: (high - low), |high - previous close|, |low - previous close|. This captures overnight gaps and limit moves that high-low alone would miss.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
handle_na | simple bool | If true and previous close is na (first bar), uses high - low as TR. If false, returns na in that case. |
Returns: series float
tsi
ta.tsi(
source: series float,
short_length: simple int,
long_length: simple int
): series floatTrue Strength Index (TSI).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
short_length | simple int | The short EMA length for TSI calculation. | |
long_length | simple int | The long EMA length for TSI calculation. |
Returns: series float — A value between -1.0 and 1.0 representing momentum strength and direction.
value_when
ta.value_when(
condition: series bool,
source: series T,
occurrence: simple int
): series TReturns the value of the source series at the time when the condition was true for the specified occurrence.
The occurrence parameter selects which match to return: 0 for the most recent, 1 for the one before that, etc.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
condition | series bool | The condition to evaluate. | |
source | series T | The series to retrieve the value from. | |
occurrence | simple int | Which occurrence to retrieve (0 for the most recent). |
Returns: series T — The source value at the specified occurrence, or na if fewer matches have occurred.
variance
ta.variance(
source: series float,
length: series int,
biased: series bool = true
): series floatVariance of the source series over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. | |
biased | series bool | true | If true, uses biased estimation; if false, uses unbiased estimation. |
Returns: series float
vwap
Volume Weighted Average Price with optional standard deviation bands.
VWAP accumulates since the anchor resets (typically daily) and weights price by volume, giving a benchmark that institutions often use. Returns a tuple of [vwap, upper_band, lower_band] where bands are vwap +/- stdev_mult * stddev.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The price series (commonly hlc3). | |
anchor | series bool | When true, resets the VWAP calculation. Typically timeframe.change("1D"). | |
stdev_mult | series float | Multiplier for standard deviation bands. Use na to disable bands. |
Returns: A tuple of [vwap, upper_band, lower_band]. Bands are na when stdev_mult is na.
vwma
ta.vwma(source: series float, length: series int): series floatVolume Weighted Moving Average (VWMA).
It gives more weight to periods with higher volume.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
wma
ta.wma(source: series float, length: series int): series floatWeighted Moving Average (WMA).
It assigns more weight to recent data points.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | series float | The input series for the calculation. | |
length | series int | The number of bars for the calculation. |
Returns: series float
wpr
ta.wpr(length: series int): series floatWilliams Percent Range (WPR).
It measures overbought and oversold levels by comparing the close price to the high-low range over the specified length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
length | series int | The number of bars for the calculation. |
Returns: series float — A value between -100 and 0. Values above -20 indicate overbought, below -80 indicate oversold.