MACDColorHist.efs

ICE Data Services -


MACDColorHist.efs 
  

File Name: MACDColorHist.efs


Description:
Colors MACD histogram green when rising, red when falling. All inputs to MACD are configurable including histogram color. The display of the MACD histogram, Signal, MACD and MACD drop-lines can be turned on/off individually. The color of the drop-lines will match the up/down colors of the histogram up/down color settings. When the MACD is positive, the drop-down lines will be the up color and down color when the MACD is negative.


Formula Parameters:
Fast Length: Default is 12
Slow Length: Default is 26
Smoothing Length: Default is 9
Price Source: Default is Close, [Open, High, Low, Close, HL/2, HLC/3, OHLC/4]
MA Type: Default is SMA, [SMA, EMA]
MACD Hist Up Color: Default is green
MACD Hist Down Color: Default is red
MACD Color: Default is red
MACD Sig Color: Default is blue
Display Histogram: Yes, [Yes, No]
Display MACD: Yes, [Yes, No]
Display Signal: Yes, [Yes, No]
Display Drop Lines: Yes, [Yes, No]

Notes:
NA

Download File:
MACDColorHist.efs




EFS Code:






/*********************************Provided By : eSignal. (c) Copyright 2003*********************************//***  Updated 12/1/2003  ***    *Added FunctionParameter objects for user defined inputs.*Added drop-down lines to the MACD where the color will  match the up/down colors of the histogram up/down color  settings.  When MACD is positive, drop-down lines will be  the up color and down color when the MACD is negative.*Added options to enable/disable MACD histogrram, Signal,  MACD and MACD drop-lines.        ***************************/function preMain() {    setStudyTitle("Color MACD Histogram ");    setCursorLabelName("MACD", 0);    setCursorLabelName("MACD", 1);    setCursorLabelName("MACD Sig", 2);    setCursorLabelName("MACD Hist", 3);    setDefaultBarFgColor(Color.blue, 0);    setDefaultBarFgColor(Color.blue, 1);    setDefaultBarFgColor(Color.red, 2);    setDefaultBarFgColor(Color.magenta, 3);    setDefaultBarThickness(4, 3);    setPlotType(PLOTTYPE_LINE, 0);    setPlotType(PLOTTYPE_HISTOGRAM, 1);    setPlotType(PLOTTYPE_LINE, 2);    setPlotType(PLOTTYPE_HISTOGRAM, 3);        addBand(0, PS_SOLID, 1, Color.black, "zero");        var fp1 = new FunctionParameter("nFast", FunctionParameter.NUMBER);    fp1.setName("Fast Length");    fp1.setLowerLimit(1);    fp1.setDefault(12);        var fp2 = new FunctionParameter("nSlow", FunctionParameter.NUMBER);    fp2.setName("Slow Length");    fp2.setLowerLimit(1);    fp2.setDefault(26);    var fp3 = new FunctionParameter("nSmoothing", FunctionParameter.NUMBER);    fp3.setName("Smoothing Length");    fp3.setLowerLimit(1);    fp3.setDefault(9);    var fp4 = new FunctionParameter("PriceSource", FunctionParameter.STRING);    fp4.setName("Price Source");    fp4.addOption("Open");    fp4.addOption("High");    fp4.addOption("Low");    fp4.addOption("Close");    fp4.addOption("HL/2");    fp4.addOption("HLC/3");    fp4.addOption("OHLC/4");    fp4.setDefault("Close");    var fp5 = new FunctionParameter("nType", FunctionParameter.STRING);    fp5.setName("MA Type");    fp5.addOption("SMA");   //true    fp5.addOption("EMA");   //false    fp5.setDefault("SMA");        var fp6 = new FunctionParameter("nColorUp", FunctionParameter.COLOR);    fp6.setName("MACD Hist Up Color");    fp6.setDefault(Color.green);        var fp7 = new FunctionParameter("nColorDn", FunctionParameter.COLOR);    fp7.setName("MACD Hist Down Color");    fp7.setDefault(Color.red);        var fp8 = new FunctionParameter("cMACD", FunctionParameter.COLOR);    fp8.setName("MACD Color");    fp8.setDefault(Color.red);    var fp9 = new FunctionParameter("cMACDsig", FunctionParameter.COLOR);    fp9.setName("MACD Sig Color");    fp9.setDefault(Color.blue);    var fp10 = new FunctionParameter("bHist", FunctionParameter.STRING);    fp10.setName("Display Histogram");    fp10.addOption("Yes");    fp10.addOption("No");    fp10.setDefault("Yes");    var fp11 = new FunctionParameter("bMACD", FunctionParameter.STRING);    fp11.setName("Display MACD");    fp11.addOption("Yes");    fp11.addOption("No");    fp11.setDefault("Yes");    var fp12 = new FunctionParameter("bSignal", FunctionParameter.STRING);    fp12.setName("Display Signal");    fp12.addOption("Yes");    fp12.addOption("No");    fp12.setDefault("Yes");    var fp13 = new FunctionParameter("bDropLines", FunctionParameter.STRING);    fp13.setName("Display Drop Lines");    fp13.addOption("Yes");    fp13.addOption("No");    fp13.setDefault("Yes");}var study = null;var vColor = null;var vColorUp = null;var vColorDn = null;var vHist = null;var vHist1 = null;var bEdit = true;function main(nFast, nSlow, nSmoothing, PriceSource, nType, nColorUp, nColorDn,                 cMACD, cMACDsig, bHist, bMACD, bSignal, bDropLines) {    if (study == null || bEdit == true) {        if (nFast == null) nFast = 12;        if (nSlow == null) nSlow = 26;        if (nSmoothing == null) nSmoothing = 9;        if (PriceSource == null) PriceSource = "Close";        if (nType == null) {            nType = false;        } else if (nType == "SMA") {            nType = true;        } else {            nType = false;        }        if (nColorUp == null) {            vColorUp = Color.green;        } else {            vColorUp = nColorUp;        }        if (nColorDn == null) {            vColorDn = Color.red;        } else {            vColorDn = nColorDn;        }        study = new MACDStudy(nFast, nSlow, nSmoothing, PriceSource, nType);        setDefaultBarFgColor(cMACD, 0);        setDefaultBarFgColor(cMACD, 1);        setDefaultBarFgColor(cMACDsig, 2);        setDefaultBarFgColor(cMACDsig, 3);        bEdit = false;    }        if (getBarState() == BARSTATE_NEWBAR && vHist != null) {        vHist1 = vHist;    }        vHist = study.getValue(MACDStudy.HIST);    if (vHist == null)        return;    var vMACD = study.getValue(MACDStudy.MACD);    if (vMACD == null)        return;    var vSig = study.getValue(MACDStudy.SIGNAL);    if (vSig == null)        return;        if (vHist1 != null && vHist >= vHist1) {        vColor = vColorUp;    } else if (vHist1 != null && vHist < vHist1) {        vColor = vColorDn;    }        if (vMACD < 0) setBarFgColor(nColorDn, 1);    if (vMACD >= 0) setBarFgColor(nColorUp, 1);    if (vColor != null) {        setBarFgColor(vColor, 3);    }    var vHdisplay = vHist.toFixed(2)*1;    if (bHist == "No") vHdisplay = vHdisplay+"";    var vMdisplay = vMACD.toFixed(2)*1;    if (bMACD == "No") vMdisplay = vMdisplay+"";    var vMdisplay1 = vMACD.toFixed(2)*1;    if (bDropLines == "No") vMdisplay1 = vMdisplay1+"";    var vSdisplay = vSig.toFixed(2)*1;    if (bSignal == "No") vSdisplay = vSdisplay+"";        return new Array(vMdisplay, vMdisplay1, vSdisplay, vHdisplay);}