Technical Indicators and Technical Analysis

Technical Analysis is based on the belief that technical indicators give insight into the
current and future market situation. A technical indicator is a
function that retrieves information from a time series
of prices or trade volumes, and converts them to an output that can be used as a
trade signal for buying or selling at the right moment. For instance, the Simple Moving Average (SMA) indicator
with a Time Period 100 adds the last 100 prices and divides the sum by
100, this way getting the average price of the last 100 bars. If the current price rises above the average, some traders believe that prices will further rise, and take this as a buy signal. It the price falls below the average, they believe that prices will further fall and they must sell.

Price 1

IndicatorFunction

Buy/SellSignal

Price 2

Price 3

...

Price 100

Indicators usually generate buy or sell signals when they reach a threshold, cross each other,
or cross the price curve. About 800 different indicators are meanwhile published in books and trading magazines,
from the very simple to the very bizarre.
The most often used are available in Zorro's indicator function library listed
below. The library contains moving averages, oscillators, bands, momentum, strength indices, linear regression,
and signal processing. It is divided in several sections:

Traditional indicators are mostly based on the TA-Lib indicator library by Mario Fortier (www.ta-lib.org) that has established as a standard. The usage, algorithms, and source codes of TA-Lib indicators can be found online at www.tadoc.org; the source codes are also included in the Zorro/Source folder. The source code of most other indicators and analysis functions can be found in
indicators.c.

If you need an indicator that is is missing, simply add it. Most technical indicators are primitive and can be implemented in a few minutes with a few lines of code. The file indicators.c contains the source codes of many nonstandard indicators, so you can use it as learning material for adding more complex indicators.

AC(vars Data): var

Accelerator Oscillator by Bill Williams; the difference of the AO indicator (see below) and its 5-bar simple moving average (SMA). Believed to indicate acceleration and deceleration of a 'market driving force' (whatever that means). For Data normally a MedPrice or price series is used. Source code in indicators.c.

ADO(): var

Accumulation/Distribution Oscillator: ((Close-Low)-(High-Close))/(High-Low). Ranges from -1 when the close is the low of the bar, to +1 when it's the high. Supposed to gauge supply and demand by determining whether traders are generally "accumulating" (buying) or "distributing" (selling). This indicator was published in many individual variants to the formula, but none of them seems any better than the other. Uses the current asset price series. Source code in indicators.c.

ADX(int TimePeriod): var

Average Directional Movement Index. Moving average of the DX indicator (see below). Uses the current asset price series. Does not support TimeFrame. The returned values range from 0 to 100.

ADXR(int TimePeriod): var

Average Directional Movement Index Rating. The average of the current ADX and the ADX from TimePeriod bars ago. Uses the current asset price series.
Does not support TimeFrame.

Alligator(vars Data): var

Alligator Indicator by Bill Willams. Consist of three lines: blue = SMA(13) delayed by 5 bars; red: SMA(8) delayed by 2 bars; green: SMA(5). Indicates a down trend with lines in the order blue-red-green (top to bottom), and an uptrend with green-red-blue. The closer the Alligator’s lines move, the weaker the trend gets and vice versa. Does not contain the additional 3 bars lag of the original Alligator algorithm (use Data+3 for that). For Data normally the high/low average (MedPrice series) is used. Result in rRed, rGreen, rBlue. Source code in indicators.c.

AO(vars Data): var

Awesome Oscillator by Bill Williams; simply the difference of a 5-bar and a 34-bar SMA. For Data normally a MedPrice or price series is used. Source code in indicators.c.

APO(vars Data, int FastPeriod, int SlowPeriod, int MAType): var

Absolute Price Oscillator; a more general version of the AO. Returns the difference between two moving averages.
Parameters: FastPeriod (Number of period for the fast MA), SlowPeriod (Number of period for the slow MA), MAType (Type of Moving Average).

Aroon(int TimePeriod): var

Aroon indicator. Consists of two lines (Up and Down) that measure how
long it has been since the highest high/lowest low has occurred within
the time period. Uses the current asset price series. Does not support TimeFrame. Result in rAroonDown, rAroonUp.

AroonOsc(int TimePeriod): var

