MASS Index

ICE Data Services -


MassIndex.efs  EFSLibrary - Discussion Board
  

File Name: MassIndex.efs


Description:
MASS Index


Formula Parameters:
nSetup : 27
nTrigger : 26.5
nLength1 : 9
nLength2 : 25

Notes:
The Mass Index was designed to identify trend reversals by measuring
the narrowing and widening of the range between the high and low prices.
As this range widens, the Mass Index increases; as the range narrows
the Mass Index decreases.
The Mass Index was developed by Donald Dorsey.

Download File:
MassIndex.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:            MASS IndexVersion:            1.0  04/17/2009Formula Parameters:                     Default:    nSetup                              27    nTrigger                            26.5    nLength1                            9    nLength2                            25    Notes:    The Mass Index was designed to identify trend reversals by measuring     the narrowing and widening of the range between the high and low prices.     As this range widens, the Mass Index increases; as the range narrows     the Mass Index decreases.    The Mass Index was developed by Donald Dorsey. **********************************/var fpArray = new Array();var bInit = false;function preMain() {    setStudyTitle("Mass Index");    setCursorLabelName("MassIndex", 0);    setDefaultBarFgColor(Color.red, 0);    var x = 0;    fpArray[x] = new FunctionParameter("nSetup", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(1);        setDefault(27);    }    fpArray[x] = new FunctionParameter("nTrigger", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(1);        setDefault(26.5);    }    fpArray[x] = new FunctionParameter("nLength1", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(1);        setDefault(9);    }    fpArray[x] = new FunctionParameter("nLength2", FunctionParameter.NUMBER);    with(fpArray[x++]) {        setLowerLimit(1);        setDefault(25);    }}var xMassIndex = null;function main(nSetup, nTrigger, nLength1, nLength2) {var nBarState = getBarState();var nMassIndex = 0;    if (nBarState == BARSTATE_ALLBARS) {        if (nSetup != null) nSetup = 27;        if (nTrigger != null) nTrigger = 26.5;        if (nLength1 != null) nLength1 = 9;        if (nLength2 != null) nLength2 = 25;    }        if (bInit == false) {        addBand(nSetup, PS_SOLID, 1, Color.blue, 1);        addBand(nTrigger, PS_SOLID, 1, Color.blue, 2);        xMassIndex = efsInternal("Calc_MassIndex", nLength1, nLength2);        bInit = true;    }    nMassIndex = xMassIndex.getValue(0);    return nMassIndex;}   var bSecondInit = false;var xSmoothXAvg = null;var xEMA = null;function Calc_MassIndex(nLength1, nLength2) {var nSmoothXAvg = 0;var nRes = 0;var i = 0;    if (bSecondInit == false) {        xEMA = ema(nLength1, efsInternal("Calc_Price"));        xSmoothXAvg = ema(nLength1, xEMA);        bSecondInit = true;    }    if (xSmoothXAvg.getValue(-nLength2) == null || xEMA.getValue(-nLength2) == null) return;    for (i = 0; i < nLength2; i++) {        nSmoothXAvg = xSmoothXAvg.getValue(-i);        if (nSmoothXAvg != 0) nRes += xEMA.getValue(-i) / nSmoothXAvg;    }    return nRes;}    function Calc_Price() {var nRes = 0;    nRes = high(0) - low(0);    if (nRes == null) return;    return nRes;}