Announcement

Collapse
No announcement yet.

Exponential Moving Averages

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

  • Exponential Moving Averages

    I would be extremely greatful if someone would explain to me EXACTLY how to calculate exponential moving averages EXACTLY the same way esignal does. I have found several different formulas in various books but none of them produce the exact same results as are produced by esignal.

    Thanks !
    Gene Martin
    InfoLogic

  • #2
    This works for me and gives me the same line as the builtin study.

    function main(nPeriod) {
    if (nPeriod == null) nPeriod = 20;

    var x1 = 2 / (nPeriod + 1);
    var x2 = 1 - x1;

    return (x1 * close()) + (x2 * ref(-1));
    }

    Comment


    • #3
      Actually, I guess that should be altered a bit so that it deals with the first bars in the series better. I'm using ref() here, but you could store that previous value in a variable or other such method.

      function main(nPeriod) {
      if (nPeriod == null) nPeriod = 20;

      var x1 = 2 / (nPeriod + 1);
      var x2 = 1 - x1;
      var prevVal = ref(-1) == null ? close() : ref(-1);

      return (x1 * close()) + (x2 * prevVal);
      }

      Comment

      Working...
      X