Aroon Oscillator. Calculated by subtracting the Aroon Down from the Aroon Up. The return value will oscillate between +100 and -100. Uses the current asset price series. Does not support TimeFrame.

ATR(int TimePeriod): var

Average True Range. A measure of price volatility; useful for calculating stop loss or profit target distances. Formula: ATR = (ATR1 * (TimePeriod-1) + max(High,Close)-min(Low,Close)) / TimePeriod, where ATR1 is the ATR from the last bar. Uses the current asset prices. The function internally creates series when TimeFrame is > 1, and must then be called in a fixed order in the script. See also: Volatility, CVolatilty, TrueRange, ATRS.

ATR(vars Open, vars High, vars Low, vars Close, int TimePeriod): var

Average True Range from arbitrary price series, with arbitrary offset and time frame.
Use this function when when TimeFrame
is not constant, but changes from bar to bar, f.i. when skipping bars outside
market hours.

ATRS(int TimePeriod): var

Simple Average True Range. SMA of the TrueRange over the TimePeriod, using the current asset price series. A measure of price volatility, simpler to calculate than the ATR, but adapting slow to volatility changes and thus less suited for stop loss / profit targets. Used by the MTR4 platform instead of the real ATR. Does not support TimeFrame. Source code in indicators.c.

AvgPrice(): var

Average Price. Simply (Open+High+Low+Close)/4 with the current asset price series.

Bollinger Bands. Consist of three lines; the middle band is a moving average (usually
a 20 periods SMA) of the
Data series. The
upper and lower bands are n standard deviations (usually 2) above and below the middle band. The bands widen and narrow when the volatility of the
Data series is higher or lower, respectively. They collapse to
a line when the standard deviation is less than 0.0001. Result in rRealUpperBand, rRealMiddleBand, rRealLowerBand. Parameters: NbDevUp (Deviation multiplier for upper band), NbDevDn (Deviation multiplier for lower band), MAType (Type of Moving Average). Example in Indicatortest.c.

BBOsc(vars Data, int TimePeriod, var NbDev, int MAType): var

Bollinger Bands Oscillator; the percentage of the current value of the series within the Bollinger Bands.

Beta(vars Data, vars Data2, int TimePeriod): var

Beta value. A measure of a single asset's prices versus the overall market index. The asset price is given in Data and the market index price (f.i. S&P 500, DAX, etc) is given in Data2. The algorithm calculates the change between prices in both series and then stores these changes as 2-dimensional points. The x value of any point is the Data2 (market) change and the y value is the Data (asset) change. The beta value is the slope of a linear regression line through these points. A beta of 1 is simple the line y=x, so the asset varies percisely with the market. A beta of less than one means the asset varies less than the market and a beta of more than one means the asset varies more than the market.

BOP(): var

CCI(int TimePeriod): var

Commodity Channel Index. Variation of the price from its statistical mean, typically oscillates between +/-100. Uses the current asset price series. Does not support TimeFrame.

CI(int TimePeriod): var

Choppiness Index; measures single bar price volatility in relation to the volatility of the past TimePeriod in a 1..100 range. Uses the current asset price series. Does not support TimeFrame.

ChandelierLong(int TimePeriod, var Multiplier): var

ChandelierShort(int TimePeriod, var Multiplier): var

Chandelier exit; the highest price of TimePeriod minus the ATR multiplied with Multiplier. Normally used as a trailing Stop Loss, for keeping trades in a trend and preventing an early exit as long as the trend continues. Source code in indicators.c. Does not support TimeFrame. Example in the TMF chapter.

CGOsc(vars Data, int TimePeriod): var

Center of Gravity oscillator, by John Ehlers; computes the deviation of prices from their center within the TimePeriod. Can be used to identify price turning points with almost zero lag. Source code in indicators.c.

Chikou(int Shift): var

Chikou line belonging to the Ichimoku indicator; simply
a delayed Close moved forward by Shift. Uses the current asset price series. Source code in indicators.c.
The traditional Ichimoku requires a future peeking Chikou line (Shift =
-26); this can be achieved by setting Shift = 0 and
moving the rest of the Ichimoku forward by Offset = 26.

CMO(vars Data, int TimePeriod): var

Chande Momentum Oscillator. Similar to the RSI, but divides the total data movement by the net movement ((up - down) / (up + down)).

