Skip to content

ta

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

pine
ta.alma(
    series float series,
    series int length,
    simple float offset,
    simple float sigma,
    simple bool floor = false
  ) → series float

Arnaud Legoux Moving Average.

It uses Gaussian distribution as weights for moving average.

Parameters

NameTypeDefaultDescription
seriesseries floatSeries of values to process.
lengthseries intNumber of bars (length).
offsetsimple floatControls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0).
sigmasimple floatChanges the smoothness of ALMA. The larger sigma the smoother ALMA.
floorsimple boolfalseSpecifies whether the offset calculation is floored before ALMA is calculated.

Returns: series float


atr

pine
ta.atr(simple int length) → series float

Calculates the Average True Range (ATR) of a financial instrument over a specified length.

Parameters

NameTypeDefaultDescription
lengthsimple intThe number of bars for the ATR calculation.

Returns: series float


barssince

pine
ta.barssince(series bool condition) → series int

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

If the condition has never been true, it returns na.

Parameters

NameTypeDefaultDescription
conditionseries boolThe 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

pine
ta.bb(series float series, series int length, simple float mult)

Bollinger Bands (BB).

Parameters

NameTypeDefaultDescription
seriesseries floatThe input series for BB calculation.
lengthseries intThe number of bars for the calculation.
multsimple floatThe multiplier for the standard deviation bands.

Returns: A tuple of [basis, upper, lower] where basis is the SMA, upper/lower are basis ± mult × stdev.


bbw

pine
ta.bbw(series float source, series int length, simple float mult) → series float

Bollinger Band Width (BBW).

It measures the width of the Bollinger Bands relative to the moving average.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for BBW calculation.
lengthseries intThe number of bars for the calculation.
multsimple floatThe multiplier for the standard deviation bands.

Returns: series float — The bandwidth as a percentage: (upper - lower) / basis × 100.


cci

pine
ta.cci(series float source, series int length) → series float

Commodity Channel Index (CCI).

It measures the deviation of the series series from its statistical mean.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe 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

NameTypeDefaultDescription
sourceseries intThe integer series to compare.
lengthseries int1Number of bars to look back. Defaults to 1 (previous bar).

Returns: series intsource - source[length].

Calculates the difference between the current source value and its value length bars ago.

Parameters

NameTypeDefaultDescription
sourceseries floatThe float series to compare.
lengthseries int1Number of bars to look back. Defaults to 1 (previous bar).

Returns: series floatsource - source[length].

Detects if a boolean value has changed from its value length bars ago.

Useful for detecting state transitions (e.g., signal flips).

Parameters

NameTypeDefaultDescription
sourceseries boolThe boolean series to compare.
lengthseries int1Number of bars to look back. Defaults to 1 (previous bar).

Returns: series booltrue if the current value differs from the historical value, false otherwise.


cmo

pine
ta.cmo(series float series, series int length) → series float

Chande Momentum Oscillator (CMO).

It measures the momentum of the series series over the specified length.

Parameters

NameTypeDefaultDescription
seriesseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float — A value between -100 and 100. Positive values indicate upward momentum, negative indicate downward.


cog

pine
ta.cog(series float source, series int length) → series float

Center of Gravity (COG).

It identifies the center of gravity of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float


correlation

pine
ta.correlation(
    series float source1,
    series float source2,
    series int length
  ) → series float

Pearson Correlation Coefficient between two series over the specified length.

Parameters

NameTypeDefaultDescription
source1series floatThe first input series.
source2series floatThe second input series.
lengthseries intThe 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

pine
ta.cross(series float source1, series float source2) → series bool

Detects if source1 has crossed source2 in either direction.

Parameters

NameTypeDefaultDescription
source1series floatThe first series to compare.
source2series floatThe second series to compare.

Returns: series bool


crossover

pine
ta.crossover(series float source1, series float source2) → series bool

Detects if source1 has crossed over source2.

Parameters

NameTypeDefaultDescription
source1series floatThe first series to compare.
source2series floatThe second series to compare.

