Trend Intensity Index (TII)

Modified on 2010/09/13 15:27 by Eugene — Categorized as: Community Indicators

Trend Intensity Index: Indicator Documentation

Syntax

DataSeries TII( DataSeries ds, int period, int ma_period )

Parameter Description

ds Data series
period The number of bars to use when calculating the indicator
ma_period The length of the moving average to use

Description

TII is the Trend Intensity Index. It measures the strength of a trend by tabulating the deviation of price and its moving average. Specify the number of bars to use when calculating the indicator in the Period parameter, and the length of the moving average to use in the MAPeriod parameter.

Interpretation

TII moves between 0 and 100. A strong uptrend is indicated when TII is above 80. A strong downtrend is indicated when TII is below 20.

Calculation

TII compares the price to its "MAPeriod" moving average, recording the deviation at each bar. If price is above the moving average, a positive deviation is recorded, and if price is below the moving average a negative deviation. The deviation is simply the distance between price and the moving average.

Once the deviations are calculated, TII is calculated as:

( Sum of Positive Dev ) / ( ( Sum of Positive Dev ) + ( Sum of Negative Dev ) ) * 100

Example

The following example illustrates how to build a system on TII crosses above and below its threshold levels:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Indicators;

namespace WealthLab.Strategies { public class TII_Strategy : WealthScript { protected override void Execute() { TII tii = TII.Series( Close,30,60 ); ChartPane tiiPane = CreatePane( 30,true,true ); PlotSeries( tiiPane, tii, Color.Blue, LineStyle.Solid, 2 ); DrawHorzLine( tiiPane, 20.0, Color.Red, LineStyle.Dashed, 1 ); DrawHorzLine( tiiPane, 80.0, Color.Blue, LineStyle.Dashed, 1 ); for(int bar = 60; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if ( bar+1 - p.EntryBar >= 10 ) ExitAtMarket( bar+1, p, "Exit after 10 days" ); } else { // Buy when TII crosses above 80 if( CrossOver( bar, tii, 80.0 ) ) BuyAtMarket( bar + 1, "tiiTurnedUp" );

// Short when TII crosses below 20 if( CrossUnder( bar, tii, 20.0 ) ) ShortAtMarket( bar + 1, "tiiTurnedDown" ); } } } } }