Coral(vars Data): var

Indicator by Larry Connors, mean of a 3 period RSI
on Data, a 2 period RSI of the recent up/down streak, and the
percent rank of the recent change.
Fluctuates between 0 and 100 and believed to indicate the overbought (high
values) or oversold (low values) level. The function internally creates series and thus must be called in a fixed order in the script. Source code in indicators.c.

DChannel(int TimePeriod)

Donchian Channel; the minimum and maximum value of the priceHigh and priceLow functions over the time period. Basis of the famous Turtle Trading System. Uses the current asset price series. Does not support TimeFrame. Result in rRealUpperBand, rRealLowerBand.

DCOsc(vars Data, int TimePeriod): var

Donchian Channel Oscillator; the percentage of the current Data value within the Donchian Channel. Uses the current asset and current TimeFrame.

Decycle(vars Data, int CutOffPeriod): var

Ehlers' Decycler, a low-lag trend indicator; simply Data - HighPass2(Data,CutOffPeriod). Removes all cycles below CutOffPeriod from the Data series and keeps the trend.
The function internally creates series and thus must be called in a fixed order in the script. Source code in indicators.c.

DEMA(vars Data, int TimePeriod): var

Double Exponential Moving Average.

DPO(vars Data, int TimePeriod): var

DX(int TimePeriod): var

Directional Movement Index by Welles Wilder. Wilder discovered that "the interaction of sun, moon, and earth is the basis of all market movement".
But just in case that celestial bodies suddenly refrain from moving the market, he also invented
the DX, which he believed to indicate trend strength. The values range from 0 to 100, but rarely get above 60. The DX uses the current asset price series and does not support TimeFrame. Formula: DX = 100 * abs(PlusDI-MinusDI) / (PlusDI+MinusDI). For PlusDI and MinusDI see the description below.

EMA(vars Data, int TimePeriod): var

EMA(vars Data, var alpha): var

Exponential Moving Average. Emphasizes more recent data values. It uses the formula
EMA = alpha * data + (1-alpha) * EMA1,
where alpha is a recursion factor between 0 .. 1 that is calculated from 2.0/(TimePeriod+1), and EMA1 is the previous EMA value. The smaller alpha is, the higher is the smoothing effect of the EMA formula. Both EMA functions use slightly different algorithms. The first (using a TimePeriod) does not create a series, is slower, and requires a Data length of TimePeriod+UnstablePeriod+1. The second (using alpha) creates an internal series, needs only a Data length of 2 and is much faster.

ER(vars Data, int TimePeriod): var

Kaufman's Efficiency Ratio, the amount of price changes in the given interval in
relation to the absolute price change. Source code in indicators.c.

FractalHigh(vars Data, int TimePeriod): var

Fractal High, an indicator by Bill Williams, believed to signal when the market reverses (has nothing to do with fractals). Returns the highest Data value when it is in the center of the TimePeriod, otherwise 0.

FractalLow(vars Data, int TimePeriod): var

Fractal Low. Returns the lowest Data value when it is in the center of the TimePeriod, otherwise 0.

HAOpen(): var

HAClose(): var

HAHigh(): var

HALow(): var

Haiken Ashi prices, based on the current asset prices. Source code in indicators.c. Alternatively, the price curve can be converted to Haiken Ashi bars using the bar function.

HH(int TimePeriod, int Offset): var

Highest value of the priceHigh function over the TimePeriod ending with Offset (default 0). F.i. HH(3,1) returns the highest price of
the 3 bars before the current bar. Uses the current asset price series. Sets
rHHBar to the absolute bar number with the highest price. Does not support TimeFrame; for multiple time frames, use
a data series and MaxVal(Data+Offset,Period) instead. See also dayHigh.

HMA(vars Data, int TimePeriod): var

Hull Moving Average by Alan Hull; attempts to address lag as well as to smooth out some choppiness. Formula:HMA(n) = WMA(2*WMA(n/2) – WMA(n)),sqrt(n)). The function internally creates a series and thus must be called in a fixed order in the script. Source code in indicators.c.

IBS(): var

Internal Bar Strength; relative position in percent of the close price with
respect to the low to high range for the same period. Source code in indicators.c.

