Announcement

Collapse
No announcement yet.

TSI Momentum

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TSI Momentum

    From an esignal user who emailed me...

    I do not know how to put this in Javascript code.

    TSI formulae is:


    TSI(Close,r,s) = 100 * EMA(EMA(MTM,r),s)/EMA(EMA(|MTM|,r),s)


    Where MTM = Momentum = Close [today] - close[yesterday]

    computed for r =32, s = 5 days...

  • #2
    Hi,

    Here is the TSI code:

    Code:
    /*******************************************************************
    Description	: This Indicator plots TSI indicator
    Provided By	: Developed by TS Support, LLC for eSignal. (c) Copyright 2002 
    ********************************************************************/
    
    function preMain()
    {
        setStudyTitle("TSI"); 
        setCursorLabelName("TSI", 0);
        setCursorLabelName("SigLine", 1);
        setCursorLabelName("ZeroLine", 2);
        setDefaultBarFgColor(Color.red, 0);
        setDefaultBarFgColor(Color.blue, 1);
        setDefaultBarFgColor(Color.grey, 2);
    }
    var XA1_1 = 0.0;
    var XA2_1 = 0.0;
    var XA3_1 = 0.0;
    var aXA1_1 = 0.0;
    var aXA2_1 = 0.0;
    var aXA3_1 = 0.0;
    var XA_1 = 0.0;
    
    
    var XA1 = 0;
    var XA2 = 0;
    var XA3 = 0;
    var aXA1 = 0;
    var aXA2 = 0;
    var aXA3 = 0;
    var XA = 0;
    
    
    function main(sPrice, r, s, u, ZeroLine, SmthLen)
    {
        if (sPrice == null) sPrice = "Close";
        if (r == null) r = 4;
        if (s == null) s = 8;
        if (u == null) u = 6;
        if (ZeroLine == null) ZeroLine = 0;
        if (SmthLen == null) SmthLen = 13;
    
        // makes sense    
        var Price = getValue(sPrice, 0, -2);
        // MAG
        if(Price == null) {
        	return;
        }
    
        var vPrice = Price[0] - Price[1];
    
        // MAG (moved from bottom of formula)    
        if (getBarState() == BARSTATE_NEWBAR)
        {
            XA1_1 = XA1;
            XA2_1 = XA2;
            XA3_1 = XA3;
            aXA1_1 = aXA1;
            aXA2_1 = aXA2;
            aXA3_1 = aXA3;
            XA_1 = XA;
        }
        /**
        XA1 = XA1_1;
        XA2 = XA2_1;
        XA3 = XA3_1;
        aXA1 = aXA1_1;
        aXA2 = aXA2_1;
        aXA3 = aXA3_1;
        XA = XA_1;
        **/
        
        
        // constants
        var FactorR = 2 / (r + 1);
        var FactorS = 2 / (s + 1);
        var FactorU = 2 / (u + 1);
        
        // MAG removed 'var' 
        XA1 = FactorR * vPrice + (1 - FactorR) * XA1_1;
        XA2 = FactorS * XA1 + (1 - FactorS) * XA2_1;
        XA3 = FactorU * XA2 + (1 - FactorU) * XA3_1;
    
        vPrice = Math.abs(Price[0] - Price[1]);
    
        // MAG removed 'var'
        aXA1 = FactorR * vPrice + (1 - FactorR) * aXA1_1;
        aXA2 = FactorS * aXA1 + (1 - FactorS) * aXA2_1;
        aXA3 = FactorU * aXA2 + (1 - FactorU) * aXA3_1;
    
        var Val1 = 100 * XA3;
        var Val2 = aXA3;
        var TSI = 0.0;
    
        if (Val2 != 0) TSI = Val1 / Val2;
        else TSI = 0.0;
    
        var Factor = 2 / (SmthLen + 1);
        
        // MAG removed 'var'
        XA = Factor * TSI + (1 - Factor) * XA_1;
    
        return new Array(TSI, XA, ZeroLine);
    }
    Regards,
    Andy

    Comment

    Working...
    X