Impulse CD Color

ICE Data Services -

ImpulseCDC.efs  

EFSLibrary - Discussion Board  

File Name: ImpulseCDC.efs

Description:
Impulse CD Color

Formula Parameters:

  • Slow MA : 34
  • Fast MA : 14
  • Signal MA : 9

Notes:

Download File:
ImpulseCDC.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:        
    Impulse CD Color
    
Version:            1.0  08/26/2009
 
Formula Parameters:                     Default:
    Slow MA                             34
    Fast MA                             14
    Signal MA                           9
   
Notes:
    
**********************************/
var fpArray = new Array();
var bInit = false;

function preMain(){
    setPriceStudy(false);
    setShowCursorLabel(true);
    setShowTitleParameters(false);
    setStudyTitle("Impulse CD");
    setCursorLabelName("Impulse MACD", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setPlotType(PLOTTYPE_HISTOGRAM, 0);
    setDefaultBarThickness(2,0);    
    setCursorLabelName("Signal", 1);
    setDefaultBarFgColor(Color.red, 1);
    setPlotType(PLOTTYPE_LINE, 1);
    setDefaultBarThickness(2,1);        
    setCursorLabelName("Impulse CD", 2);
    setDefaultBarFgColor(Color.green, 2);
    setPlotType(PLOTTYPE_HISTOGRAM, 2);
    setDefaultBarThickness(2,2);    
    var x = 0;
    fpArray[x] = new FunctionParameter("SlowMA", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Slow MA");
        setLowerLimit(1);
        setDefault(34);
    }    
    fpArray[x] = new FunctionParameter("FastMA", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Fast MA");
        setLowerLimit(1);
        setDefault(14);
    }        
    fpArray[x] = new FunctionParameter("SignalMA", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
        setName("Signal MA");
        setLowerLimit(1);
        setDefault(9);
    }        
}

var xImpulseCD = null;
var xMACDDivr = null;
var xSignalMACDDivr = null;
var xColor = null;

function main(SlowMA, FastMA, SignalMA) {
var nBarState = getBarState();
var nImpulseCD = 0;
var nMACDDivr = 0;
var nSignalMACDDivr = 0;
    if (nBarState == BARSTATE_ALLBARS) {
        if(SlowMA == null) SlowMA = 34;
        if(FastMA == null) FastMA = 14;
        if(SignalMA == null) SignalMA = 9;        
	}
	if (bInit == false) {
        addBand(0, PS_SOLID, 1, Color.black, "ZeroLine");
        xImpulseCD = efsInternal("Calc_ImpulseCD", SlowMA, FastMA, SignalMA);
        xMACDDivr = getSeries(xImpulseCD, 1);
        xSignalMACDDivr = getSeries(xImpulseCD, 2);
        xColor = getSeries(xImpulseCD, 3);
        bInit = true;
	}
    nImpulseCD = xImpulseCD.getValue(0);
    nMACDDivr = xMACDDivr.getValue(0);
    nSignalMACDDivr = xSignalMACDDivr.getValue(0);
    if (nMACDDivr == null) return;
    setBarFgColor(xColor.getValue(0), 2);
    return new Array(nMACDDivr, nSignalMACDDivr, nImpulseCD);
}

var bSecondInit = false;
var xMACDDivBuff = null;
var xMA_MACDDivBuff = null;

function Calc_ImpulseCD(SlowMA, FastMA, SignalMA) {
var nRes = 0;
var cColor = Color.green;
var nMACDDivBuff = 0;
var nMA_MACDDivBuff = 0;
var nMACDDivBuff1 = 0;
var nMA_MACDDivBuff1 = 0;
    if (!bSecondInit) {
        xMACDDivBuff =  macd(FastMA, SlowMA, 1); 
        xMA_MACDDivBuff = sma(SignalMA, xMACDDivBuff);
        bSecondINit = true;
    }
    nMACDDivBuff = xMACDDivBuff.getValue(0);
    nMA_MACDDivBuff = xMA_MACDDivBuff.getValue(0);
    nMACDDivBuff1 = xMACDDivBuff.getValue(-1);
    nMA_MACDDivBuff1 = xMA_MACDDivBuff.getValue(-1);
    if (nMA_MACDDivBuff1 == null) return;
    nRes = nMACDDivBuff - nMA_MACDDivBuff;
    if ((nMACDDivBuff - nMA_MACDDivBuff) > (nMACDDivBuff1 - nMA_MACDDivBuff1)) cColor = Color.green;
    if ((nMACDDivBuff - nMA_MACDDivBuff) < (nMACDDivBuff1 - nMA_MACDDivBuff1)) cColor = Color.red;    
    return new Array(nRes, nMACDDivBuff, nMA_MACDDivBuff, cColor);
}