Announcement

Collapse
No announcement yet.

MACD + Signal Formel

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

  • MACD + Signal Formel

    hallo,
    which formel does eSignal use to calculate MACD, and the MACD Signal line?
    thanks,
    alen
    Last edited by Alen; 09-12-2005, 02:50 AM.

  • #2
    alen
    The Basic Studies version of the MACD can use either simple or exponential averages whereas the EFS2 version only uses exponential
    Alex

    Comment


    • #3
      Alexis
      I know that, but there are two different ways to calculate the k factor

      the one is 2/(days +1) and the other ... I just forgot
      so I would like to know which formula esignal exactly use.

      thanks,
      alen

      Comment


      • #4
        alen
        The formula for the exponential averages used to calculate the MACD and Signal lines is the same as the ema.efs that you can find in the Library folder of Formulas. In that formula the length which is expressed in periods is converted to a percentage value in line 29 using the equation dPercent = (2.0 / (nInputLength + 1.0));
        Alex

        Comment


        • #5
          alen
          As a note of interest here is a complete MACD formula written in efs2 using a slightly revised version of the ema.efs that is in the Library folder to compute all the exponential averages.
          In the image that follows you can see the plot returned by the script compared to that of the Basic Studies MACD set to use only exponential averages
          Alex

          PHP Code:
          var MACD null
          var SIG null;

          function 
          main(){
              if(
          MACD==nullMACD efsInternal("calcMACD",12,26,close());//creates a series of the MACD
              
          if(SIG==nullSIG efsInternal("calcEMA",9,MACD);//uses MACD series as input to calcEMA function
              
          if(MACD.getValue(0)==null||SIG.getValue(0)==null) return;
              return new Array (
          MACD.getValue(0),SIG.getValue(0));
          }

          var 
          xAvg1 null;
          var 
          xAvg2 null;
          //this section calculates the MACD (ie the difference between the exponential averages)
          function calcMACD(Length1,Length2,Source) {
              if(
          xAvg1 == nullxAvg1 efsInternal("calcEMA",Length1,Source);
              if(
          xAvg2 == nullxAvg2 efsInternal("calcEMA",Length2,Source);
              if(
          xAvg1.getValue(0)==null||xAvg2.getValue(0)==null) return;
              var 
          xMACD xAvg1.getValue(0)-xAvg2.getValue(0)
              return 
          xMACD;
          }
          //this section calculates the exponential moving averages used by the MACD
          //and Signal lines
          var dThisMA null;
          var 
          dLastMA null;
          var 
          dPercent 0.0;
          var 
          bPrimed false;

          function 
          calcEMA(nInputlength,source) {
              var 
          nBarState getBarState();
              var 
          dSum 0.0;
              if(
          nBarState == BARSTATE_ALLBARS) {
                  
          dPercent = (2.0/(nInputlength+1.0));
                  
          bPrimed false;
              }
              if(
          nBarState == BARSTATE_NEWBAR) {
                  
          dLastMA dThisMA;
              }
              if(
          bPrimed == false) {
                  for(var 
          i=0i<nInputlengthi++) {
                      if(
          getCurrentBarCount()<nInputlength) return;
                      
          dSum += source.getValue(-i);
                  }
                  
          bPrimed true;
                  
          dThisMA dSum/nInputlength;
                  
              } else {
                  
          dThisMA = ((source.getValue(0)-dLastMA)*dPercent)+dLastMA;
              }
              return 
          dThisMA;

          Comment

          Working...
          X