TradingView

ta

TradingView ที่อัปเดต:   
Library "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


This version includes the following new functions:

aroon(length)
  Calculates the values of the Aroon indicator.
  Parameters:
    length (simple int): (simple int) Number of bars (length).
  Returns: ([float, float]) A tuple of the Aroon-Up and Aroon-Down values.

coppock(source, longLength, shortLength, smoothLength)
  Calculates the value of the Coppock Curve indicator.
  Parameters:
    source (float): (series int/float) Series of values to process.
    longLength (simple int): (simple int) Number of bars for the fast ROC value (length).
    shortLength (simple int): (simple int) Number of bars for the slow ROC value (length).
    smoothLength (simple int): (simple int) Number of bars for the weigted moving average value (length).
  Returns: (float) The oscillator value.

dema(source, length)
  Calculates the value of the Double Exponential Moving Average (DEMA).
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Length for the smoothing parameter calculation.
  Returns: (float) The double exponentially weighted moving average of the `source`.

d​ema2(​src, length)
  An alternate ​Double Exponential ​Moving Average (D​ema) function to `d​ema()`, which allows a "series float" length argument.
  Parameters:
    ​src: (series int/float) Series of values to process.
    length: (series int/float) Length for the smoothing parameter calculation.
  Returns: (float) The double exponentially ​weighted moving average of the `​src`.

dm(length)
  Calculates the value of the "Demarker" indicator.
  Parameters:
    length (simple int): (simple int) Number of bars (length).
  Returns: (float) The oscillator value.

donchian(length)
  Calculates the values of a Donchian Channel using `high` and `low` over a given `length`.
  Parameters:
    length (int): (series int) Number of bars (length).
  Returns: ([float, float, float]) A tuple containing the channel high, low, and median, respectively.

