SymbolCompareAsNPS2.efs

ICE Data Services -

SymbolCompareAsNPS2.efs  

File Name: SymbolCompareAsNPS2.efs

Description:

Compare a symbol to your chart symbol as a non-price study with H/L bars.

Formula Parameters:

  • Symbol: Any valid symbol (Spread symbols are not valid for this formula).
  • Number of Bars: Default is 200. Max/Min Limits: 200/1
  • Bar Thickness: Default is 2. Controls the thickness of the H/L bars.
  • Up Bar Color: Default is green.
  • Neutral Bar Color: Default is grey.
  • Down Bar Color: Default is red.

Notes:
After applying the formula, go to "Edit Studies" and enter a symbol. The formula also draws the high/Low bars and the open, similar to a bar chart.

Download File:
SymbolCompareAsNPS2_EFS2.efs (Requires Version 7.9 or later)
SymbolCompareAsNPS2.efs


EFS Code:

/***************************************************************
Copyright © eSignal, a division of Interactive Data Corporation. 2005

EFS2 version of SymbolCompareAsNPS2.efs
Requires eSignal version 7.9 or later.

The study has been updated to utilize EFS2 functions to handle syncronization
between symbols that have different trading hours.

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


var vLoaded = false;
var cSym = "";
var vSym = null;

function preMain() {
    if (vLoaded == false) {    
        setStudyTitle(" ... Add Symbol");
        setCursorLabelName("Add Symbol");
        setDefaultBarFgColor(Color.red);
        var fp1 = new FunctionParameter("Symbol1", FunctionParameter.STRING);
            fp1.setName("Symbol");
            //fp1.setDefault(null);
        var fp2 = new FunctionParameter("NumBars", FunctionParameter.NUMBER);
            fp2.setName("Number of Bars");
            fp2.setLowerLimit(1);		
            fp2.setUpperLimit(400);
            fp2.setDefault(200);
        var fp3 = new FunctionParameter("BarThickness", FunctionParameter.NUMBER);
            fp3.setName("Bar Thickness");
            fp3.setLowerLimit(1);		
            fp3.setUpperLimit(10);
            fp3.setDefault(2);
        var fp4 = new FunctionParameter("Ucolor", FunctionParameter.COLOR);
            fp4.setName("Up Bar Color");
            fp4.setDefault(Color.green);
        var fp5 = new FunctionParameter("Ncolor", FunctionParameter.COLOR);
            fp5.setName("Neutral Bar Color");
            fp5.setDefault(Color.grey);
        var fp6 = new FunctionParameter("Dcolor", FunctionParameter.COLOR);
            fp6.setName("Down Bar Color");
            fp6.setDefault(Color.red);
    } else {
        if (vSym != null && vSym != "") {
            setStudyTitle(cSym + " vs. ");
            setCursorLabelName(vSym+" O", 0);
            setCursorLabelName(vSym+" H", 1);
            setCursorLabelName(vSym+" L", 2);
            setCursorLabelName(vSym+" C", 3);
            setPlotType(PLOTTYPE_FLATLINES,0);
            setPlotType(PLOTTYPE_DOT,1);
            setPlotType(PLOTTYPE_DOT,2);
            setPlotType(PLOTTYPE_FLATLINES,3);
            setDefaultBarThickness(1,0);
            setDefaultBarThickness(1,1);
            setDefaultBarThickness(1,2);
            setDefaultBarThickness(1,3);
            setDefaultBarFgColor(Color.black,0);
            setDefaultBarFgColor(Color.black,1);
            setDefaultBarFgColor(Color.black,2);
            setDefaultBarFgColor(Color.black,3);
        } else {
            setStudyTitle(" ... Add Symbol");        
            setCursorLabelName("Add Symbol");
        }
    }
}

var vBarCntr = 0;

function main(Symbol1, NumBars, BarThickness, Ucolor, Ncolor, Dcolor) {
    if (vLoaded == false) {
        cSym = getSymbol();
        if (Symbol1 == null) {
            vSym = null;
        } else {
            vSym = Symbol1;
        }
        vLoaded = true;
        preMain();
    }

    if (vSym == null) return;
    
    if (getBarState() == BARSTATE_NEWBAR) {
        if (vBarCntr > NumBars) {
            vBarCntr = 0;
        } else {
            vBarCntr += 1;
        }
    }
    
    var o = open(sym(vSym));
    var h = high(sym(vSym));
    var l = low(sym(vSym));
    var c = close(sym(vSym));
    
    var vColor = Ncolor;
    if (c > o) vColor = Ucolor;
    else if (c < o) vColor = Dcolor;
    
    setBarFgColor(vColor, 0);
    setBarFgColor(vColor, 1);
    setBarFgColor(vColor, 2);
    setBarFgColor(vColor, 3);
    
    drawLineRelative(0, h, 0, l, PS_SOLID, BarThickness, vColor, "bar"+vBarCntr);
    
    return new Array(o, h, l, c);
}