Ichimoku()

Ichimoku Kinko Hyo indicator. Invented by the journalist Goichi Hosoda in the 1930s, and today again in fashion due to its enormous number of colorful lines. The Ichimoku is a mix of the medium prices of 3 time periods. Offset (default 0) determines the bar for calculating the indicator,
and can be used to shift all lines forward. The function returns 4 variables:

Another line belonging to the Ichimoku, the Chikou line, is future peeking and calculated separately. The function uses the current asset price series.
It internally creates series when TimeFrame is > 1, and must then be called in a fixed order in the script. Source code in indicators.c.

IBS(): var

KAMA(vars Data, int TimePeriod): var

Kaufman Adaptive Moving Average. An exponential moving average adjusted by price volatility, so its time period becomes shorter when volatility is high.

KAMA2(vars Data, int ERPeriod, int FastPeriod, int SlowPeriod): var

Kaufman Adaptive Moving Average as above, but the volatilty detection period as
well as the short and long time period can be set separately. Internally creates series
and must be called in a fixed order in the script. Source code in
indicators.c.

Keltner(vars Data, int TimePeriod, var Factor): var

Keltner Channel, by Charles Keltner. A Simple Moving Average - SMA(Data,TimePeriod) - with side bands in the distance Factor * ATRS(TimePeriod). Results in rRealUpperBand, rRealMiddleBand, rRealLowerBand. Source code in indicators.c.

LL(int TimePeriod, int Offset): var

Lowest value of the priceLow function over the TimePeriod ending with Offset (default 0). F.i. LL(3,10) returns the lowest price between the last 10 and the last 13 bars. Uses the current asset price series.
Sets rLLBar to the absolute bar number with the lowest price. Does not support TimeFrame; for multiple time frames, use
a data series and MinVal(Data+Offset,Period) instead. See also dayLow.

MACD(vars Data, int FastPeriod, int SlowPeriod, int SignalPeriod)

Moving Average Convergence/Divergence. The MACD is an intermediate-term trend indicator, created by subtracting a 26-period Exponential Moving Average (EMA, see above) from a 12-period EMA. A nine-period EMA is then applied to the MACD result to create a 'signal line'. A MACD Histogram line is finally created from the difference of the MACD to its signal line. It is believed that the zero crossing of the histogram from below is a buy signal, zero crossing from above a sell signal. The formula is:

Results in rMACD, rMACDSignal, rMACDHist.
Returns: rMACD. Parameters: FastPeriod (time period for the fast MA), SlowPeriod (time period for the slow MA), SignalPeriod (time period for smoothing the signal line).

MACD with controllable MA type.
Result in rMACD, rMACDSignal, rMACDHist.
Parameters: FastPeriod (time period for the fast MA), FastMAType (Type of Moving Average for fast MA), SlowPeriod (time period for the slow MA), SlowMAType (Type of Moving Average for slow MA), SignalPeriod (time period for smoothing the signal line), SignalMAType (Type of Moving Average for signal line).

MACDFix(vars Data, int SignalPeriod)

Moving Average Convergence/Divergence Fix 12/26.
Result in rMACD, rMACDSignal, rMACDHist.
Parameters: SignalPeriod (time period for smoothing the signal line).

MAMA(vars Data, var FastLimit, var SlowLimit)

MESA Adaptive Moving Average, developed by John Ehlers (see links).
Result in rMAMA, rFAMA.
Parameters: FastLimit (Upper limit use in the adaptive algorithm), SlowLimit (Lower limit use in the adaptive algorithm).

MedPrice(): var

Center price; simply the center point (High+Low)/2 of the current candle. For the mean price - the average of all price ticks of the candle - use price(). For the middle price between Ask and Bid, take the ask price and add Spread/2.

MidPoint(vars Data, int TimePeriod): var

MidPoint over period. Simply (highest value + lowest value)/2.

MidPrice(int TimePeriod): var

Midpoint price over period. Simply (highest high + lowest low)/2 of the current asset price series. Does not support TimeFrame.

MinusDM(int TimePeriod): var

Minus Directional Movement, two versions. If the function is not called with different price series, the current asset price series is used.

MMI(vars Data, int TimePeriod): var