​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`.

eom(length, div)
  Calculates the value of the Ease of Movement indicator.
  Parameters:
    length (simple int): (simple int) Number of bars (length).
    div (simple int): (simple int) Divisor used for normalzing values. Optional. The default is 10000.
  Returns: (float) The oscillator value.

frama(source, 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:
    source (float): (series int/float) Series of values to process.
    length (int): (series int) Number of bars (length).
  Returns: (float) The fractal adaptive moving average of the `source`.

ft(source, length)
  Calculates the value of the Fisher Transform indicator.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Number of bars (length).
  Returns: (float) The oscillator value.

ht(source)
  Calculates the value of the Hilbert Transform indicator.
  Parameters:
    source (float): (series int/float) Series of values to process.
  Returns: (float) The oscillator value.

ichimoku(conLength, baseLength, senkouLength)
  Calculates values of the Ichimoku Cloud indicator, including tenkan, kijun, senkouSpan1, senkouSpan2, and chikou. NOTE: offsets forward or backward can be done using the `offset` argument in `plot()`.
  Parameters:
    conLength (int): (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 (int): (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 (int): (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: ([float, float, float, float, float]) A tuple of the Tenkan, Kijun, Senkou Span 1, Senkou Span 2, and Chikou Span values. NOTE: by default, the senkouSpan1 and senkouSpan2 should be plotted 26 periods in the future, and the Chikou Span plotted 26 days in the past.

ift(source)
  Calculates the value of the Inverse Fisher Transform indicator.
  Parameters:
    source (float): (series int/float) Series of values to process.
  Returns: (float) The oscillator value.

kvo(fastLen, slowLen, trigLen)
  Calculates the values of the Klinger Volume Oscillator.
  Parameters:
    fastLen (simple int): (simple int) Length for the fast moving average smoothing parameter calculation.
    slowLen (simple int): (simple int) Length for the slow moving average smoothing parameter calculation.
    trigLen (simple int): (simple int) Length for the trigger moving average smoothing parameter calculation.
  Returns: ([float, float]) A tuple of the KVO value, and the trigger value.

pzo(length)
  Calculates the value of the Price Zone Oscillator.
  Parameters:
    length (simple int): (simple int) Length for the smoothing parameter calculation.
  Returns: (float) The oscillator value.

rms(source, length)
  Calculates the Root Mean Square of the `source` over the `length`.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (int): (series int) Number of bars (length).
  Returns: (float) The RMS value.

rwi(length)
  Calculates the values of the Random Walk Index.
  Parameters:
    length (simple int): (simple int) Lookback and ATR smoothing parameter length.
  Returns: ([float, float]) A tuple of the `rwiHigh` and `rwiLow` values.

stc(source, fast, slow, cycle, d1, d2)
  Calculates the value of the Schaff Trend Cycle indicator.
  Parameters:
    source (float): (series int/float) Series of values to process.
    fast (simple int): (simple int) Length for the MACD fast smoothing parameter calculation.
    slow (simple int): (simple int) Length for the MACD slow smoothing parameter calculation.
    cycle (simple int): (simple int) Number of bars for the Stochastic values (length).
    d1 (simple int): (simple int) Length for the initial %D smoothing parameter calculation.
    d2 (simple int): (simple int) Length for the final %D smoothing parameter calculation.
  Returns: (float) The oscillator value.

stochFull(periodK, smoothK, periodD)
  Calculates the %K and %D values of the Full Stochastic indicator.
  Parameters:
    periodK (simple int): (simple int) Number of bars for Stochastic calculation. (length).
    smoothK (simple int): (simple int) Number of bars for smoothing of the %K value (length).
    periodD (simple int): (simple int) Number of bars for smoothing of the %D value (length).
  Returns: ([float, float]) A tuple of the slow %K and the %D moving average values.

stochRsi(lengthRsi, periodK, smoothK, periodD, source)
  Calculates the %K and %D values of the Stochastic RSI indicator.
  Parameters:
    lengthRsi (simple int): (simple int) Length for the RSI smoothing parameter calculation.
    periodK (simple int): (simple int) Number of bars for Stochastic calculation. (length).
    smoothK (simple int): (simple int) Number of bars for smoothing of the %K value (length).
    periodD (simple int): (simple int) Number of bars for smoothing of the %D value (length).
    source (float): (series int/float) Series of values to process. Optional. The default is `close`.
  Returns: ([float, float]) A tuple of the slow %K and the %D moving average values.

supertrend(factor, atrLength, 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 (float): (series int/float) Multiplier for the ATR value.
    atrLength (simple int): (simple int) Length for the ATR smoothing parameter calculation.
    wicks (simple bool): (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.

szo(source, length)
  Calculates the value of the Sentiment Zone Oscillator.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Length for the smoothing parameter calculation.
  Returns: (float) The oscillator value.

t3(source, length, vf)
  Calculates the value of the Tilson Moving Average (T3).
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Length for the smoothing parameter calculation.
    vf (simple float): (simple float) Volume factor. Affects the responsiveness.
  Returns: (float) The Tilson moving average of the `source`.

t3Alt(source, length, vf)
  An alternate Tilson Moving Average (T3) function to `t3()`, which allows a "series float" `length` argument.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (float): (series int/float) Length for the smoothing parameter calculation.
    vf (simple float): (simple float) Volume factor. Affects the responsiveness.
  Returns: (float) The Tilson moving average of the `source`.

tema(source, length)
  Calculates the value of the Triple Exponential Moving Average (TEMA).
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Length for the smoothing parameter calculation.
  Returns: (float) The triple exponentially weighted moving average of the `source`.

tema2(source, length)
  An alternate Triple Exponential Moving Average (TEMA) function to `tema()`, which allows a "series float" `length` argument.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (float): (series int/float) Length for the smoothing parameter calculation.
  Returns: (float) The triple exponentially weighted moving average of the `source`.

trima(source, length)
  Calculates the value of the Triangular Moving Average (TRIMA).
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (int): (series int) Number of bars (length).
  Returns: (float) The triangular moving average of the `source`.

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`.

trix(source, length, signalLength, exponential)
  Calculates the values of the TRIX indicator.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Length for the smoothing parameter calculation.
    signalLength (simple int): (simple int) Length for smoothing the signal line.
    exponential (simple bool): (simple bool) Condition to determine whether exponential or simple smoothing is used. Optional. The default is `true` (exponential smoothing).
  Returns: ([float, float, float]) A tuple of the TRIX value, the signal value, and the histogram.

uo(fastLen, midLen, slowLen)
  Calculates the value of the Ultimate Oscillator.
  Parameters:
    fastLen (simple int): (series int) Number of bars for the fast smoothing average (length).
    midLen (simple int): (series int) Number of bars for the middle smoothing average (length).
    slowLen (simple int): (series int) Number of bars for the slow smoothing average (length).
  Returns: (float) The oscillator value.

vhf(source, length)
  Calculates the value of the Vertical Horizontal Filter.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (simple int): (simple int) Number of bars (length).
  Returns: (float) The oscillator value.

vi(length)
  Calculates the values of the Vortex Indicator.
  Parameters:
    length (simple int): (simple int) Number of bars (length).
  Returns: ([float, float]) A tuple of the viPlus and viMinus values.

vzo(length)
  Calculates the value of the Volume Zone Oscillator.
  Parameters:
    length (simple int): (simple int) Length for the smoothing parameter calculation.
  Returns: (float) The oscillator value.

