2001 Feb: Buff Up Your Moving Averages

ICE Data Services -

BuffAverages.efs  
EFSLibrary - Discussion Board  

File Name: BuffAverages.efs

Description:
Buff Averages

Formula Parameters:

  • Fast Avg Length: 5
  • Slow Avg Length: 20
  • Thickness: 2
  • Line Color Fast Buff: Red
  • Line Color Slow Buff: Blue
  • Display Cursor Labels: True

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


EFS Code:

/*********************************
Provided By:  
    eSignal (Copyright c eSignal), a division of Interactive Data 
    Corporation. 2008. 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:        
    Buff Averages

Version:            1.0  01/12/2009

Formula Parameters:                     Default:
    Fast Avg Length                     5
    Slow Avg Length                     20
    Thickness                           2
    Line Color Fast Buff                Red
    Line Color Slow Buff                Blue
    Display Cursor Labels               True

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;

function preMain() {
    setPriceStudy(true);
    setShowCursorLabel(false);
    setShowTitleParameters( false );
    setStudyTitle("Buff Averages");
    setCursorLabelName("Fast Buff", 0);
    setCursorLabelName("Slow Buff", 1);    
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.blue, 1);
    setPlotType(PLOTTYPE_LINE, 0); 
    setPlotType(PLOTTYPE_LINE, 1); 
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
   
    askForInput();
    var x=0;
    fpArray[x] = new FunctionParameter("LineColor1", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("Line Color Fast Buff");
        setDefault(Color.red);
    }    

    fpArray[x] = new FunctionParameter("LineColor2", FunctionParameter.COLOR);
    with(fpArray[x++]){
        setName("Line Color Slow Buff");
        setDefault(Color.blue);
    }    

    fpArray[x] = new FunctionParameter("ViewValue", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
        setName("Display Cursor Labels");
        setDefault(true);
    }    
    
    fpArray[x] = new FunctionParameter("SlowAvg", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Slow Avg Length");
        setLowerLimit(1);		
        setDefault(20);
    }

    fpArray[x] = new FunctionParameter("FastAvg", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Fast Avg Length");
        setLowerLimit(1);		
        setDefault(5);
    }

    fpArray[x] = new FunctionParameter("Thickness", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Lines Thickness");
        setLowerLimit(1);		
        setDefault(2);
    }
}

var xBuffFastAvg = null;
var xBuffSlowAvg = null;

function main(FastAvg, SlowAvg, Thickness, LineColor1, LineColor2, ViewValue) {
var nBuff1Res = 0;
var nBuff2Res = 0;

    if ( bInit == false ) { 
        setDefaultBarFgColor(LineColor1, 0);
        setDefaultBarFgColor(LineColor2, 1);        
        setDefaultBarThickness(Thickness, 0);
        setDefaultBarThickness(Thickness, 1);        
        setShowCursorLabel(ViewValue);   
        xBuffFastAvg = efsInternal("Buff_Calc", FastAvg);
        xBuffSlowAvg = efsInternal("Buff_Calc", SlowAvg);
        bInit = true; 
    } 

    if (getCurrentBarCount() < Math.max(SlowAvg, FastAvg)) return;
    
    nBuff1Res = xBuffFastAvg.getValue(0);
    nBuff2Res = xBuffSlowAvg.getValue(0); 
    
    if (nBuff1Res == null || nBuff2Res == null) return;

    return new Array(nBuff1Res, nBuff2Res); 
}

function Buff_Calc(nLength) {
var nVolSum = 0;
var nRes = 0;
    for (var i = 0; i <= nLength -1; i++) {
        nVolSum += volume(-i);
    }
    
    if (nVolSum != 0) {
        for (var i = 0; i < nLength; i++){
            nRes += (close(-i) * volume(-i)) / nVolSum;
        }
    }
    if (nRes == null) nRes = 1;
    return nRes;
}