Announcement

Collapse
No announcement yet.

Change color of line for different slopes

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

  • Change color of line for different slopes

    Hello

    I searched the forums for a efs that will plot an EMA which change colors as the angles/slope of the line change.

    I did find an efs that do that with LSMA but I do not know how to apply the code to get the same result on a EMA efs.

    I attach the efs incase somebody can assist me with this.

    As always any help or direction will be appreciated.

    Regards
    Attached Files

  • #2
    I also found this efs but it only change colors when the line goes Up or down.

    I realy want the logic of the previous attached efs, that means one color if the slope is possitive more than a certain degree/slope, another color if the slope is negative more than a certain degree/slope and a third color for in between.

    Regards
    Attached Files

    Comment


    • #3
      I will be interested by EMA colored by slope too!

      Comment


      • #4
        Kobus
        In this thread you can find a basic script that shows how to calculate the slope of a moving average and apply a color based on the value of that slope.
        Use that as an example to create your efs and if you encounter any problems post what you have done and I or someone else can assist you
        Alex

        Comment


        • #5
          Alex

          As always thank you for the help. I attach the code for your inspection and comments.

          I notice that sometimes there is a small piece of the MA is blue, I checked the code and can not find any reason why this small pieces of blue occur (Unless of course I am not checking properly)

          Your advice will be appreciated
          Attached Files

          Comment


          • #6
            I try to attach an image, hope it comes out
            Attached Files

            Comment


            • #7
              Kobus
              That will happen when the value of sDisplayPrice is the same as the one at the prior bar. Because there is no provision to color the plot under that condition (and because no other default color is set through setDefailtBarFgColor()) the plot will be colored in blue which is the default used by efs.
              Alex

              Comment


              • #8
                Alex

                Thank you for the reply, I appreciate your help.

                I have added a few more option but I can not get it to plot the line, can you please be so kind as to show me my error.

                Regards
                Attached Files

                Comment


                • #9
                  Kobus
                  In line 77 if(vMA.getValue(-1)==null) return; should be if(vMA.getValue(MAStudy.MA,-1)==null) return;
                  Also check lines 80 and 83 where you calculate angle and FinalDegrees as the equations are different from those in the other formula.
                  Alex

                  Comment


                  • #10
                    Alex

                    Thank you very much, The problem is now solved and the indicator works correctly.

                    Thank you again for your dedication to us the mere mortals.

                    Regards

                    Comment


                    • #11
                      Kobus
                      You are most welcome.
                      At this point you may also want to revise or remove the logic used for the alerts as it is not functional. Either way you may want to simplify the conditions along the lines of the example shown below
                      Alex


                      PHP Code:
                      if (sDisplayPrice DnDegrees) { //if sDisplayPrice is less than the DnDegrees threshold
                              
                      setBar(Bar.FgColor,-1Color.red);
                              
                      //add other commands to be executed here
                          
                      } else if (sDisplayPrice UpDegrees) { //else if it greater than the UpDegrees threshold
                              
                      setBar(Bar.FgColor,-1Color.green);
                              
                      //add other commands to be executed here
                          
                      } else { //in all other cases... ie no need to define them specifically
                              
                      setBar(Bar.FgColor, -1Color.RGB(250,180,250));
                          } 

                      Comment


                      • #12
                        Alex

                        Thank you very much, I have implemented your suggestions.

                        I include the indicator as it stands now.

                        One more question, if I want to add another MA into the same code, do I have to duplicate everything or is there a more economical way?


                        Regards
                        Attached Files

                        Comment


                        • #13
                          Kobus
                          You would need to duplicate everything. Having said that if you click here you will find an efs called basicMAx2.efs which is already programmed to compute two moving averages. An EFS2 version called MAx2.efs is also available here
                          Alex

                          Comment


                          • #14
                            Alex

                            Thank you for the references, I got the two MA's to plot, but I ran into another problem. How do I get the other line to plot the different colors? If you would, can you please point out the error in my code?

                            I would very much appreciate it.

                            Thank you

                            Regards
                            Attached Files

                            Comment


                            • #15
                              Kobus
                              If you have more then one item being returned you need to specify that in the setBar() function by using the seriesIndex parameter (see the EFS KnowledgeBase for the complete syntax and examples) .
                              In the set of conditions that reference the second average you need to replace each instance of
                              setBar(Bar.FgColor,-1, Color...);
                              with
                              setBar(Bar.FgColor,-1, 1,Color...);
                              The added 1 will indicate to the setBar() function that it applies to the second element of the returned array.
                              Alex

                              Comment

                              Working...
                              X