Market Meanness Index by Financial Hacker. Measures the meanness of the market, i.e. its mean reversal tendency, in a 0..100% range. Random numbers have a MMI of 75%. Real prices are more or less autocorrelated, so the probability of a real price series to revert to the mean is less than 75%, but normally more than 50%. The higher it is, the 'meaner' is the market to trend following systems.
The Market Meanness Index can determine when trend following systems will become more profitable (MMI is falling) or less profitable (MMI is rising), and thus prevent losses in unprofitable periods. Source code in indicators.c.

MovingAverage(vars Data, int TimePeriod, int MAType): var

Moving average with variable period given by the Periods series. Parameters: MinPeriod (Value less than minimum will be changed to Minimum period), MaxPeriod (Value higher than maximum will be changed to Maximum period), MAType (Type of Moving Average, see remarks).

NATR(int TimePeriod): var

Normalized Average True Range, by John Forman. Similar to the ATR, except it is being normalized as follows: NATR = 100 * ATR(TimePeriod) / Close. Uses the current asset price series.
Does not support TimeFrame.

NumWhiteBlack(var Body, int Offset, int TimePeriod): var

Number of white minus number of black candles in the given TimePeriod. Offset is the distance to the current bar (0 = current bar), Body is the minimum length of a candle to be counted. Source available in indicators.c.

PlusDM(int TimePeriod): var

Plus Directional Movement, two versions. In the first version the current asset price series is used.

PPO(vars Data, int FastPeriod, int SlowPeriod, int MAType): var

Percentage Price Oscillator. Parameters: FastPeriod (Number of period for the fast MA), SlowPeriod (Number of period for the slow MA), MAType (Type of Moving Average).

ProfitFactor(vars Data, int Length): var

Returns the profit factor of the Data series. The profit factor is the ratio of the sum of positive returns (i.e. Data[i-1] > Data[i]) to the sum of negative returns (i.e. Data[i-1] < Data[i]).
The returned value is clipped to the 0.1...10 range. Use its reciprocal when the Data array is in not in series order, but in ascending order, as wins and losses are then swapped. Source available in indicators.c.

ROCP(vars Data, int TimePeriod): var

ROCR(vars Data, int TimePeriod): var

ROCL(vars Data, int TimePeriod): var

Logarithmic return: log(price/prevPrice).

ROCR100(vars Data, int TimePeriod): var

Rate of change ratio, 100 scale: (price/prevPrice)*100.

Roof(vars Data, int CutoffLow, int CutoffHigh): var

Ehlers' roofing filter, prepares the Data series for further computation by removing trend and noise. Applies a 2-pole highpass filter followed by the Smooth filter. Recommended values for the low and high cutoff periods are 10 and 50. The minimum length of the Data series is 2. The function internally creates series and thus must be called in a fixed order in the script. Source available in indicators.c.

RSI(vars Data, int TimePeriod): var

Relative Strength Index, by Welles Wilder. Ratio of the recent upwards data movement to the total data movement; range 0..100. The RSI is believed to indicate overbought/oversold conditions when the value is over 70/below 30. Formula: RSI = 100 * Up/(Up+Dn), where Up = EMA(max(0,Data[0]-Data[1]),TimePeriod) and Dn = EMA(max(0,Data[1]-Data[0]),TimePeriod).

RSIS(vars Data, int TimePeriod): var

Relative Strength Index variant, using the simple average of
the Up/Dn sums instead of an EMA. This RSI variant is used by several trading
platforms instead of the original version.

RVI(int TimePeriod): var

Relative Vigor Index, by John Ehlers. Ratio of price change to the total price range: (C-O)/(H-L), averaged over the time period and smoothed with a FIR filter. Oscillates between -1 and 1. The function internally creates a series and thus must be called in a fixed order in the script. Source code in indicators.c.

SAR(var Step, var Min, var Max): var

Parabolic SAR by Welles Wilder. The SAR runs above or below the price curve, depending on the current trend; each price curve crossing is believed to indicate a trend change. Parameters: Step (acceleration factor increment, normally 0.02), Min (acceleration factor minimum value, normally 0.02), Max (acceleration factor maximum value, normally 0.2). SAR is a recursive function that depends on the direction of the initial price candle; for consistent values the LookBack period should be long enough to contain at least one price curve crossing. Uses the current asset prices. The function internally creates a series and thus must be called in a fixed order in the script. Source code in indicators.c, example in Indicatortest.c.