Returns: series bool


crossunder

pine
ta.crossunder(series float source1, series float source2) → series bool

Detects if source1 has crossed under source2.

Parameters

NameTypeDefaultDescription
source1series floatThe first series to compare.
source2series floatThe second series to compare.

Returns: series bool


cum

pine
ta.cum(series float source) → series float

Cumulative sum of the source series.

In other words it's a sum of all elements of the source series.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to accumulate.

Returns: series float


dev

pine
ta.dev(series float source, series int length) → series float

Mean Deviation of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float


dmi

pine
ta.dmi(series float diLength, series int adxSmoothing)

Directional Movement Index (DMI).

Parameters

NameTypeDefaultDescription
diLengthseries floatThe length for Directional Indicator calculation.
adxSmoothingseries intThe smoothing length for ADX calculation.

Returns: A tuple of [plus_di, minus_di, adx], all expressed as percentages (0–100).


ema

pine
ta.ema(series float source, simple int length) → series float

Exponential Moving Average (EMA).

It gives more weight to recent prices to make it more responsive to new information.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthsimple intThe number of bars for the calculation.

Returns: series float


falling

pine
ta.falling(series float source, series int length) → series bool

Checks if the source series is falling over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to check.
lengthseries intThe number of bars to check.

Returns: series bool


highest

Returns the highest value of the high series over the specified length.

Parameters

NameTypeDefaultDescription
lengthseries intThe number of bars to check.

Returns: series float

Returns the highest value of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars to check.

Returns: series float


highestbars

Returns the number of bars since the highest value of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe 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.

Returns the number of bars since the highest value of the high series over the specified length.

Parameters

NameTypeDefaultDescription
lengthseries intThe number of bars to check.

Returns: series int


hma

pine
ta.hma(series float source, simple int length) → series float

Hull Moving Average (HMA).

It aims to reduce lag while maintaining a smooth curve.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthsimple intThe number of bars for the calculation.

Returns: series float


kc

pine
ta.kc(
    series float series,
    simple int length,
    simple float mult,
    simple bool useTrueRange = true
  )

Keltner Channels (KC).

Parameters

NameTypeDefaultDescription
seriesseries floatThe input series for KC calculation.
lengthsimple intThe number of bars for the calculation.
multsimple floatThe multiplier for the channel bands.
useTrueRangesimple booltrueWhether to use True Range.

Returns: A tuple of [basis, upper, lower] where basis is the EMA, upper/lower are basis ± mult × range EMA.


kcw

pine
ta.kcw(
    series float series,
    simple int length,
    simple float mult,
    simple bool useTrueRange = true
  ) → series float

Keltner Channel Width (KCW).

It measures the width of the Keltner Channels relative to the moving average.

Parameters

NameTypeDefaultDescription
seriesseries floatThe input series for KCW calculation.
lengthsimple intThe number of bars for the calculation.
multsimple floatThe multiplier for the channel bands.
useTrueRangesimple booltrueWhether to use True Range.

Returns: series float — The channel width as a ratio: (upper - lower) / basis.


linreg

pine
ta.linreg(
    series float source,
    series int length,
    simple int offset
  ) → series float

Linear 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

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the regression.
offsetsimple intThe 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

NameTypeDefaultDescription
lengthseries intThe number of bars to check.

Returns: series float

Returns the lowest value of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars to check.

Returns: series float


lowestbars

Returns the number of bars since the lowest value of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe 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.

Returns the number of bars since the lowest value of the low series over the specified length.

Parameters

NameTypeDefaultDescription
lengthseries intThe number of bars to check.

Returns: series int


macd

pine
ta.macd(
    series float source,
    simple int fast_length,
    simple int slow_length,
    simple int signal_length
  )

Moving Average Convergence Divergence (MACD).

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
fast_lengthsimple intThe length for the fast EMA.
slow_lengthsimple intThe length for the slow EMA.
signal_lengthsimple intThe length for the signal line EMA.

