2009 Dec: Disparity Index

ICE Data Services -

DisparityIndex.efs  
EFSLibrary - Discussion Board  

File Name: DisparityIndex.efs

Description:
Disparity Index

Formula Parameters:

  • Length First : 200
  • Length Secind : 50
  • Length Third : 20
  • First Line Color : Red
  • Second Line Color : Blue
  • Third Line Color : Green
  • Show First Line : True
  • Show Second Line : True
  • Show Third Line : True
  • FirstLineThickness : 1
  • SecondLineThickness : 1
  • ThirdLineThickness : 1

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

Download File:
DisparityIndex.efs


EFS Code:

/*********************************
Provided By:  
    eSignal (Copyright c eSignal), a division of Interactive Data 
    Corporation. 2009. All rights reserved. This sample eSignal 
    Formula Script (EFS) is for educational purposes only and may be 
    modified and saved under a new file name.  eSignal is not responsible
    for the functionality once modified.  eSignal reserves the right 
    to modify and overwrite this EFS file with each new release.

Description:        
    Disparity Index

Version:            1.0  10/07/2009

Formula Parameters:                     Default:
    Length First                        200
    Length Secind                       50
    Length Third                        20
    First Line Color                    Red
    Second Line Color                   Blue
    Third Line Color                    Green
    Show First Line                     True
    Show Second Line                    True
    Show Third Line                     True
    FirstLineThickness                  1
    SecondLineThickness                 1
    ThirdLineThickness                  1

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 bInit = false;
var bVersion = null;

function preMain() {
    setPriceStudy(false);
    setShowCursorLabel(true);
    setShowTitleParameters(false);
    setCursorLabelName("DIX", 0);
    setShowCursorLabel(true, 0);
    setPlotType(PLOTTYPE_LINE, 0);
    setDefaultBarThickness(1, 0);
    setDefaultBarFgColor(Color.red, 0);
    setCursorLabelName("DIX", 1);
    setShowCursorLabel(true, 1);
    setPlotType(PLOTTYPE_LINE, 1);
    setDefaultBarThickness(1, 1);
    setDefaultBarFgColor(Color.blue, 1);
    setCursorLabelName("DIX", 2);
    setShowCursorLabel(true, 2);
    setPlotType(PLOTTYPE_LINE, 2);
    setDefaultBarThickness(1, 2);
    setDefaultBarFgColor(Color.green, 2);
    setStudyTitle("Disparity Index");
    askForInput();
    var x=0;
    fpArray[x] = new FunctionParameter("LengthFirst", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Length First");
        setLowerLimit(1);		
        setDefault(200);
    }
    fpArray[x] = new FunctionParameter("LengthSecond", FunctionParameter.NUMBER);
	with(fpArray[x++]){
	    setName("Length Second");
        setLowerLimit(1);		
        setDefault(50);
    }
    fpArray[x] = new FunctionParameter("LengthThird", FunctionParameter.NUMBER);
	with(fpArray[x++]){
	    setName("Length Third");
        setLowerLimit(1);		
        setDefault(20);
    }
    fpArray[x] = new FunctionParameter("FirstLineColor", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("First Line Color");
        setDefault(Color.red);
    }   
    fpArray[x] = new FunctionParameter("SecondLineColor", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("Second Line Color");
        setDefault(Color.blue);
    }   
    fpArray[x] = new FunctionParameter("ThirdLineColor", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("Third Line Color");
        setDefault(Color.green);
    }
    fpArray[x] = new FunctionParameter("ShowFirst", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
        setName("Show First Line");
        setDefault(true);
    }   
    fpArray[x] = new FunctionParameter("ShowSecond", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
        setName("Show Second Line");
        setDefault(true);
    }   
    fpArray[x] = new FunctionParameter("ShowThird", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
        setName("Show Third Line");
        setDefault(true);
    }   
    fpArray[x] = new FunctionParameter("FirstLineThickness", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("First Line Thickness");
        setLowerLimit(1);		
        setDefault(1);
    }   
    fpArray[x] = new FunctionParameter("SecondtLineThickness", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("First Line Thickness");
        setLowerLimit(1);		
        setDefault(1);
    }   
    fpArray[x] = new FunctionParameter("ThirdLineThickness", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("First Line Thickness");
        setLowerLimit(1);		
        setDefault(1);
    }   
}

var xDIX200 = null;
var xDIX50 = null;
var xDIX20 = null;

function main(LengthFirst, LengthSecond, LengthThird, FirstLineColor, SecondLineColor, ThirdLineColor,
             ShowFirst, ShowSecond, ShowThird, FirstLineThickness, SecondtLineThickness, ThirdLineThickness) {
var nBarState = getBarState();
var nDIX200 = 0;
var nDIX50 = 0;
var nDIX20 = 0;
var aReturn = new Array();
var nCount = 0;
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;   
    if (nBarState == BARSTATE_ALLBARS) {
        if (LengthFirst == null) LengthFirst = 200;
        if (LengthSecond == null) LengthSecond = 50;
        if (LengthThird == null) LengthThird = 20;
        if (FirstLineColor == null) FirstLineColor = Color.red;
        if (SecondLineColor == null) SecondLineColor = Color.blue;
        if (ThirdLineColor == null) ThirdLineColor = Color.green;
        if (ShowFirst == null) ShowFirst = true;
        if (ShowSecond == null) ShowSecond = true;
        if (ShowThird == null) ShowThird = true;
        if (FirstLineThickness == null) FirstLineThickness = 1;
        if (SecondtLineThickness == null) SecondtLineThickness = 1;
        if (ThirdLineThickness == null) ThirdLineThickness = 1;
    }    
    if ( bInit == false ) { 
        setDefaultBarFgColor(FirstLineColor, 0);
        setDefaultBarFgColor(SecondLineColor, 1);
        setDefaultBarFgColor(ThirdLineColor, 2);
        setDefaultBarThickness(FirstLineThickness, 0);
        setDefaultBarThickness(SecondtLineThickness, 1);
        setDefaultBarThickness(ThirdLineThickness, 2);
        xDIX200 = efsInternal("Calc_DIX", LengthFirst);
        xDIX50 = efsInternal("Calc_DIX", LengthSecond);
        xDIX20 = efsInternal("Calc_DIX", LengthThird);
        bInit = true; 
    }
    nDIX200 = xDIX200.getValue(0);
    nDIX50 = xDIX50.getValue(0);
    nDIX20 = xDIX20.getValue(0);
    if (nDIX200 == null && nDIX50 == null && nDIX20 == null) return;
    if (ShowFirst) aReturn[nCount++] = nDIX200; else {
        setShowCursorLabel(false, 0);
        aReturn[nCount++] = null;
    }    
    if (ShowSecond) aReturn[nCount++] = nDIX50; else {
        setShowCursorLabel(false, 1);
        aReturn[nCount++] = null;
    }    
    if (ShowThird) aReturn[nCount++] = nDIX20; else {
        setShowCursorLabel(false, 2);
        aReturn[nCount++] = null;
    }    
    return aReturn;
}

var bSecondInit = false;
var xEMA = null;

function Calc_DIX(Length) {
var nRes = 0;
var nEMA = 0;
var nClose = 0;
    if (bSecondInit == false) {
        addBand(0,PS_SOLID,1,Color.black,"Zero");
        xEMA = ema(Length);
        bSecondInit = true;
    }
    nEMA = xEMA.getValue(0);
    if (nEMA == null) return;
    nClose = close(0);
    nRes = 100 * (nClose - nEMA) / nClose;
    return nRes;
}

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;
}