SentimentLW(int TimePeriod): var

Market Sentiment Index by Larry Williams, based on the averaged differences of
day closes to day highs/lows. Returns a 0..100 percentage. Williams believed
that a high index indicates a bullish market saturation and predicts sells,
while a low index indicates no bullishness and predicts buys. Uses the current asset prices. The function internally creates a series and thus must be called in a fixed order in the script. Source code in indicators.c.

SentimentG(int TimePeriod): var

Genesis Sentiment Index, the current price in relation to the given
TimePeriod, usually 6 months. Returns a 0..100 percentage; believed to
indicate a bullish market with a high index and bearishness with a low index. Uses the current asset prices. The function internally creates a series and thus must be called in a fixed order in the script. Source code in indicators.c.

SIROC(vars Data, int TimePeriod, int EMAPeriod): var

Smoothed Rate of Change (S-RoC) by Fred G Schutzman. Differs from the ROC (see above) in that it is based on the exponential moving average (EMA) of the Data series. Believed to indicate the strength of a trend by determining if the trend is accelerating or decelerating. Formula: (Current EMA - Previous EMA)/(Previous EMA) x 100.
Source code in indicators.c.

SMA(vars Data, int TimePeriod): var

Simple Moving Average; the mean of the data, i.e. the sum divided by the time period.
Use Moment when long time periods are required.

Smooth(vars Data, int CutoffPeriod): var

Ehlers' super-smoothing filter, a 2-pole Butterworth filter combined with a SMA that suppresses the Nyquist frequency. Can be used as a low-lag universal filter for removing noise from price data. The minimum length of the Data series is 2. The function internally creates series and thus must be called in a fixed order in the script. Source available in indicators.c.

SMom(vars Data, int TimePeriod, int CutoffPeriod): var

Smoothed Momentum by John Ehlers; indicates the long term trend direction. TimePeriod is the momentum period, CutoffPeriod is a Butterworth filter constant for lowpass filtering the momentum. Source code in indicators.c.

Stochastic Oscillator (unrelated to stochastics, but its inventor, George Lane, looked for a fancy name). Measures where the Close price is in relation to the recent trading range. Formula: FastK = 100 * (Close-LL)/(HH-LL); SlowK = MA(FastK); SlowD = MA(SlowK). Some traders believe that the SlowK crossing above SlowD is a buy signal; others believe they should buy when SlowD is below 20 and sell when it is above 80. Two versions; the first version uses the current asset price series and does not support TimeFrame. Result in rSlowK, rSlowD. Parameters:
FastK_Period - Time period for the HH and LL to generate the FastK value, usually 14.SlowK_Period - Time period for smoothing FastK to generate rSlowK; usually 3.SlowK_MAType - Type of Moving Average for Slow-K, usually MAType_EMA.SlowD_Period - Time period for smoothing rSlowK to generate rSlowD, usually 3.SlowD_MAType - Type of Moving Average for Slow-D, usually MAType_EMA.

Predictive stochastic oscillator by John Ehlers. Measures where the Data value is in relation to its range within TimePeriod. The data runs through a 2-pole highpass filter with period CutOffHigh and through a Butterworth lowpass filter with period CutOffLow. Indicator algorithm explained in Ehler's "Predictive Indicators" paper; usage example in the Ehlers script. Source code in indicators.c. The function internally creates series and thus must be called in a fixed order in the script.

StochF(int FastK_Period, int FastD_Period, int FastD_MAType): var

Stochastic Fast. Measures where the Close price is in relation to the recent trading range; Formula: Fast-K = 100 * (Close-LL)/(HH-LL); Fast-D = MA(Fast-K). Uses the current asset price series, and does not support TimeFrame. Result in rFastK, rFastD. Returns: FastK. Parameters:
FastK_Period (Time period for the HH and LL of Fast-K, usually 14),
FastD_Period (Moving Average Period for Fast-D; usually 3),
FastD_MAType (Type of Moving Average for Fast-D, usually MAType_EMA).

