Volume_with_MA.efs

ICE Data Services -

 

Volume_with_MA.efs    

File Name: Volume_with_MA.efs

Description:
This plots a moving average on a volume indicator.

 

Formula Parameters:
nMALength - Defines the length of the Moving Average. Default is 10.

 

Notes:
NA

 

Download File:
Volume_with_MA.efs


EFS Code:

/*************************
Copyright © eSignal, 2003
**************************
Description: Displays volume with moving average
*/

var study = null;

function preMain() {
    
    setStudyTitle("Volume with MA");
    setCursorLabelName("Volume",0);
    setCursorLabelName("MA",1);
    
    setPlotType(PLOTTYPE_HISTOGRAM,0);
}

var vMAArray = new Array();

function main(nMALength) {

    if (nMALength == null) {
        nMALength = 10;
    }    
    else {
        nMALength = Math.round(nMALength);
    }

    // Get data
    var vVol = volume();
    var vOpen = open();
    var vClose = close();
    
    if (vVol == null) return;
    
    var nBarState = getBarState();
    
    if (nBarState == BARSTATE_NEWBAR) {
        
        vMAArray.unshift(vVol);   //inserts array element to the front of the array
    
    }

    vMAArray[0] = vVol;

    if (vMAArray[nMALength-1] != null) {
        
        var vSum = 0;
        
        for (i=0; i <= nMALength-1; i++) {
            vSum += vMAArray[i];
        }
        var vMAofVol = vSum / nMALength;
        
    } else return;
    
    if (vOpen <= vClose) setBarFgColor(Color.green, 0);
    if (vOpen > vClose) setBarFgColor(Color.red, 0);
    
    return new Array (vVol, vMAofVol);

}