MACD Gradient

ICE Data Services -

MACDGradient.efs                                                                                  EFSLibrary - Discussion Board

File Name: MACDGradient.efs


Description:
MACD Gradient

 

Formula Parameters:
Fast Length: 12
Slow Length: 26
Smoothing: 9

 

Notes:
Changes colors of the price bars according to the relative level
of MACDDiff.

 

Download File:
MACDGradient.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:        
    MACD Gradient

Version:            1.0  10/28/2008

Formula Parameters:                     Default:
    Fast Length                          12
    Slow Length                          26
    Smoothing                            9

Notes:
    Changes colors of the price bars according to the relative level
    of MACDDiff.

**********************************/

var fpArray = new Array();
var bInit = false;

function preMain() {
    setPriceStudy(true);
    setShowCursorLabel(false);
    setShowTitleParameters( false );
    setStudyTitle("MACD Gradient");
    setColorPriceBars(true);    

    var x=0;
    fpArray[x] = new FunctionParameter("FastLength", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Fast Length");
        setLowerLimit(1);		
        setDefault(12);
    }
    fpArray[x] = new FunctionParameter("SlowLength", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Slow Length");
        setLowerLimit(1);		
        setDefault(26);
    }
    fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
	with(fpArray[x++]){
        setName("Smoothing");
        setLowerLimit(1);		
        setDefault(9);
    }
}

var	xMACDValue = null;
var nR = 0;
var nG = 0;
var nB = 0;
var Max = 1;
var Min = -1;

function main(FastLength, SlowLength, Smoothing) {
var nMACDDiff = 0;
var nValue = 0;
    if ( bInit == false ) { 
        xMACDValue = macdHist(FastLength, SlowLength, Smoothing);
        bInit = true; 
    } 

    if (getCurrentBarCount() < Math.max(SlowLength, FastLength)) return;
    nValue = xMACDValue.getValue(0);

    nR = 0;   
    if (nValue >= 0) {
        nG = 220;
        nB = Math.round(nValue * 100) + 5;    
        if (nB > Max) Max = nB;
        if (nB < Min) Min = nB;
        nB = RGB_G(nB, Max, Min);
        if (nB == null) nB = 0;
    } else {
        nG = Math.round(Math.abs(nValue) * 100) + 5;        
        nB = 255;        
        if (nG > Max) Max = nG;
        if (nR < Min) Min = nG;
        nG = RGB_G(nG, Max, Min);
        if (nG == null) nG = 0;
    }
    setPriceBarColor(Color.RGB(nR,nG,nB));
    return; 
}

function RGB_G(Val, Max, Min) {
var tmpG = 0;
var Perc1 = 0;
    if (Val > 0) {
        Perc1 = (Val * 100) / Max;
        tmpG = 255 - (Perc1*255)/100;
        return Math.round(tmpG);
    } else {
        Perc1 = ((Val*-1) * 100) / (Min*-1);
        tmpG = 255 - (Perc1*255)/100;
        return Math.round(tmpG);
    }
    return  tmpG;
}