2011 Feb: The Spearman Indicator For Technical Analysis

ICE Data Services -

SpearmanIndicator.efs  
EFSLibrary - Discussion Board  

File Name: SpearmanIndicator.efs

Description:
The Spearman Indicator For Technical Analysis

Formula Parameters:

  • Period: 10

Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

Download File:
SpearmanIndicator.efs


EFS Code:

/*********************************
Provided By:  
    Interactive Data Corporation (Copyright © 2010) 
    All rights reserved. This sample eSignal Formula Script (EFS)
    is for educational purposes only. Interactive Data Corporation
    reserves the right to modify and overwrite this EFS file with 
    each new release. 
	
Description:        
    The Spearman Indicator For Technical Analysis
 
Version:            1.0  10/12/2010

Formula Parameters:                     Default:
    Period                                10
    
Notes:
    The related article is copyrighted material. If you are not
    a subscriber of Stocks & Commodities, please visit www.traders.com.

**********************************/

var fpArray = new Array();
var bVersion = null;
function preMain()
{
    setStudyTitle("Spearman Indicator");
    setCursorLabelName("Spearman Indicator",0);
    setCursorLabelName("EMA(3)",1);
    
    setDefaultBarFgColor(Color.RGB(0,148,255),0);
    setDefaultBarFgColor(Color.red,1);
    
    var x=0;
    fpArray[x] = new FunctionParameter("gPeriod", FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
	setName("Period");
	setLowerLimit(1);
        setDefault(10);
    }
}

var vSC2 = null;
var vSC1 = null;
var vSC = null;
function main(gPeriod)
{
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return; 

    if ( getCurrentBarCount() - gPeriod < 0 ) return;
    if (getBarState() == BARSTATE_NEWBAR)
    {
        vSC2 = vSC1;
        vSC1 = vSC;
    }
   
    var r1 = new Array ();
    var r22 = new Array ();
    var r11 = new Array ();
    var r21 = new Array ();
    for ( i=0; i<gperiod; i++="" )="" {="" r1[i]="gPeriod" -="" i;="" r22[i]="gPeriod" r11[i]="close(i" gperiod="" +="" 1);="" r21[i]="close(i" var="" j="i;" while="" (j="">0 && j<gperiod) {="" if="" (r21[j]="">r21[j-1])
                {
                    var cBoard = r21[j];
                    r21[j] = r21[j-1];
                    r21[j-1] = cBoard;
                }
                else break;
                j--;   
            }
    }
    
    for( i=0; i<gPeriod; i++)
    {
        var found = 0;
        while ( found < 1 )
        {
            for (j=0; j<gPeriod; j++)
            {
                if (r21[j]==r11[i])
                {
                    r22[i]=j;
                    found=1;
                }
            }
        }
    }

    var absum = 0;
    for ( i=0; i<gPeriod; i++ )
    {
        var ab = r1[i] - r22[i];
        var ab2 = ab*ab;
        absum = absum + ab2;
    }
    
    var vCoefCorr = (1-(6*absum)/(gPeriod*(gPeriod*gPeriod-1)));    
    vSC = vCoefCorr*100;
    
    if (vSC2 ==null) return new Array(vSC,vSC);
        
    var vSMA3SC = (vSC+vSC1+vSC2)/3;
    return new Array(vSC, vSMA3SC);
    
}

function verify() {
    var b = false;
    if (getBuildNumber() < 779) {
        drawTextAbsolute(5, 35, "This study requires version 8.0 or later.", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "error");
        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "upgrade");
        return b;
    } else {
        b = true;
    }
    return b;
}