Stochastic Relative Strength Index (RSI). Result in rFastK, rFastD. Returns: FastK. Parameters:
FastK_Period (Time period for building the Fast-K line),
FastD_Period (Smoothing for making the Fast-D line. Usually set to 3),
FastD_MAType (Type of Moving Average for Fast-D).

T3(vars Data, int TimePeriod, var VFactor): var

TEMA(vars Data, int TimePeriod): var

Triple Exponential Moving Average by Patrick Mulloy, calculated from (3xEMA)-(3xEMA of EMA)+(EMA of EMA of EMA).

Trima(vars Data, int TimePeriod): var

Triangular Moving Average (also known under the name TMA); a form of Weighted Moving Average where the weights are assigned in a triangular pattern. F.i. the weights for a 7 period Triangular Moving Average would be 1, 2, 3, 4, 3, 2, 1. This gives more weight to the middle of the time series. It causes better smoothing, but greater lag.

Trix(vars Data, int TimePeriod): var

1-day Rate-Of-Change (see ROC) of a Triple EMA (see TEMA).

TrueRange(): var

True Range (TR); max(High[0],Close[1])-min(Low[0],Close[1]) of the current asset price series. See also ATR, ATRS.

TSI(vars Data, int TimePeriod): var

Trend Strength Index, an indicator by Frank Hassler who believed that it identifies trend strength. A high TSI value (above ~ 1.65) indicates that short-term trend continuation is more likely than short-term trend reversal.
The function internally creates series and thus must be called in a fixed order in the script.

TypPrice(): var

UltOsc(int TimePeriod1, int TimePeriod2, int TimePeriod3): var

Ultimate Oscillator. Parameters: TimePeriod1 (Number of bars for 1st period.), TimePeriod2 (Number of bars for 2nd period), TimePeriod3 (Number of bars for 3rd period). Uses the current asset price series.
Does not support TimeFrame.

UO(vars Data, int CutOff): var

Universal oscillator by John Ehlers, from S&C Magazine 1/2015. Removes white noise from the data, smoothes it and runs it through the AGC filter. Detects trend reversals very early. Output in the -1..+1 range. Source code in indicators.c. The function internally creates series and thus must be called in a fixed order in the script.

Volatility(vars Data, int TimePeriod): var

Annualized volatility of the Data series; standard deviation of the logarithmic returns, multiplied with the square root of time frames in a year.
This is the standard measure of volatility used in financial models, such as the
Black-Scholes model. For normalizing the volatilty, daily gaps in the historical Data series must be compensated by multiplying the result with the square root of trading bars per day divided by bar periods per day (example: with 60 minute bars and 8 trading bars per day, multiply with sqrt(8./24) = 0.58). The function internally creates series and thus must be called in a fixed order in the script. Source code in indicators.c.
A practical alternative for options calculations is VolatilityOV.

VolatilityC(int TimePeriod, int EMAPeriod): var

Chaikin Volatility indicator by Marc Chaikin; measures volatility in percent as momentum of the smoothed difference between High and Low. An increase in the Chaikin Volatility indicates that a bottom is approaching, a decrease indicates that a top is approaching. TimePeriod is the period of the momentum (normally 10), EMAPeriod determines the smoothing (also, normally 10). Uses the current asset price series. The function internally creates series and thus must be called in a fixed order in the script. Source code in indicators.c.

VolatilityMM(vars Data, int TimePeriod, int EMAPeriod): var

Min/Max volatility of the Data series; the difference of MaxVal and MinVal in the time period, smoothed by an EMA (set EMAPeriod = 0 for no smoothing). The function internally creates a series when EMAPeriod > 0, and then must be called in a fixed order in the script. Source available in indicators.c. For the volatility of price candles, use ATR or ATRS.

VolatilityOV(int Days): var

Annualized volatility of the current asset, calculated over the given number of Days (usually 20) regardless of the bar period. Empirical formula used by options software packages (OptionsVue™) for estimating the values of options, alternatively to Volatility(). Source code in contract.c, which must be included for using this indicator.

WCLPrice(): var

Weighted Close Price. Uses the current asset price series.

WillR(int TimePeriod): var

Williams' Percent Range. Formula: -100* (HH-Close)/(HH-LL). Uses the current asset price series. Does not support TimeFrame.

