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 Continuation Factor for eSignal (EFS)

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

The Trend Continuation Factor is an indicator built to draw trend state. It is a typical momentum indicator calculated with the rate over change price movement, compound over a summation period.

You will need to save the attached easyArray.efsLib file in the FunctionLibrary folder of the eSignal directory.

All credits to Alexis C. Montenegro

Files

Indicator / Formula

Copy & Paste Friendly
/*********************************************************
Alexis C. Montenegro © October 2005                       
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a 
description of any changes you make.                      
**********************************************************/

var fpArray = new Array();

function preMain(){
    setPriceStudy(false);
    setStudyTitle("Trend Continuation Factor");
    setCursorLabelName("TCF+", 0);
    setCursorLabelName("TCF-", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setLowerLimit(2);		
        setDefault(20);
    }
	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("Params", FunctionParameter.BOOLEAN);
	with(fpArray[x++]){
        setName("Show Parameters");
        setDefault(false);
    }
}

var bInit = false;
var xTCF = null;
var xTCFPos = null;
var xTCFNeg = null;
function main(Length,Source,Symbol,Interval,Params){
    if(bInit == false){
        if(Symbol == null) Symbol = getSymbol();
        if(Interval == null) Interval = getInterval();
        var vSymbol = Symbol+","+Interval;
        xTCF = efsInternal("calcTCF",Length,eval(Source)(sym(vSymbol)));
        xTCFPos = getSeries(xTCF,0);
        xTCFNeg = getSeries(xTCF,1);
        addBand( 0, PS_SOLID, 1, Color.black,"0");
        setShowTitleParameters(eval(Params));
        bInit = true;
    }

    return new Array (xTCFPos,xTCFNeg);
}

var myLib = addLibrary("easyArray.efsLib");//comment out this line if not using the ezArray() function
var pVar = 0;
var nVar = 0;
var pCF = 0;
var nCF = 0;

/* add a / at the beginning of this line if using conventional logic             
var apVar = null;
var anVar = null;
var apCF = null;
var anCF = null;
//*/

function calcTCF(length,source){
  
        /*    ARRAY CREATED AND MAINTAINED USING CONVENTIONAL LOGIC     */
/* add a / at the beginning of this line if using conventional logic             
    if(apVar==null) apVar = new Array (length);
    if(anVar==null) anVar = new Array (length);
    if(apCF==null) apCF = new Array (length);
    if(anCF==null) anCF = new Array (length);

    if(getBarState()==BARSTATE_NEWBAR){
        apVar.pop();
        anVar.pop();
        apCF.pop();
        anCF.pop();
        apVar.unshift(pVar);
        anVar.unshift(nVar);
        apCF.unshift(pCF);
        anCF.unshift(nCF);
    }
    if(apVar[length-1]==null || anVar[length-1]==null || apCF[length-1]==null || anCF[length-1]==null) return;
        //                END CONVENTIONAL ARRAY LOGIC                  */

        /*    ARRAY CREATED AND MAINTAINED USING ezArray() FUNCTION     */
//*  remove a / at the beginning of this line if using conventional logic         
    var apVar = myLib.ezArray(pVar,length,"PosVar");
    var anVar = myLib.ezArray(nVar,length,"NegVar");
    var apCF  = myLib.ezArray(pCF,length,"PosCF");
    var anCF  = myLib.ezArray(nCF,length,"NegCF");
    if(apVar[length-1]==null || anVar[length-1]==null || apCF[length-1]==null || anCF[length-1]==null) return;
        //                    END ezArray() LOGIC                       */

    var Source_0 = source.getValue(0);
    var Source_1 = source.getValue(-1);
    if(Source_0==null || Source_1==null) return;
    
    if(Source_0>Source_1){
        pVar = Source_0-Source_1;
        nVar = 0;
    }else{
        pVar = 0;
        nVar = Source_1-Source_0;
    }
    
    if(pVar == 0){
        pCF = 0;
        nCF = nVar+anCF[1];
    }else{
        pCF = pVar+apCF[1];
        nCF = 0;
    }

// the following lines update the most recent element of the array
// and are required by both the conventional and ezArray() logic  
    apVar[0] = pVar;
    anVar[0] = nVar;
    apCF[0] = pCF;
    anCF[0] = nCF;
// end array update                                               
    
    var sumpVar = 0
    var sumnVar = 0;
    var sumpCF = 0;
    var sumnCF = 0
    
    for (var i=0; i<length; i++){
        sumpVar += apVar[i];
        sumnVar += anVar[i];
        sumpCF += apCF[i];
        sumnCF += anCF[i];
    }
    
    var pTCF = sumpVar-sumnCF;
    var nTCF = sumnVar-sumpCF;

    return new Array (pTCF, nTCF);
}

0 comments

Leave Comment

Please login here to leave a comment.

Back