Returns: A tuple of [macd_line, signal_line, histogram] where histogram = macd_line − signal_line.


max

pine
ta.max(series float source) → series float

Returns the maximum value of the source series.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.

Returns: series float


median

pine
ta.median(series float source, series int length) → series float

Returns the median value of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars for the calculation.

Returns: series float


mfi

pine
ta.mfi(series float series, series int length) → series float

Money Flow Index (MFI).

It measures the inflow and outflow of money into an asset over the specified length.

Parameters

NameTypeDefaultDescription
seriesseries floatThe input series for the calculation.
lengthseries intThe 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

pine
ta.min(series float source) → series float

Returns the minimum value of the source series.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.

Returns: series float


mode

pine
ta.mode(series float source, series int length) → series float

Returns the mode (most frequently occurring value) of the series series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars for the calculation.

Returns: series float


mom

pine
ta.mom(series float source, series int length) → series float

Calculates the momentum of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float


percentile_linear_interpolation

pine
ta.percentile_linear_interpolation(
    series float source,
    series int length,
    simple float percentage
  ) → series float

Returns the percentile value of the source series over the specified length using linear interpolation.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars for the calculation.
percentagesimple floatThe percentile value (0-100).

Returns: series float


percentile_nearest_rank

pine
ta.percentile_nearest_rank(
    series float source,
    series int length,
    simple float percentage
  ) → series float

Returns the percentile value of the source series over the specified length using the nearest-rank method.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars for the calculation.
percentagesimple floatThe percentile value (0-100).

Returns: series float


percentrank

pine
ta.percentrank(series float source, series int length) → series float

Returns the percentile rank of the current value in the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe 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.


pivothigh

Returns the price of the pivot high point.

It returns 'NaN', if there was no pivot high point.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to analyze.
leftbarsseries intThe number of bars to the left to check.
rightbarsseries intThe number of bars to the right to check.

Returns: series float — The pivot high price (offset by rightbars), or na if no pivot is found at that point.

Returns the pivot high price.

Parameters

NameTypeDefaultDescription
leftbarsseries intThe number of bars to the left to check.
rightbarsseries intThe number of bars to the right to check.

Returns: series float


pivotlow

Returns the price of the pivot low point.

It returns 'NaN', if there was no pivot low point.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to analyze.
leftbarsseries intThe number of bars to the left to check.
rightbarsseries intThe number of bars to the right to check.

Returns: series float — The pivot low price (offset by rightbars), or na if no pivot is found at that point.

Returns the pivot low price.

Parameters

NameTypeDefaultDescription
leftbarsseries intThe number of bars to the left to check.
rightbarsseries intThe number of bars to the right to check.

Returns: series float


range

pine
ta.range(series float source, series int length) → series float

Returns the range (difference between highest and lowest) of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to evaluate.
lengthseries intThe number of bars for the calculation.

Returns: series float


rci

pine
ta.rci(series float source, simple int length) → series float

Rank Correlation Index (RCI).

It measures the strength and direction of a linear relationship between the ranks of two variables over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthsimple intThe 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

pine
ta.rising(series float source, series int length) → series bool

Checks if the source series is rising over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series to check.
lengthseries intThe number of bars to check.

Returns: series bool


rma

pine
ta.rma(series float source, series int length) → series float

Recursive Moving Average (RMA).

It is similar to an Exponential Moving Average (EMA) but uses a different smoothing factor.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe length for the RMA calculation.

Returns: series float


roc

pine
ta.roc(series float source, series int length) → series float

Rate of Change (ROC).

It measures the percentage change between the current value and the value length bars ago.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the comparison.

Returns: series float — The percentage change: 100 × (source − source[length]) / source[length].


rsi

pine
ta.rsi(series float source, series int length) → series float

Relative Strength Index (RSI).

It measures the speed and change of price movements over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float — A value between 0 and 100. Values above 70 typically indicate overbought, below 30 oversold.


sar

pine
ta.sar(simple float start, simple float inc, simple float max) → series float

