Announcement

Collapse
No announcement yet.

builtinmacdcolorcoded

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

  • builtinmacdcolorcoded

    I downloaded the 'builtinmacdcolorcoded' efs study from the

    forum. How do I change the histogram's magenta color bars to

    different colors, green color for up bars and red color for down

    bars.

    Thanks.
    Attached Files

  • #2
    Hello bandraguy,

    The magenta lines are the Histogram series, which is the first series returned by the formula. It's series position in the return statement is 0, so you need to reference that series number with the setBarFgColor(Color, Series) parameter. Try adding the following code just before the return statement in main.

    PHP Code:
        
        
    if(vMACD.getValue(MACDStudy.HIST)>vMACD.getValue(MACDStudy.HIST,-1)) {
            
    setBarFgColor(Color.lime,0)
        } else {
            
    setBarFgColor(Color.red,0)
        } 
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Difference b/w Two MACD

      What is the difference between two MACD
      files, 'builtinmacdcolorcoded(1)' and 'builtinmacd(hist color)2', which are on the forum.

      Besides, color and thickness of lines, I see both files have different codes (script), but when plotted, both look the same.

      Do these files plot simple moving averages (sma) or exponential moving averages (ema)?

      Thanks for your prompt reply.

      Comment


      • #4
        bandraguy
        You may want to provide the links to the efs(s) you are referencing.
        Alex

        Comment


        • #5
          Difference between two MACD

          What is the difference between two MACD
          files, 'builtinmacdcolorcoded(1)' and 'builtinmacd(hist color)2', which are on the forum.

          Besides, color and thickness of lines, I see both files have different codes (script), but when plotted, both look the same.

          Do these files plot simple moving averages (sma) or exponential moving averages (ema)?

          Thanks for your prompt reply.



          File # 1: 'Builtinmacdcolorcoded(1)



          /************************************************** *******
          Alexis C. Montenegro © July 2003
          Use and/or modify this code freely. If you redistribute it
          please include this and/or any other comment blocks and a
          description of any changes you make.
          ************************************************** ********/

          var vMACD = null;

          function preMain() {
          setStudyTitle("MACD");
          setCursorLabelName("MACDHist",0);
          setCursorLabelName("MACD",1);
          setCursorLabelName("MACDSig",2);
          setDefaultBarFgColor(Color.red,0);
          setDefaultBarFgColor(Color.blue,1);
          setDefaultBarFgColor(Color.red,2);
          setDefaultBarThickness(2,0);
          setDefaultBarThickness(2,1);
          setDefaultBarThickness(2,2);
          setPlotType(PLOTTYPE_HISTOGRAM);

          var fp1 = new FunctionParameter("Fast", FunctionParameter.NUMBER);
          fp1.setLowerLimit(1);
          fp1.setDefault(12); //Edit this value to set a new default

          var fp2 = new FunctionParameter("Slow", FunctionParameter.NUMBER);
          fp2.setLowerLimit(1);
          fp2.setDefault(26); //Edit this value to set a new default

          var fp3 = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
          fp3.setLowerLimit(1);
          fp3.setDefault(9); //Edit this value to set a new default

          var fp4 = new FunctionParameter("Source", FunctionParameter.STRING);
          fp4.setName("Source");
          fp4.addOption("Close");
          fp4.addOption("High");
          fp4.addOption("Low");
          fp4.addOption("Open");
          fp4.addOption("HL/2");
          fp4.addOption("HLC/3");
          fp4.addOption("OHLC/4");
          fp4.setDefault("Close"); //Edit this value to set a new default

          var fp5 = new FunctionParameter("TypeOsc", FunctionParameter.BOOLEAN);
          fp5.setName("SMA (Oscillator)");
          fp5.setDefault(false); //Edit this value to set a new default

          var fp5 = new FunctionParameter("TypeSig", FunctionParameter.BOOLEAN);
          fp5.setName("SMA (Signal)");
          fp5.setDefault(true); //Edit this value to set a new default

          }

          function main(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig) {


          if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig);

          /*********************************************
          Insert your code following this text block
          Use vMACD.getValue(MACDStudy.HIST) and
          vMACD.getValue(MACDStudy.MACD) and
          vMACD.getValue(MACDStudy.SIGNAL) for your code
          **********************************************/

          if(vMACD.getValue(MACDStudy.HIST)>vMACD.getValue(M ACDStudy.HIST,-1))
          setBarFgColor(Color.lime,1);



          if(vMACD.getValue(MACDStudy.MACD)>vMACD.getValue(M ACDStudy.MACD,-1))
          setBarFgColor(Color.lime,1)
          return new Array (vMACD.getValue(MACDStudy.HIST),vMACD.getValue(MAC DStudy.MACD),vMACD.getValue(MACDStudy.SIGNAL));

          }



          File # 2: 'Builtinmacd(hist color)2



          /************************************************** *******
          Alexis C. Montenegro © July 2003
          Use and/or modify this code freely. If you redistribute it
          please include this and/or any other comment blocks and a
          description of any changes you make.
          ************************************************** ********/

          var vMACD = null;

          function preMain() {
          setStudyTitle("MACD");
          setCursorLabelName("MACDHist",0);
          setCursorLabelName("MACD",1);
          setCursorLabelName("MACDSig",2);
          setDefaultBarFgColor(Color.magenta,0);
          setDefaultBarFgColor(Color.blue,1);
          setDefaultBarFgColor(Color.red,2);
          setDefaultBarThickness(1,0);
          setDefaultBarThickness(1,1);
          setDefaultBarThickness(1,2);
          setPlotType(PLOTTYPE_HISTOGRAM);

          var fp1 = new FunctionParameter("Fast", FunctionParameter.NUMBER);
          fp1.setLowerLimit(1);
          fp1.setDefault(12); //Edit this value to set a new default

          var fp2 = new FunctionParameter("Slow", FunctionParameter.NUMBER);
          fp2.setLowerLimit(1);
          fp2.setDefault(26); //Edit this value to set a new default

          var fp3 = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
          fp3.setLowerLimit(1);
          fp3.setDefault(9); //Edit this value to set a new default

          var fp4 = new FunctionParameter("Source", FunctionParameter.STRING);
          fp4.setName("Source");
          fp4.addOption("Close");
          fp4.addOption("High");
          fp4.addOption("Low");
          fp4.addOption("Open");
          fp4.addOption("HL/2");
          fp4.addOption("HLC/3");
          fp4.addOption("OHLC/4");
          fp4.setDefault("Close"); //Edit this value to set a new default

          var fp5 = new FunctionParameter("TypeOsc", FunctionParameter.BOOLEAN);
          fp5.setName("SMA (Oscillator)");
          fp5.setDefault(false); //Edit this value to set a new default

          var fp5 = new FunctionParameter("TypeSig", FunctionParameter.BOOLEAN);
          fp5.setName("SMA (Signal)");
          fp5.setDefault(true); //Edit this value to set a new default

          var fp6 = new FunctionParameter("Display1", FunctionParameter.STRING);
          fp6.setName("Display MACD");
          fp6.addOption("ON");
          fp6.addOption("OFF");
          fp6.setDefault("ON"); //Edit this value to set a new default

          var fp7 = new FunctionParameter("Display2", FunctionParameter.STRING);
          fp7.setName("Display HIST");
          fp7.addOption("ON");
          fp7.addOption("OFF");
          fp7.setDefault("ON"); //Edit this value to set a new default


          }

          function main(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig, Display1, Display2) {

          if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig);

          /*********************************************
          Insert your code following this text block
          Use vMACD.getValue(MACDStudy.HIST) and
          vMACD.getValue(MACDStudy.MACD) and
          vMACD.getValue(MACDStudy.SIGNAL) for your code
          **********************************************/

          var MACD = vMACD.getValue(MACDStudy.MACD);
          var SIGNAL = vMACD.getValue(MACDStudy.SIGNAL);
          var HIST = vMACD.getValue(MACDStudy.HIST);

          if(Display1=="OFF"){
          MACD=null;
          SIGNAL=null;
          }
          if(Display2=="OFF"){
          HIST=null;
          }

          if(HIST>0)
          setBarFgColor(Color.green,0);
          if(HIST<0)
          setBarFgColor(Color.red,0);


          return new Array (HIST,MACD,SIGNAL);

          }

          Comment


          • #6
            bandraguy
            Both efs(s) are modifications of the builtinMACD.efs that is in the Builtin subfolder of Formulas and share the same functionality of the original. They can be set to use simple or exponential averages for either the MACD or Signal lines.
            Builtinmacdcolorcoded.efs was originally posted in this thread and was modified at that time to color the MACD line in green when it is rising. In the version you posted code was added that also colors the MACD line in green if the Histogram is rising.
            Builtinmacd(hist color)2.efs instead was originally posted in this thread and was modified at that time to color the Histogram in green if above 0 and in red if below. The option to display/hide the MACD and Signal or Histogram lines was also added. The code you posted is unchanged from that version.
            Alex

            Comment


            • #7
              MACD osc sma or ema

              I am using the file 'builtinmacd(hist color)2.efs' to plot macd histogram, is this file using simple moving average (sma) or exponential moving average (ema) to plot macd signal.

              If it is using sma, how do I change it to ema and vice versa.

              Also, I have made some changes to change the color and thickness of the lines, can you check, if those changes are correct.

              Thanks for your prompt reply.


              File Name: 'builtinmacd(hist color)2'


              /************************************************** *******
              Alexis C. Montenegro © July 2003
              Use and/or modify this code freely. If you redistribute it
              please include this and/or any other comment blocks and a
              description of any changes you make.
              ************************************************** ********/

              var vMACD = null;

              function preMain() {
              setStudyTitle("MACD");
              setCursorLabelName("MACDHist",0);
              setCursorLabelName("MACD",1);
              setCursorLabelName("MACDSig",2);
              setDefaultBarFgColor(Color.magenta,0);
              setDefaultBarFgColor(Color.blue,1);
              setDefaultBarFgColor(Color.red,2);
              /*************************************
              setDefaultBarThickness(1,0);
              setDefaultBarThickness(1,1);
              setDefaultBarThickness(1,2);

              (Changes made by bandraguy next 3 lines)
              *************************************/

              setDefaultBarThickness(2,0);
              setDefaultBarThickness(2,1);
              setDefaultBarThickness(2,2);
              setPlotType(PLOTTYPE_HISTOGRAM);

              var fp1 = new FunctionParameter("Fast", FunctionParameter.NUMBER);
              fp1.setLowerLimit(1);
              fp1.setDefault(12); //Edit this value to set a new default

              var fp2 = new FunctionParameter("Slow", FunctionParameter.NUMBER);
              fp2.setLowerLimit(1);
              fp2.setDefault(26); //Edit this value to set a new default

              var fp3 = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
              fp3.setLowerLimit(1);
              fp3.setDefault(9); //Edit this value to set a new default

              var fp4 = new FunctionParameter("Source", FunctionParameter.STRING);
              fp4.setName("Source");
              fp4.addOption("Close");
              fp4.addOption("High");
              fp4.addOption("Low");
              fp4.addOption("Open");
              fp4.addOption("HL/2");
              fp4.addOption("HLC/3");
              fp4.addOption("OHLC/4");
              fp4.setDefault("Close"); //Edit this value to set a new default

              var fp5 = new FunctionParameter("TypeOsc", FunctionParameter.BOOLEAN);
              fp5.setName("SMA (Oscillator)");
              fp5.setDefault(false); //Edit this value to set a new default

              var fp5 = new FunctionParameter("TypeSig", FunctionParameter.BOOLEAN);
              fp5.setName("SMA (Signal)");
              fp5.setDefault(true); //Edit this value to set a new default

              var fp6 = new FunctionParameter("Display1", FunctionParameter.STRING);
              fp6.setName("Display MACD");
              fp6.addOption("ON");
              fp6.addOption("OFF");
              fp6.setDefault("ON"); //Edit this value to set a new default

              var fp7 = new FunctionParameter("Display2", FunctionParameter.STRING);
              fp7.setName("Display HIST");
              fp7.addOption("ON");
              fp7.addOption("OFF");
              fp7.setDefault("ON"); //Edit this value to set a new default


              }

              function main(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig, Display1, Display2) {

              if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig);

              /*********************************************
              Insert your code following this text block
              Use vMACD.getValue(MACDStudy.HIST) and
              vMACD.getValue(MACDStudy.MACD) and
              vMACD.getValue(MACDStudy.SIGNAL) for your code
              **********************************************/

              var MACD = vMACD.getValue(MACDStudy.MACD);
              var SIGNAL = vMACD.getValue(MACDStudy.SIGNAL);
              var HIST = vMACD.getValue(MACDStudy.HIST);

              if(Display1=="OFF"){
              MACD=null;
              SIGNAL=null;
              }
              if(Display2=="OFF"){
              HIST=null;
              }
              /**************************************
              (Changes made by bandraguy next 3 lines)
              **************************************/

              if(vMACD.getValue(MACDStudy.MACD)>vMACD.getValue(M ACDStudy.MACD,-1))
              setBarFgColor(Color.lime,1);

              if(HIST>0)
              setBarFgColor(Color.green,0);
              if(HIST<0)
              setBarFgColor(Color.red,0);


              return new Array (HIST,MACD,SIGNAL);

              }

              Comment


              • #8
                bandraguy
                To change the type of average used for the MACD and Signal lines go into Edit Studies and check the appropriate parameter
                Alex

                Comment

                Working...
                X