Announcement

Collapse
No announcement yet.

change MA into EMA

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

  • change MA into EMA

    Hi guys,

    A While ago I got this EFS studie that showed all bars above the SMA green and below the SMA red. It helps me visually to stay in a trade and use this MA as a sort of trailing stop.

    It is a simple moving average (SMA). I would like to use the Exponential Moving Average (EMA) as my trailing stop. I have tried to do some programming on my own, but failed misserably.

    My question is: Can someone help me change the code of this EFS study from SMA into EMA? The EFS study is attached to this post.

    Kind regards,

    thevinman

  • #2
    no attachment

    Comment


    • #3
      Oke I think I have attached it to this one.

      Kind regards

      thevinman
      Attached Files

      Comment


      • #4
        thevinman
        Replace this line of code in the script
        PHP Code:
        if (study == nullstudy = new MAStudy(maLength0"Close"MAStudy.SIMPLE); 
        with the following
        PHP Code:
        if (study == nullstudy = new MAStudy(maLength0"Close"MAStudy.EXPONENTIAL); 
        and save the script with a new name.
        The efs will then use an exponential average instead of the simple one
        Alex

        Comment


        • #5
          var v = ema(maLength); //study.getValue(MAStudy.MA);

          Comment


          • #6
            Thank you for such a quick reply, but should I change both (the var and the line) answers or just one of them?

            thevinman

            Comment


            • #7
              When in doubt, go with Alex.

              Happy New Year!

              Comment


              • #8
                I changed it and it worked. Thank you both.

                Happy new year!

                thevinman

                Comment


                • #9
                  Dave
                  Thanks for the vote of confidence and a Happy New Year to you too.

                  thevinman
                  You can use either one and the result would be the same. Implementing both would not cause any problems as the solution provided by David would override mine.
                  If you opt to use David's solution then you can also comment out (or delete) the following line of code as it would no longer be required
                  PHP Code:
                  if (study == nullstudy = new MAStudy(maLength0"Close"MAStudy.SIMPLE); 
                  To comment out a line of code insert two forward slashes // at the beginning of the line
                  Happy New Year also to you

                  Alex

                  Comment


                  • #10
                    EMA trailing stop

                    Hi Guys,

                    Thank you again for helping me out. I am using this EMA file as an trailing stop for my stock positions. I have attached the file, so that others could benefit from it, or at least to check it out.

                    It works like this. All bars above the EMA are green and all bars below the EMA are red. The EMA default is 10.
                    It helps me to stay longer in a position, because I don't react too fast on wiggles as the color of the bar stays the same.


                    Kind regards,

                    thevinman
                    Attached Files

                    Comment

                    Working...
                    X