Announcement

Collapse
No announcement yet.

Multiple Color in EFS ? How?

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

  • Multiple Color in EFS ? How?

    I have a simple EFS I am working on, and I am attempting to set multiple colors in it, so if the MACD.Signal line goes below 0 it will be a darker color, and if above 0 a lighter color. So basically the question is how or are you able to set multiple colors from EFS:

    Here is my simple EFS:

    function main() {

    var vMACD_15 =macd(12, 26, 9);
    var vMACD_S_15 =macdSignal(12, 26, 9);
    var vMACD_60 =macd(12, 26, 9);
    var vMACD_S_60 =macdSignal(12, 26, 9);


    if (
    vMACD_15.getValue(macd) > vMACD_S_15.getValue(macdSignal)

    ) onAction1()

    else if (
    vMACD_15.getValue(macd) < vMACD_S_15.getValue(macdSignal)

    ) onAction2()



    function onAction1() {
    setBarBgColor(Color.RGB(178,255,178));
    vLastAlert = 1;
    }

    function onAction2() {
    setBarBgColor(Color.RGB(255,192,160));
    vLastAlert = 2;

  • #2
    To clarify the attached EFS does indeed plot 2 colors, but what I am attempting to do, is to be able to plot up to 4 colors, 2 colors for MACD going up, and 2 colors for MACD going down.

    Hopefully this can be done. ?

    Comment


    • #3
      Read a few things over, and modified the code a bit again trying to plot multiple colors, here is the code:

      function main() {

      var vMACD_15 =macd(12, 26, 9);
      var vMACD_S_15 =macdSignal(12, 26, 9);
      var vMACD_H_15 =macdHist(12, 26, 9);
      var onAction1 =setBarBgColor(Color.RGB(0,255,0));
      var onAction2 =setBarBgColor(Color.RGB(255,192,160));
      var OnAction3 =setBarBgColor(Color.RGB(255,255,0));
      var OnAction4 =setBarBgColor(Color.RGB(128,255,0));


      if (
      vMACD_15.getValue(macd) > vMACD_S_15.getValue(macdSignal) && vMACD_15(getValue(macd) > 0

      )) onAction1() //Light Green Color Above 0

      vMACD_15.getValue(macd) < vMACD_S_15.getValue(macdSignal) && vMACD_15(getValue(macd) < 0

      ) ;onAction2() //Light Red Color Below 0

      vMACD_S_15.getValue(macd) > vMACD_S_15.getValue(macdSignal) && vMACD_15(getValue(macd) < 0

      ) ;onAction3()

      vMACD_15.getValue(macd) < vMACD_S_15.getValue(macdSignal) && vMACD_15(getValue(macd) > 0

      ) ;onAction4() //Darker Green Above 0 but going down.

      But its still not displaying the multi-colors.. Any suggestions are welcome.

      Comment


      • #4
        Got it working!

        Comment


        • #5
          OK, sorry everyone for my ignorance... But this is getting somewhat frustrating...

          Here is my EFS, the MENU is working, but now its NOT coloring the background, as it was before. I added the ability to change the colors from the menu, but since doing that its not working:

          var aFPArray =new Array();
          var vMACD_15 =macd(12, 26, 9);
          var vMACD_S_15 =macdSignal(12, 26, 9);
          var vLastAlert = -1;


          function preMain()
          {

          //initialize formula parameters
          x=0;
          setPriceStudy(false);
          setStudyTitle("MACD-Colored");
          //define a color menu option
          aFPArray[x] = new FunctionParameter( "FCOLOR1", FunctionParameter.COLOR);
          with( aFPArray[x] ) {
          setName( "Select COLOR - MACD > Signal & above 0" );
          setDefault( Color.blue );
          }
          x++;
          //define a color menu option
          aFPArray[x] = new FunctionParameter( "FCOLOR2", FunctionParameter.COLOR);
          with( aFPArray[x] ) {
          setName( "Select COLOR - MACD < Signal & above 0" );
          setDefault( Color.red );
          }
          //define a color menu option
          aFPArray[x] = new FunctionParameter( "FCOLOR3", FunctionParameter.COLOR);
          with( aFPArray[x] ) {
          setName( "Select COLOR - MACD < Signal & below 0" );
          setDefault( Color.red );
          }
          //define a color menu option
          aFPArray[x] = new FunctionParameter( "FCOLOR4", FunctionParameter.COLOR);
          with( aFPArray[x] ) {
          setName( "Select COLOR - MACD > Signal & below 0" );
          setDefault( Color.blue );
          }
          }


          function Main( FCOLOR1,
          FCOLOR2,
          FCOLOR3,
          FCOLOR4) {
          var x;
          {
          if (
          vMACD_15.getValue(macd) > vMACD_S_15.getValue(macdSignal) &&
          vMACD_15.getValue(macd) < 0
          ) onAction1()

          else if (
          vMACD_15.getValue(macd) > vMACD_S_15.getValue(macdSignal) &&
          vMACD_15.getValue(macd) > 0
          ) onAction2()

          else if (
          vMACD_15.getValue(macd) < vMACD_S_15.getValue(macdSignal) &&
          vMACD_15.getValue(macd) > 0
          ) onAction3()

          else if (
          VMACD_15.getValue(macd) < vMACD_S_15.getValue(macdSignal) &&
          vMACD_15.getValue(macd) < 0
          ) onAction4()
          }}


          function postMain() {

          }

          //{{EFSWizard_Actions
          //{{EFSWizard_Action_1
          function onAction1() {
          setBarBgColor.FCOLOR1
          vLastAlert = 1;

          }
          function onAction2() {
          setBarBgColor.FCOLOR2;
          vLastAlert = 2;
          }
          function onAction3() {
          setBarBgColor.FCOLOR3;
          vLastAlert = 3;
          }
          function onAction4() {
          setBarBgColor.FCOLOR4;
          vLastAlert = 4;
          }

          Comment


          • #6
            Try this:

            PHP Code:
            //http://forum.esignal.com/showthread.php?threadid=34909
            var aFPArray =new Array(); 
            var 
            vMACD_15 =null;
            var 
            vMACD_S_15 =null;
            var 
            vLastAlert = -1;

            function 
            preMain(){ 

                
            setPriceStudy(false);
                
            setStudyTitle("MACD-Colored"); 

                var 
            x=0;
                
            aFPArray[x] = new FunctionParameter"FCOLOR1"FunctionParameter.COLOR); 
                
            withaFPArray[x++] ) { 
                    
            setName"Select COLOR - MACD > Signal & above 0" ); 
                    
            setDefaultColor.blue ); 
                } 
                
            aFPArray[x] = new FunctionParameter"FCOLOR2"FunctionParameter.COLOR); 
                
            withaFPArray[x++] ) { 
                    
            setName"Select COLOR - MACD < Signal & above 0" ); 
                    
            setDefaultColor.red ); 
                }
                
            aFPArray[x] = new FunctionParameter"FCOLOR3"FunctionParameter.COLOR); 
                
            withaFPArray[x++] ) { 
                    
            setName"Select COLOR - MACD < Signal & below 0" ); 
                    
            setDefaultColor.red ); 
                }
                
            aFPArray[x] = new FunctionParameter"FCOLOR4"FunctionParameter.COLOR); 
                
            withaFPArray[x++] ) { 
                    
            setName"Select COLOR - MACD > Signal & below 0" ); 
                    
            setDefaultColor.blue ); 
                }
            }

            var 
            bInit false;

            function 
            mainFCOLOR1,FCOLOR2,FCOLOR3,FCOLOR4){

                if(!
            bInit){
                    
            vMACD_15 =macd(12269);
                    
            vMACD_S_15 =macdSignal(12269);
                    
            bInit true;
                }
                if (
            vMACD_15.getValue(0) > vMACD_S_15.getValue(0) &&
                
            vMACD_15.getValue(0) < && vLastAlert != 1onAction1(FCOLOR1);

                else if (
            vMACD_15.getValue(0) > vMACD_S_15.getValue(0) &&
                
            vMACD_15.getValue(0) > && vLastAlert != 2onAction2(FCOLOR2);

                else if (
            vMACD_15.getValue(0) < vMACD_S_15.getValue(0) &&
                
            vMACD_15.getValue(0) > && vLastAlert != 3onAction3(FCOLOR3);

                else if (
            vMACD_15.getValue(0) < vMACD_S_15.getValue(0) &&
                
            vMACD_15.getValue(0) < && vLastAlert != 4onAction4(FCOLOR4);

                return new Array(
            getSeries(vMACD_15),getSeries(vMACD_S_15));
            }

            function 
            onAction1(FCOLOR1) {
                
            setBarBgColor(FCOLOR1,0);
                
            vLastAlert 1;
            }

            function 
            onAction2(FCOLOR2) {
                
            setBarBgColor(FCOLOR2,0);
                
            vLastAlert 2;
            }

            function 
            onAction3(FCOLOR3) {
                
            setBarBgColor(FCOLOR3,0);
                
            vLastAlert 3;
            }

            function 
            onAction4(FCOLOR4) {
                
            setBarBgColor(FCOLOR4,0);
                
            vLastAlert 4;

            Wayne

            Comment

            Working...
            X