Announcement

Collapse
No announcement yet.

MACD Drop Lines

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MACD Drop Lines

    Hello,

    Is there any way of making the MACD drop lines color coded?

    i.e. red if lower than previous, green if higher.

    I cant seem to get to the code to look.

    Many thanks
    Attached Files

  • #2
    abbers
    You may want to check this thread as I think Jason has already coded something along the lines of your request
    Alex

    Comment


    • #3
      Alex,

      Thanks for the reply, ive had a look at the code and i think its lines
      134 - 143 i need to change, could u be so kind as to help me on what i should change it to.

      Once again many thanks.


      /************************************************** **************************************************
      Copyright © eSignal, a division of Interactive Data Corporation. 2003. All rights reserved.
      This sample eSignal Formula Script (EFS) may be modified and saved under a new
      filename; however, eSignal is no longer responsible for the functionality once modified.
      eSignal reserves the right to modify and overwrite this EFS file with each new release.
      ************************************************** ************************************************** */

      /*** 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 historgram, 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.darkgrey, "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 (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);
      }

      Comment


      • #4
        abbers
        Change the following two lines
        if (vMACD < 0) setBarFgColor(nColorDn, 1);
        if (vMACD >= 0) setBarFgColor(nColorUp, 1);

        to
        if (vMACD < study.getValue(MACDStudy.MACD,-1)) setBarFgColor(nColorDn, 1);
        if (vMACD >= study.getValue(MACDStudy.MACD,-1)) setBarFgColor(nColorUp, 1);

        I think that should do it
        Alex

        Comment


        • #5
          Alex,

          That did the trick........many thanks

          Comment

          Working...
          X