Announcement

Collapse
No announcement yet.

Linear Regression MACD

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

  • Linear Regression MACD

    I am trying to determine the slope, or angle of the MACD in coding an indicator. After searching and reading a lot of posts, It looks like the EFS indicators written by Alexis were suggested, I have downloaded Alexis indicators

    amLinregangle.efs
    amLinregslope.efs


    I have looked in the Edit Studies and notice I can change the Length, and the Source, so my question is if I would like to determine the angle on a standard MACD indicator, of the Fast Length parameter, which is set to 12, if I have the "amLinregangle.efs" loaded and set to 12 Close, is this value that its returning the Angle in decimal?

    Is there a way to convert this to degrees? or just perform the math?

    Just looking to learn more about this Any help is appreciated.

  • #2
    This might work:

    http://share.esignal.com/groupconten...on&groupid=339

    You may want to read this regarding use of slope:

    http://forum.esignalcentral.com/show...threadid=15319

    Wayne
    Last edited by waynecd; 06-08-2010, 11:02 PM.

    Comment


    • #3
      I loaded the slope indicators, as you suggested, and modified the settings for the EMA to the same as the MACD that I have running.

      I overlaid the Slope indicator over the MACD, the SLOPE is Green color, the MACD fast line is Blue.

      I get a value of .007.

      Is there a way to modify this indicator, to report the degrees of the slope?

      I read a post that discusses how to do this:
      http://forum.esignalcentral.com/show...e&pagenumber=3

      from this post:
      "Standard slope is simply rise over run. 


      Converting an angle to percentage terms is:

nSlopePct = Math.tan( nAngle * (Math.PI/180) );



      where nAngle is the angle in degrees of the line in question.



      Use the Math.atan() function to accomplish this.



      If you have a 30% slope, to convert that to degrees you would divide the arctangent of 0.30 by Pi /180. In EFS you could do it this way:

var nSlope = 0.30; //30% slope

nAngle = Math.atan( nSlope ) / (Math.PI/180);

