PerformanceComp.efs

ICE Data Services -

PerformanceComp.efs  

File Name: PerformanceComp.efs

Description:
Compare up to 3 symbols on a % performance basis as a non-price study.

Formula Parameters:

  • Symbol1: Any valid symbol
  • Symbol2: Any valid symbol

Notes:
Must apply a time template that is not in dynamic mode to establish a specific starting point. This formula will not display useful results if your time template is in dynamic mode. For intra-day chart intervals, it is recommended to set the start/end times in your time template to the market's open and close times.

Download File:
PerformanceComp.efs


EFS Code:

/****************************************************************************************************
Copyright © eSignal, a division of Interactive Data Corporation. 2003. All rights reserved. 
This sample eSignal Formula Script (EFS) may be modified and saved under a new 
filename; however, eSignal is no longer responsible for the functionality once modified.
eSignal reserves the right to modify and overwrite this EFS file with each new release.
*****************************************************************************************************/
/** Updated:  01/14/03   **/

addBand(0, PS_SOLID, 2, Color.grey, "0");

var vLoaded = false;
var cSym = "";
function preMain() {
    if (vLoaded == false) {    
        setStudyTitle("\% Performance  ... Add Symbol(s)");
        setCursorLabelName("", 0);
        setCursorLabelName("Add Symbol", 1);
        setCursorLabelName("Add Symbol", 2);
        setDefaultBarFgColor(Color.blue, 0);
        setDefaultBarFgColor(Color.red, 1);
        setDefaultBarFgColor(Color.green, 2);
    } else {
        if (vSymbols[1] != null || vSymbols[2] != null) {
            setStudyTitle("\% Performance " + cSym + " vs. ");
        }
        setCursorLabelName(cSym + " \% Return", 0);
        if (vSymbols[1] != null) {
            setCursorLabelName(vSymbols[1] + " \% Return", 1);
        }
        if (vSymbols[2] != null) {
            setCursorLabelName(vSymbols[2] + " \% Return", 2);
        }
    }
}

var vSymbols = new Array(3);

var vBase = new Array(3);
var b = new Array(3);
for (i = 0; i < 3; ++i) {
    vBase[i] = 100;
}

var vCalcStart = false;

function adj() {
    for(cntr = 0; cntr < 3; ++cntr) {
        b[cntr] = (vBase[cntr] - 100);
    }
}

function ret_calc(pNew,pOld){
    var r = ((pNew-pOld)/pOld);
    return r;
}

function main(Symbol1, Symbol2) {
    if (vLoaded == false) {
        cSym = getSymbol();
        vSymbols[0] = cSym;
        for (cntr = 1; cntr < 3; ++cntr) {
            if (eval("Symbol" + cntr) != null) {
                vSymbols[cntr] = eval("Symbol" + cntr);
            }
        }
        for (i = 0; i < 3; ++i) {
            vBase[i] = 100;
        }
        adj();
        vLoaded = true;
        vCalcStart = false;
        preMain();
    }

    if (getBarState() == BARSTATE_NEWBAR) {
        for (cntr = 0; cntr < 3; ++cntr) {
            if (vSymbols[cntr] != null) {
                var p0 = close(0, 1, vSymbols[cntr]);
                if (vCalcStart == false) {
                    var p1 = open(-1, 1, vSymbols[cntr]);
                } else {
                    var p1 = close(-1, 1, vSymbols[cntr]);
                }
                if (p0 != null && p1 != null) {
                    var tReturn = ret_calc(p0, p1);
                    vBase[cntr] += (vBase[cntr] * tReturn);
                }
            }
        }
        vCalcStart = true;
        adj();
    }
    return b;
}