Parabolic SAR.

Parameters

NameTypeDefaultDescription
startsimple floatThe starting acceleration factor.
incsimple floatThe increment for the acceleration factor.
maxsimple floatThe maximum acceleration factor.

Returns: series float — The SAR value for the current bar.


sma

pine
ta.sma(series float source, series int length) → series float

Simple Moving Average (SMA).

Calculates the average of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float


stdev

pine
ta.stdev(
    series float source,
    series int length,
    series bool biased = true
  ) → series float

Calculates the standard deviation of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.
biasedseries booltrueIf true, function will calculate using a biased estimate of the entire population, if false - unbiased estimate of a sample.

Returns: series float


stoch

pine
ta.stoch(
    series float source,
    series float high,
    series float low,
    series int length
  ) → series float

Stochastic Oscillator (STOCH).

It compares the source series to its price range over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
highseries floatThe high series for the range.
lowseries floatThe low series for the range.
lengthseries intThe 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

pine
ta.supertrend(series float factor, simple int atrPeriod)

SuperTrend indicator.

Parameters

NameTypeDefaultDescription
factorseries floatThe multiplier for ATR in the SuperTrend calculation.
atrPeriodsimple intThe period for ATR calculation.

Returns: A tuple of [super_trend, direction] where direction is -1 (uptrend/bullish) or 1 (downtrend/bearish).


swma

pine
ta.swma(series float source) → series float

Smoothed Weighted Moving Average (SWMA).

It applies weighted moving average smoothing to the source series.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.

Returns: series float


tr

pine
ta.tr(simple bool handle_na) → series float

True 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

NameTypeDefaultDescription
handle_nasimple boolIf true and previous close is na (first bar), uses high - low as TR. If false, returns na in that case.

Returns: series float


tsi

pine
ta.tsi(
    series float source,
    simple int short_length,
    simple int long_length
  ) → series float

True Strength Index (TSI).

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
short_lengthsimple intThe short EMA length for TSI calculation.
long_lengthsimple intThe long EMA length for TSI calculation.

Returns: series float — A value between -1.0 and 1.0 representing momentum strength and direction.


valuewhen

pine
ta.valuewhen(
    series bool condition,
    series T source,
    simple int occurrence
  ) → series T

Returns 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

NameTypeDefaultDescription
conditionseries boolThe condition to evaluate.
sourceseries TThe series to retrieve the value from.
occurrencesimple intWhich 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

pine
ta.variance(
    series float source,
    series int length,
    series bool biased = true
  ) → series float

Variance of the source series over the specified length.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.
biasedseries booltrueIf 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

NameTypeDefaultDescription
sourceseries floatThe price series (commonly hlc3).
anchorseries boolWhen true, resets the VWAP calculation. Typically timeframe.change("1D").
stdev_multseries floatMultiplier 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.

Volume Weighted Average Price without bands.

Parameters

NameTypeDefaultDescription
sourceseries floatThe price series (commonly hlc3).
anchorseries booltimeframe.change("1D")When true, resets the VWAP. Defaults to daily reset (timeframe.change("1D")).

Returns: series float — A single VWAP series that resets when anchor is true.


vwma

pine
ta.vwma(series float source, series int length) → series float

Volume Weighted Moving Average (VWMA).

It gives more weight to periods with higher volume.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float


wma

pine
ta.wma(series float source, series int length) → series float

Weighted Moving Average (WMA).

It assigns more weight to recent data points.

Parameters

NameTypeDefaultDescription
sourceseries floatThe input series for the calculation.
lengthseries intThe number of bars for the calculation.

Returns: series float


wpr

pine
ta.wpr(series int length) → series float

Williams Percent Range (WPR).

It measures overbought and oversold levels by comparing the close price to the high-low range over the specified length.

Parameters

NameTypeDefaultDescription
lengthseries intThe number of bars for the calculation.

Returns: series float — A value between -100 and 0. Values above -20 indicate overbought, below -80 indicate oversold.

基于 MIT 许可证发布。