nAngle now equals 16.6992442 degrees.
"
      Attached Files

      Comment


      • #4
        What indicator?
        Is there a way to modify this indicator, to report the degrees of the slope?
        Wayne

        Comment


        • #5
          One of the EFS, that you pointed me to in the fileshare had a EFS called Relative Slope, the EFS is here:

          /* Notes:
          Study requires version 8.0 or later.
          Relative Slope efs coded by - S. Hare - 1 30 2007, Version 1.0
          http://share.esignal.com/fileupload....%20Calculation
          Post: http://forum.esignalcentral.com/show...6877#post96877

          Authored by Dimitris Tsokakis, the relative slope takes an exponential moving average of typical
          price (HLC/3), commonly a 20 period EMA but the period is customizable. It then takes the resulting
          values, and for each value, the previous value is subtracted and the result is divided by the sum
          of the two values. These results are then further smoothod with a 3 period EMA.

          other efs by the same author : http://share.esignal.com/groupconten...rts&groupid=84 */

          var bInit = false; // these are global variables, they can be seen in every part of the efs
          var flag1 = false;
          var relativeSlopeSeries = null;
          var relativeSlope = null;
          var X = null;
          var fpArray = new Array();

          function preMain() {
          setPriceStudy(false);
          setShowTitleParameters(false);
          setStudyTitle("Relative Slope");
          setCursorLabelName("Relative Slope",0);
          setDefaultBarFgColor(Color.blue,0);
          setDefaultBarThickness(2,0);
          addBand( 0, PS_SOLID, 1, Color.red);
          InitFunctionParameter();
          }

          function main(Smoothing,P) {
          if(bInit == false){
          relativeSlopeSeries = ema(Smoothing, efsInternal("RelativeSlope", P, hlc3));
          bInit = true;
          }

          if (getBarState() == BARSTATE_NEWBAR) {}

          relativeSlope = relativeSlopeSeries.getValue(0);
          if(relativeSlope>0)
          {
          setDefaultBarFgColor(Color.green,0);
          }
          else
          {
          setDefaultBarFgColor(Color.red,0);
          }
          return relativeSlope;
          }

          function RelativeSlope(len,source)
          {
          if(bInit == false){
          X = ema(len, source());
          bInit = true; // this starts out as a global value set to false, but is distinct from other instance in main
          }

          if(!flag1)
          {
          flag1 = (X.getValue(-1)!=null);
          return null;
          }

          var testForZero = X.getValue(0)+X.getValue(-1);
          if(testForZero == 0)
          {
          testForZero +=.001;
          }

          var Y = 2*(X.getValue(0)-X.getValue(-1))/testForZero;
          return (Y*100);
          }

          // now the customizable user inputs
          function InitFunctionParameter()
          {
          var x = 0;
          fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
          with(fpArray[x++])
          {
          setName("Smoothing");
          setLowerLimit(1);
          setDefault(3);
          }
          fpArray[x] = new FunctionParameter("P", FunctionParameter.NUMBER);
          with(fpArray[x++])
          {
          setName("User Supplied Period");
          setLowerLimit(5);
          setDefault(20);
          }
          }
          Attached Files

          Comment


          • #6
            I added a formula for degrees. You can find commentary on it and slope at:

            http://forum.esignalcentral.com/show...e&pagenumber=1

            Notice that degrees and slope (at least as implemented in this efs) are the same plot but with different scales. Since the scales are so different you can only display one at a time, you won't see them both if you plot them in the same pane.

            Just select which; slope or degrees, you want to plot from the menu.

            Wayne
            Attached Files

            Comment


            • #7
              waynecd -

              Thanks for your assistance on this!

              I have loaded this, and over-laid the changes to a standard MACD indicator, I have taken a screen shot of just the over-lay, with the change and setting to Degrees as shown in the screen - shot.


              My thought is if displayed in degrees the angle shown, where my line is hovering over shows the Relative Slope (in Degrees) is .9, is this value returned is in radians....


              A user on this forum suggested and I quote their comment "dividing radians by (Pi/180) will convert that value to degrees"

              Is, or can this value be modified to be displayed as a value in Degrees? or is shown already?
              Attached Files

              Comment


              • #8
                I'm not a mathematician so I am also relying on previous posts and forum searches. All I can pass on is the following from a basic forum search of "radians":

                http://forum.esignal.com/showthread....hlight=radians

                and in:
                http://forum.esignal.com/showthread....hlight=radians

                The Model.efs states the following:

                //nAlpha = (1 - Math.sin(360/nLength)) / Math.cos(360/nLength);
                /************************************************** *************
                Math.sin and Math.cos in JavaScript are represented in Radians,
                TradeStations returns degrees. To convert Math.sin(360/n) to
                Radians, replace 360 with (2*Math.PI).
                Or to convert Degrees to Radians => (Number * Math.PI) / 180
                ************************************************** *************/
                Try a forum search for "Radians" or "Slope" or "Degrees".

                Also, just the first google search result for "convert radians to degrees" gave a formula at:
                http://www.teacherschoice.com.au/mat...les/angles.htm

                Converting radians to degrees:
                To convert radians to degrees, we make use of the fact that p radians equals one half circle, or 180º.

                This means that if we divide radians by p, the answer is the number of half circles. Multiplying this by 180º will tell us the answer in degrees.

                So, to convert radians to degrees, multiply by 180/p, like this:

                degrees = radians x 180/Pi

                Converting degrees to radians:
                To convert degrees to radians, first find the number of half circles in the answer by dividing by 180º. But each half circle equals p radians, so multiply the number of half circles by p.

                So, to convert degrees to radians, multiply by p/180, like this:

                radians = degrees x Pi/180
                The next site provided this formula:
                angle in degrees = angle in radians * 180 / Pi

                Wayne
                Last edited by waynecd; 06-09-2010, 11:57 PM.

                Comment

                Working...
                X