WMA(vars Data, int TimePeriod): var

Linear Weighted Moving Average; the weight of every bar decreases linearly with its age.

ZigZag(vars Data, var Depth, int Length, int Color): var

ZigZag indicator; converts the Data series into alternating straight trend lines with at least the given Depth and Length. Non-predictive; can only identify trends in hindsight. Returned: rSlope (the slope of the last identified trend line; upwards trends have a positive slope, downwards trends a negative slope); rPeak (the bar offset of the last identified peak); rSign (1 if the last peak was a top, -1 if the last peak was a bottom); rLength (the number of bars of the last trend line ending with rPeak). If a nonzero Color is given, the trend lines are plotted in the chart.
Source code in indicators.c, example in Indicatortest.c. The function internally creates series and thus must be called in a fixed order in the script.

ZMA(vars Data, int TimePeriod): var

Zero-lag Moving Average by John Ehlers; smoothes the Data series with an Exponential Moving Average (EMA) and applies an error correction term for compensating the lag. The function internally creates a series and thus must be called in a fixed order in the script. Source in indicators.c.

Standard parameters:

TimePeriod

The number of bars for the time period of the function, if any; or 0 for using a default period.

MAType

The type of the moving average used by the function: MAType_SMA (default), MAType_EMA, MAType_WMA, MAType_DEMA, MAType_TEMA, MAType_TRIMA, MAType_KAMA, MAType_MAMA, MAType_T3.

Data

A data series in descending order (newest data first), f.i. derived from the price functions price(), priceClose() etc.. Alternatively a user created series or any other double float array with the given minimum length. If not mentioned otherwise, the minimum length of the Data series is TimePeriod. Some functions require a second data series Data2.

Open, High,
Low, Close

Price data series can be explicitly given for some indicators, for using price series generated from a different asset or with a different TimeFrame. Otherwise the prices of the current asset with a time frame equivalent to the bar period are used.

Returns:

Price variation or percentage, dependent on the function, for the current bar.

Usage example:

MACD(Price,12,26,9) calculates the standard MACD for the given Price series.
The results are stored in the global variables rMACD, rMACDSignal, and rMACDHistory.

Remarks:

The TA-Lib function prototypes are defined in include\functions.h. Information about the usage and the indicator algorithms can be found online at www.tadoc.org. The C++ source code of all included TA-Lib indicators is contained in Source\ta_lib.zip and can be studied for examining the algorithms. Some TA-Lib indicators that originally didn't work properly - such as Correlation or SAR - have been replaced by working versions. The lite-C source code of most additional indicators that are not part the the TA-Lib is contained in Source\indicators.c.

All TA functions are applied on series and do normally not accept other data arrays. In the INITRUN, all TA functions return 0, and LookBack is automatically increased to the largest required lookback time by a TA function.

Recursive TA functions - f.i. EMA or ATR - need a higher lookback period than their TimePeriod parameter (see UnstablePeriod). LookBack can be exceeded when TA functions are later called with a series offset or a different TimePeriod; this will generate an Error 046 message. Make sure that LookBack is always higher than the maximum TimePeriod plus the UnstablePeriod plus the highest possible offset of all used series.

Some functions return more than one value, f.i. MACD. The returned results are stored in global variables beginning with "r"; they can be accessed after the function is called.

Some functions only require a single Data value. Rather than creating a Data series of length 1, simply a pointer to the Data value can be used. Example: var Raw = MyIndicator(); var Transformed = AGC(&Raw,0); .

TimeFrame affects subsequent data series and thus also affects all indicators that use the data series as input. The TimePeriod is then not in Bar units, but in time frame units. TimeFrame has no effect on indicators that do not use data series.

Indicators that rely on the standard deviation (f.i. Bollinger Bands) become inaccurate when the standard deviation is below 0.0001, as it is then assumed to be zero by the TA-Lib. This can happen on very short bar periods when the price does (almost) not move.

For writing your own indicators, have a look at the examples inside indicators.c. But please do not modify indicators.c - write the indicators in your own script, or in a dedicated script that you can then include in your strategies. If you need a complex indicator that you can not be easily add, please ask for it on the Zorro user forum.