williamsFractal(period)
  Detects Williams Fractals.
  Parameters:
    period (int): (series int) Number of bars (length).
  Returns: ([bool, bool]) A tuple of an up fractal and down fractal. Variables are true when detected.

wpo(length)
  Calculates the value of the Wave Period Oscillator.
  Parameters:
    length (simple int): (simple int) Length for the smoothing parameter calculation.
  Returns: (float) The oscillator value.


█ v7, Nov. 2, 2023


This version includes the following new and updated functions:

atr2(length)
  An alternate ATR function to the `ta.atr()` built-in, which allows a "series float" `length` argument.
  Parameters:
    length (float): (series int/float) Length for the smoothing parameter calculation.
  Returns: (float) The ATR value.

changePercent(newValue, oldValue)
  Calculates the percentage difference between two distinct values.
  Parameters:
    newValue (float): (series int/float) The current value.
    oldValue (float): (series int/float) The previous value.
  Returns: (float) The percentage change from the `oldValue` to the `newValue`.

donchian(length)
  Calculates the values of a Donchian Channel using `high` and `low` over a given `length`.
  Parameters:
    length (int): (series int) Number of bars (length).
  Returns: ([float, float, float]) A tuple containing the channel high, low, and median, respectively.

highestSince(cond, source)
  Tracks the highest value of a series since the last occurrence of a condition.
  Parameters:
    cond (bool): (series bool) A condition which, when `true`, resets the tracking of the highest `source`.
    source (float): (series int/float) Series of values to process. Optional. The default is `high`.
  Returns: (float) The highest `source` value since the last time the `cond` was `true`.

lowestSince(cond, source)
  Tracks the lowest value of a series since the last occurrence of a condition.
  Parameters:
    cond (bool): (series bool) A condition which, when `true`, resets the tracking of the lowest `source`.
    source (float): (series int/float) Series of values to process. Optional. The default is `low`.
  Returns: (float) The lowest `source` value since the last time the `cond` was `true`.

relativeVolume(length, anchorTimeframe, isCumulative, adjustRealtime)
  Calculates the volume since the last change in the time value from the `anchorTimeframe`, the historical average volume using bars from past periods that have the same relative time offset as the current bar from the start of its period, and the ratio of these volumes. The volume values are cumulative by default, but can be adjusted to non-accumulated with the `isCumulative` parameter.
  Parameters:
    length (simple int): (simple int) The number of periods to use for the historical average calculation.
    anchorTimeframe (simple string): (simple string) The anchor timeframe used in the calculation. Optional. Default is "D".
    isCumulative (simple bool): (simple bool) If `true`, the volume values will be accumulated since the start of the last `anchorTimeframe`. If `false`, values will be used without accumulation. Optional. The default is `true`.
    adjustRealtime (simple bool): (simple bool) If `true`, estimates the cumulative value on unclosed bars based on the data since the last `anchor` condition. Optional. The default is `false`.
  Returns: ([float, float, float]) A tuple of three float values. The first element is the current volume. The second is the average of volumes at equivalent time offsets from past anchors over the specified number of periods. The third is the ratio of the current volume to the historical average volume.

rma2(source, length)
  An alternate RMA function to the `ta.rma()` built-in, which allows a "series float" `length` argument.
  Parameters:
    source (float): (series int/float) Series of values to process.
    length (float): (series int/float) Length for the smoothing parameter calculation.
  Returns: (float) The rolling moving average of the `source`.

