Announcement

Collapse
No announcement yet.

slope of an ema efs

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

  • slope of an ema efs

    Can someone show me how to write an efs that takes the slope of a 10ema. I want the slope to appear on my data window and i also want to have the 10ema change color in different slope ranges, green for positive slope, red negative slope, grey for a neutral slope.
    This strategy involves buying or selling bouces off the 10ema based on the steepness of the slope when it hits the 10ema.
    Its my belief that the steeper the slope the higher chances of success fo this type of trade.
    Thanks as always,
    Yoda

  • #2
    I want to make sure i was clear in my previous request. i dont simply want an efs that color codes my bars based on if the ema is simply rising or falling. Rather for this strategy i need a quantitative number that shows me the steepness as well as the direction of the slope.
    Yoda

    Comment


    • #3
      //{{EFSWizard_Description
      //
      // This formula was generated by the Alert Wizard
      //
      //}}EFSWizard_Description 7532


      //{{EFSWizard_Declarations

      var vEMA10 = new MAStudy(10, 0, "Close", MAStudy.EXPONENTIAL);
      var vLastAlert = -1;

      //}}EFSWizard_Declarations 9951


      function preMain() {
      /**
      * This function is called only once, before any of the bars are loaded.
      * Place any study or EFS configuration commands here.
      */
      //{{EFSWizard_PreMain
      setPriceStudy(false);
      setStudyTitle("yodaSlope");
      setCursorLabelName("ma10eSlope", 0);
      setDefaultBarStyle(PS_SOLID, 0);
      setDefaultBarFgColor(Color.red, 0);
      setDefaultBarThickness(1, 0);
      setPlotType(PLOTTYPE_HISTOGRAM, 0);
      //}}EFSWizard_PreMain 32753

      }

      function main() {
      /**
      * The main() function is called once per bar on all previous bars, once per
      * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
      * in your preMain(), it is also called on every tick.
      */

      //{{EFSWizard_Expressions
      //{{EFSWizard_Expression_1
      if (
      vEMA10.getValue(MAStudy.MA, -1) < vEMA10.getValue(MAStudy.MA, -2)
      ) onAction1()
      //}}EFSWizard_Expression_1 12159

      //{{EFSWizard_Expression_2
      else if (
      vEMA10.getValue(MAStudy.MA, -2) < vEMA10.getValue(MAStudy.MA, -1)
      ) onAction2();
      //}}EFSWizard_Expression_2 13752

      //}}EFSWizard_Expressions 48111


      //{{EFSWizard_Return
      return vEMA10.getValue(MAStudy.MA, -2) - vEMA10.getValue(MAStudy.MA, -1);
      //}}EFSWizard_Return 4922

      }

      function postMain() {
      /**
      * The postMain() function is called only once, when the EFS is no longer used for
      * the current symbol (ie, symbol change, chart closing, or application shutdown).
      */
      }

      //{{EFSWizard_Actions
      //{{EFSWizard_Action_1
      function onAction1() {
      setBarFgColor(Color.RGB(255,0,0));
      setPriceBarColor(Color.RGB(255,0,0))
      vLastAlert = 1;
      }
      //}}EFSWizard_Action_1 10759

      //{{EFSWizard_Action_2
      function onAction2() {
      setBarFgColor(Color.RGB(0,255,0));
      setPriceBarColor(Color.RGB(0,255,0))
      vLastAlert = 2;
      }
      //}}EFSWizard_Action_2 9652

      //}}EFSWizard_Actions 39866

      Comment


      • #4
        return vEMA10.getValue(MAStudy.MA, -1) - vEMA10.getValue(MAStudy.MA, -2);

        probably makes more sense

        Comment


        • #5
          Thanks it works great but i did switch the -1 to 0 and -2 to -1 as i need the slope as it is hitting the ma so i need the current bar and previous bar values for the calculation. Do you know of any way to calculate the angle of the emas slope.
          thanks again,
          Yoda

          Comment


          • #6
            My next request regarding this efs would be to place and X or an arrow above the price bar corresponding to the level of the slope.
            If the slope>.01 then print a green X on the bar
            If slope >-.01 and <.01 print a black X on the bar.
            if slope<.01 print a red X on the bar.

            Of course for different timeframes you would have to adjust the .01 to whatever is good for that timeframe. The object here is that you only take bounces off the 10ema if the previous bar has a green x on it for longs or a red x on it for shorts.

            My final step here would be to have a strategy which puts abuy order in at the 10ema when the previous bar has a green x and to put a sell order in at the 10ema when the previos bar has a red x on it.

            Thanks for your help here,
            Yoda

            Comment


            • #7
              yoda
              The attached efs will paint the bar green if the slope is >0.5, red if <0.5 and black if in between.
              You can adjust the slope filter values (separately for UP or DN) in Edit Studies
              Alex
              Attached Files
              Last edited by ACM; 03-04-2003, 06:36 AM.

              Comment


              • #8
                yoda

                Do you know of any way to calculate the angle of the emas slope

                The angle (in degrees) is the inv Tan of the slope expressed in percentage. Example for 30% slope
                angle = inv Tan (30/100) = 16.67 degrees
                Alex

                Comment


                • #9
                  it works great
                  thanks

                  Comment


                  • #10
                    slope

                    does anybody have the slope angle in an efs?

                    Comment


                    • #11
                      Angle of a Slope

                      WaveTrader:

                      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.

                      Chris

                      Note: the reason atan() alone won't do the trick is because the value returned is in radians.... and dividing radians by (Pi/180) will convert that value to degrees.
                      Last edited by ckryza; 03-14-2003, 11:16 AM.

                      Comment


                      • #12
                        Chris:

                        You are a genius. The best! Thanks man.

                        Comment


                        • #13
                          I was wondering if anyone could post their altered Slope studies. I was also thinking of taking the slope of price (while in my Calc class, lol) and think that this could offer some great info.

                          For instance, when Slope gets to a certain X level, it could indicate a possible profit taking level as price has become overextended and is do for a pullback. Or as sometimes price has a slow steady grind up or down, (as on Thursday,ES prices continued upward steadily) it would be an indication that price may continue upward or downward until a higher slope angle is acheived before a significant pullback (profit taking) occurs. Something along those lines....


                          Thanks,
                          Duke

                          Comment


                          • #14
                            I'm not quite finished yet with mine. But when I'm done, I'll post it here.

                            How does one calculate the slope expressed in percentage terms?

                            Comment


                            • #15
                              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.

                              Chris

                              Comment

                              Working...
                              X