Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Trend Detection Index for eSignal (EFS)

Rating:
0 / 5 (Votes 0)
Tags:
eSignal

The trend detection index (TDI) is used to detect when a trend has begun and when it has come to an end. The TDI can be used as a stand-alone indicator or combined with others; it will perform well in detecting the beginning of trends.

Indicator / Formula

Copy & Paste Friendly
/***********************************************************
Description	: This Indicator plots the Trend Detection Index
Provided By	: TS Support, LLC for eSignal                   
Modified by : Alexis C. Montenegro 08/04/2006               
              - converted to efs2 syntax                    
              - added multiple time frame/symbol capability 
              - added moving average                        
 ***********************************************************/

var fpArray = new Array();

function preMain(){
	setStudyTitle("Trend Detection Index");
	setCursorLabelName("TDI",0);
	setCursorLabelName("MAofTDI",1);
	setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
	var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setLowerLimit(1);		
        setDefault(12);
    }
	fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
	with(fpArray[x++]){
        addOption("open"); 
        addOption("high");
        addOption("low");
        addOption("close");
        addOption("hl2");
        addOption("hlc3");
        addOption("ohlc4"); 
        setDefault("close"); 
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
        setDefault();
	}
	fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
	with(fpArray[x++]){
        setDefault();
    }
    fpArray[x] = new FunctionParameter("MAType", FunctionParameter.STRING);
    with(fpArray[x++]){
        addOption("sma");
        addOption("ema");
        addOption("wma");
        setDefault("sma");
    }
	fpArray[x] = new FunctionParameter("MALength", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setLowerLimit(1);		
        setDefault(3);
    }
    fpArray[x] = new FunctionParameter("LineColor1", FunctionParameter.COLOR);
	with(fpArray[x++]){
        setName("Color1");
        setDefault(Color.blue);
    }
	fpArray[x] = new FunctionParameter("LineColor2", FunctionParameter.COLOR);
	with(fpArray[x++]){
        setName("Color2");
        setDefault(Color.red);
    }
	fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
	with(fpArray[x++]){
        setName("Show Parameters");
        setDefault(false);
    }
}

var bInit = false;
var xTDI  = null;
var xMATDI = null;

function main(Length,Source,Symbol,Interval,MAType,MALength,LineColor1,LineColor2,Params){
    if(bInit==false){
        if(Symbol == null) Symbol = getSymbol();
        if(Interval == null) Interval = getInterval();
        var vSymbol = Symbol+","+Interval;
        xTDI = getSeries(efsInternal("calcTDI", Length,eval(Source)(vSymbol)));
        xMATDI = getSeries(eval(MAType)(MALength,xTDI));
        setDefaultBarFgColor(LineColor1,0);
        setDefaultBarFgColor(LineColor2,1);
        addBand(0,PS_SOLID,1,Color.lightgrey,"0");
        setShowTitleParameters(eval(Params));
        bInit = true;
    }
    return new Array (xTDI, xMATDI);
}

xMOM = null;

function calcTDI(period, source){
	if (xMOM == null) xMOM = mom(period,source);
	var MomSum     = 0;
    var MomSumAbs  = 0; 
    var MomAbsSum  = 0;
    var MomAbsSum2 = 0;
    for (var i=0; i<period-1; i++){
        MomSum += xMOM.getValue(-i);
    }
	MomSumAbs = Math.abs(MomSum);
	for (var i=0; i<period-1; i++){
        MomAbsSum += Math.abs(xMOM.getValue(-i));
    }
	for (var i=0; i<period*2-1; i++){
        MomAbsSum2 += Math.abs(xMOM.getValue(-i));
    }
	var ret = MomSumAbs - (MomAbsSum2 - MomAbsSum);	
	return ret;
}

0 comments

Leave Comment

Please login here to leave a comment.

Back