supertrend2(factor, atrLength, wicks)
  An alternate SuperTrend function to `supertrend()`, which allows a "series float" `atrLength` argument.
  Parameters:
    factor (float): (series int/float) Multiplier for the ATR value.
    atrLength (float): (series int/float) Length for the ATR smoothing parameter calculation.
    wicks (simple bool): (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.

vStop(source, atrLength, atrFactor)
  Calculates an ATR-based stop value that trails behind the `source`. Can serve as a possible stop-loss guide and trend identifier.
  Parameters:
    source (float): (series int/float) Series of values that the stop trails behind.
    atrLength (simple int): (simple int) Length for the ATR smoothing parameter calculation.
    atrFactor (float): (series int/float) The multiplier of the ATR value. Affects the maximum distance between the stop and the `source` value. A value of 1 means the maximum distance is 100% of the ATR value. Optional. The default is 1.
  Returns: ([float, bool]) A tuple of the volatility stop value and the trend direction as a "bool".

vStop2(source, atrLength, atrFactor)
  An alternate Volatility Stop function to `vStop()`, which allows a "series float" `atrLength` argument.
  Parameters:
    source (float): (series int/float) Series of values that the stop trails behind.
    atrLength (float): (series int/float) Length for the ATR smoothing parameter calculation.
    atrFactor (float): (series int/float) The multiplier of the ATR value. Affects the maximum distance between the stop and the `source` value. A value of 1 means the maximum distance is 100% of the ATR value. Optional. The default is 1.
  Returns: ([float, bool]) A tuple of the volatility stop value and the trend direction as a "bool".


Removed Functions:

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

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

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

เอกสารเผยแพร่:
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.
เอกสารเผยแพร่:
v4

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:


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.
เอกสารเผยแพร่:
v6

We've added a new function to calculate and compare either cumulative or non-cumulative volume within a period and its average at equivalent time offsets over a specified number of periods. This addition utilizes our recently-published RelativeValue library.


relativeVolume(length, anchorTimeframe, isCumulative)
  Calculates the volume since the last change in the time value from the `anchorTimeframe`, the historical average of values at equivalent offsets from previous period anchors, and the ratio of these volumes. The volume values are cumulative by default, but can be set to non-accumulated values with the `isCumulative` parameter.
  Parameters:
    length (simple int): The number of historical periods to use in the average.
    anchorTimeframe (simple string): The anchor timeframe used in the calculation. Optional. Default is "D".
    isCumulative (simple bool): If `true`, the volume values will be accumulated since the start of the last `anchorTimeframe`. If `false`, values will be used without accumulation. Optional. The default is `true`.
  Returns: ([float, float, float]) A tuple of three float values. The first element is the current volume. The second is the average of volumes at equivalent time offsets from past anchors over the specified number of periods. The third is the ratio of the current volume to the historical average volume.
เอกสารเผยแพร่:
v7

This version's release includes the following changes:

 • Enhanced the `relativeVolume()` function.
 • Introduced eight new functions.
 • Updated the `donchian()` function to return a tuple containing all Donchian Channel values.
 • Deprecated the `allTimeHigh()` and `allTimeLow()` functions due to the availability of the more optimal ta.max() and ta.min() built-in functions, which respectively calculate the all-time highest and lowest values of a series.
 • Deprecated the `trima2()` function, as `trima()` now accepts a "series int" `length` argument.
 • Organized the functions in approximate alphabetical order.
 • We've refined the library's code comments and annotations for clarity and readability.

For more details on this version's changes, please see below.



█  ENHANCEMENTS


relativeVolume():
 • Updated to utilize the latest version of the RelativeValue library, integrating the new `averageAtTime()` overload to rectify calculation discrepancies on symbols with irregular session opening times.
 • Introduced an `adjustRealtime` parameter. When activated in cumulative mode, it allows a predictive estimation of the hypothetical closing value for in-progress bars based on accumulated data.



█  NEW FUNCTIONS


We've added the following functions to the library:

 • atr2(): An alternate ATR function to the ta.atr() built-in, which allows a "series float" `length` argument.
 • changePercent(): Calculates the percentage difference between two distinct values.
 • highestSince(): Tracks the highest value of a series since the last occurrence of a condition.
 • lowestSince(): Tracks the lowest value of a series since the last occurrence of a condition.
 • rma2(): An alternate RMA function to the ta.rma() built-in, which allows a "series float" `length` argument.
 • supertrend2(): An alternate SuperTrend function to `supertrend()`, which allows a "series float" `atrLength` argument.
 • vStop(): Calculates a volatility-adjusted stop value based on the ATR, potentially serving as a trailing stop loss or trend detection tool.
 • vStop2(): An alternate Volatility Stop function to `vStop()`, which allows a "series float" `atrLength` argument.


The original release documentation has been edited with complete documentation for the updated, added, and removed functions under the "v7" section.

Get $15 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/
ไลบรารีไพน์

จิตวิญญาณที่แท้จริงของ TradingView ผู้เขียนได้ตีพิมพ์รหัส Pine นี้เป็นไลบรารีโอเพนซอร์ซเพื่อให้โปรแกรมเมอร์คนอื่น ๆ จากชุมชนของเราสามารถนำไปใช้ซ้ำได้ ไชโยให้กับผู้เขียน! คุณสามารถใช้ไลบรารีนี้เป็นการส่วนตัวหรือในสิ่งพิมพ์โอเพนซอร์สอื่น ๆ แต่นำรหัสนี้มาใช้ซ้ำในสิ่งพิมพ์จะถูกควบคุมโดย กฎระเบียบการใช้งาน

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ เงื่อนไขการใช้บริการ

ต้องการใช้ไลบรารีนี้หรือไม่?

คัดลอกข้อความไปยังคลิปบอร์ดแล้ววางลงในสคริปต์ของคุณ