2002 Jan: The True Strength Index (Blau_TSI.efs)

ICE Data Services -

Blau_TSI.efs  

EFSLibrary - Discussion Board  

File Name: Blau_TSI.efs

Description:
This study is based on The True Stength Index by Thom Hartle, which appeared in the January 2002 issue of Active Trader Magazine.

Formula Parameters:

  • nR: 25 (First EMA period length)
  • nS: 13 (EMA period length of nR)

Notes:
The TSI Method outlined in the article was designed by William Blau. The related article is copyrighted material. If you are not a subscriber of Active Trader Magazine, please visit www. activetradermag.com.

Download File:
Blau_TSI.efs


EFS Code:

/*****************************************************************
Provided By : eSignal (c) Copyright 2004

Description:  The True Strength Index (TSI) by William Blau

Notes:
    Based on article from January 2002 issue of Active Trader Magazine.
    The True Strength Index by Thom Hartle
*****************************************************************/


function preMain() {
    setPriceStudy(false);
    setStudyTitle("Blau TSI");
    setCursorLabelName("TSI", 0);
    setCursorLabelName("Signal", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    
    addBand(0, PS_SOLID, 1, Color.black, "zero");
}

var aTSI = new Array(7);
var nTSI = 0;

function main(nR, nS) {
    if (nR == null) nR = 25;
    if (nS == null) nS = 13;

    if (getBarState() == BARSTATE_NEWBAR && nTSI != 0 && nTSI != null) {
        aTSI.pop();
        aTSI.unshift(nTSI);
    }    

    var nSignal = 0;
    
    nTSI = TSI(nR, nS);
    if (nTSI == null) return;

    if (aTSI[6] != null) {
        vEMA[4] = EMA(7, aTSI, 4, nTSI);
        nSignal = vEMA[4];
    }
    
    return new Array(nTSI*100, nSignal*100);
}

function TSI(nR, nS) {
    if (close(-1) == null) return;

    nTSI = 0;

    var nMtm = close(0) - close(-1);
    var nEMAofMtm1 = DXAverage("Value1", nMtm, nR, nS);
    if (nEMAofMtm1 == null) return;
    var nEMAofMtm2 = DXAverage("Value2", Math.abs(nMtm), nR, nS);
    if (nEMAofMtm2 == null) return;

    if (nEMAofMtm2 != 0) {
        nTSI = nEMAofMtm1 / nEMAofMtm2;
    }

    return nTSI;
}

//Double EMA
var aSource1 = null; // r   nMtm
var aSource2 = null; // s   Source1
var aSource3 = null; // r   |nMtm|
var aSource4 = null; // s   Source3

function DXAverage(sSource, nValue, nMA1Length, nMA2Length) {
    if (sSource == null || nValue == null || nMA1Length == null || nMA2Length == null) return;
    
    var nDXAverage = null;
    var nState = getBarState();

    if (aSource1 == null) aSource1 = new Array(nMA1Length);
    if (aSource2 == null) aSource2 = new Array(nMA2Length);
    if (aSource3 == null) aSource3 = new Array(nMA1Length);
    if (aSource4 == null) aSource4 = new Array(nMA2Length);
    
    if (nState == BARSTATE_NEWBAR) {
        if (sSource == "Value1") {
            if (nValue != null) {
                aSource1.pop();
                aSource1.unshift(nValue);
            }
            if (vEMA[0] != null) {
                aSource2.pop();
                aSource2.unshift(vEMA[0]);
            }
        }
        if (sSource == "Value2") {
            if (nValue != null) {
                aSource3.pop();
                aSource3.unshift(nValue);
            }
            if (vEMA[2] != null) {
                aSource4.pop();
                aSource4.unshift(vEMA[2]);
            }
        }
    }
    
    // EMA(nLength, nArray, nNum, nIndicator); 
    
    if (sSource == "Value1") {
        // EMA of aSource1 r
        if (aSource1[nMA1Length-1] == null) return;
        vEMA[0] = EMA(nMA1Length, aSource1, 0, nValue);
        aSource2[0] = vEMA[0];
        
        // EMA of aSource2 s
        if (aSource2[nMA2Length-1] == null) return;
        vEMA[1] = EMA(nMA2Length, aSource2, 1, vEMA[0]);
        nDXAverage = vEMA[1];
        
    }
    if (sSource =="Value2") {
        // EMA of aSource4 r
        if (aSource3[nMA1Length-1] == null) return;
        vEMA[2] = EMA(nMA1Length, aSource3, 2, nValue);
        aSource4[0] = vEMA[2];
        
        // EMA of aSource5 s
        if (aSource4[nMA2Length-1] == null) return;
        vEMA[3] = EMA(nMA2Length, aSource4, 3, vEMA[2]);
        nDXAverage = vEMA[3];
    }


    return nDXAverage;
}

var bPrimed = new Array(5);
bPrimed[0] = false;  // r   Mtm
bPrimed[1] = false;  // s   Source1
bPrimed[2] = false;  // u   |Mtm|
bPrimed[3] = false;  // r   Source3
bPrimed[4] = false;  // 7   aTSI

var dPercent = new Array(5);
var vEMA = new Array(5);
var vEMA1 = new Array(5);

function EMA(nLength, nArray, nNum, nIndicator) {
    var nBarState = getBarState();
    var dSum = 0.0;

    if(nBarState == BARSTATE_ALLBARS || bPrimed[nNum] == false) {
        dPercent[nNum] = (2.0 / (nLength + 1.0));
        bPrimed[nNum] = false;
    }

    if (nBarState == BARSTATE_NEWBAR) {
        vEMA1[nNum] = vEMA[nNum];
    }

    if(bPrimed[nNum] == false) {
        for(i = 0; i < nLength; i++) {
            dSum += nArray[i];
        }
        bPrimed[nNum] = true;
        return (dSum / nLength);
    } else {
        return (((nIndicator - vEMA1[nNum]) * dPercent[nNum]) + vEMA1[nNum]);
    }
}