Announcement

Collapse
No announcement yet.

ongoing MACD problem

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

  • ongoing MACD problem

    I have been investigating the bad MACD issue for a while since I primarily trade off MACD. I became a subscriber in early august and could tell that the formula was off from just watching it, and upon comparison to a different charting program, my suspicions were proved correct. Following up on this issue in the yahoogroups archives, this problem has been addressed by various individuals since at least March of this year, but never fixed. By the time I studied up on EFS and _javascript and then had a free weekend to take a closer look at the formulas...

    The MACD formula which comes in Esig does not compute correctly. My observations and tests show that the macd component of MACD is always correct but not the signal portion, whether using the esignal macd or the builtin formulas version; however, using a formula that uses the MAStudy (ema) formulas within esignal to create both the macd and the signal calculations, or if a formula performs the calculations from scratch,
    the formula has to be reloaded constantly to show the proper output.
    One of the top programmers pointed out that the (builtin) MACDStudy has an input parameter which, true or false, utilizes a simple or exponential MA. Using the 'false' input (thereby allegedly using EMAs for the formula as opposed to SMAs) for the MA parameter in the builtin formulas DOES NOT properly calculate
    the signal line; the builtin (when set to false for EMAs) returns the same WRONG signal line (and therefore histogram) as does the regular (esignal 'internal') MACD formula. Using "true" for that
    parameter does seem to use SMAs in its calculations and the output seems correct. The MACDfast and MACDslow formulas seem to be based on SMAs so they dont help and there does not seem to be a way to force EMAs. The results for these formulas match the builtin MACD formula when 'true' for SMAs.

    The esignal ('internal') MACD formula needs to be corrected to properly return the (EMA) signal line.

    Ultimately my point is that there is no way to force esignal to generate a proper MACD (signal and histogram) without having to concoct another formula which has to be refreshed constantly to show the proper values.

    I have attached a shot of a ES 5 (including overnight) minute chart (as well as the efs). The top formula is internal MACD, the second is the builtin with 'false' for EMAs, the third is a formula by Garth from back in March (thank you Garth) built from scratch, the fourth is my concoction of MAStudy.exponential's with
    histogram language thrown in. The only thing I changed was the histogram color to be more eye-friendly so you can see the output numbers in the cursor window. Compare the histograms in the cursor window, and then look at the last outputs in the chart itself (yes it is for the prior 5 minute bar to show you what the
    correct MACD values should be on MACD-3 - I couldnt keep reloading and get an accurate value all in the same picture and I wanted you to see how the formula built from scratch (Garth's MACD-2) gets mangled without a reload). The MACD-2 and MACD-3 values are the same on reloads.

    I'm very surprised that given the fact that this issue has been raised a number of times (albeit sporadically) over time that there has been no attempt to look into this issue further.

    And of course please do not dismiss this as the rantings of some stupid broad. I suspect that other formulas (was it a bressert formula? and an adaptive AMA?) which are problematic may be tied into related incorrectly programmed 'internal' formulas.

    Christine (sorry about the following formating)

    builtin MACD
    Code:
    This sample eSignal Formula Script (EFS) may be modified and saved under a new 
    filename; however, eSignal is no longer responsible for the functionality once modified.
    eSignal reserves the right to modify and overwrite this EFS file with each new release.
    *****************************************************************************************************/
    var study = new MACDStudy(12, 26, 9, "Close", false);
    
    function preMain() {
        setDefaultBarFgColor(Color.green, 0); // hist
        setDefaultBarFgColor(Color.blue, 1); // signal
        setDefaultBarFgColor(Color.red, 2); // macd
        
        setPlotType(PLOTTYPE_HISTOGRAM, 0);
    }
    
    function main() {
        var vMACD = study.getValue(MACDStudy.MACD);
        var vSignal = study.getValue(MACDStudy.SIGNAL);
        var vHist = study.getValue(MACDStudy.HIST);
        
        return new Array(vHist, vMACD, vSignal);
    }
    
    
                                           macd2
    function preMain() {
        /* Set the title that will appear in the study pane */
        setStudyTitle("MACD-2");
    
        /* Set the label that will appear in the cursor window */
        setCursorLabelName("Fast", 0);
        setCursorLabelName("Signal", 1);
        setCursorLabelName("Histogram", 2);
    
        setDefaultBarStyle(PS_SOLID, 0);
        setDefaultBarStyle(PS_SOLID, 1);
        setDefaultBarStyle(PS_SOLID, 2);
        
        setPlotType(PLOTTYPE_LINE, 0);
        setPlotType(PLOTTYPE_LINE, 1);
        setPlotType(PLOTTYPE_HISTOGRAM, 2);
    	// setDefaultBarStyle(PS_SOLID);
    	// setDefaultBarThickness(1);
    	
    	setDefaultBarThickness(1, 0);
    	setDefaultBarThickness(1, 1);
    	setDefaultBarThickness(1, 2);
    	
    	setDefaultBarFgColor(Color.red, 1);
    	setDefaultBarFgColor(Color.blue, 0);
    }
    
    var vLastMac = 0.0;
    var dFPercent = 0.0;
    var dSPercent = 0.0;
    var dSMPercent = 0.0;
    var vMacdF = 0.0;
    var vMacdS = 0.0;
    var vSmoothingSum = 0.0;
    var bPrimed = false;
    
    function main(nInputF, nInputS, nInputSmoothing) {
        if(nInputF == null)
            nInputF = 12;
        if(nInputS == null)
            nInputS = 26;
        if(nInputSmoothing == null)
            nInputSmoothing = 9;
    
        var i, j;  
        var vValue;	
        var nCount = 0;
        var vSumF = 0.0;
        var vSumS = 0.0;
    	
    	var vMac;
    
        var nBarState = getBarState();
        
        if(nBarState == BARSTATE_ALLBARS) {
    		// reset!
    		dSPercent = (2.0 / (nInputS + 1.0));
    		dFPercent = (2.0 / (nInputF + 1.0));
    		dSMPercent = (2.0 / (nInputSmoothing + 1.0));
    		vSmoothingSum = 0.0;
    		vSumF = 0.0;
            vSumS = 0.0;	
    	}
    	
    	
    	if (bPrimed == false){
            vValue = getValue("Close", 0, -(Math.max(nInputS, nInputF)+nInputSmoothing));
            if(vValue == null)
                return;
                
            for(j = 0; j < nInputSmoothing; j++) {
                nCount = 0;
                vSumF = 0.0;
                vSumS = 0.0;
    
                for(i = 0; i < nInputS; i++) {
                    v = vValue[i+j];
                    if(nCount < nInputF)
                        vSumF += v;
                    vSumS += v;
                    nCount++;
                }
                vSumF /= nInputF;
                vSumS /= nInputS;
                vSmoothingSum += (vSumF - vSumS);
                if(j == 0) {
                    vMacdF = vSumF;
                    vMacdS = vSumS;
                }
                
            }
            vSmoothingSum /= nInputSmoothing;
            bPrimed = true;   
        } else {
           if ((vValue = getValue("Close")) == null){
               return;
           }
           vMacdF =  ((vValue - vMacdF) * dFPercent) + vMacdF;
           vMacdS = ((vValue - vMacdS) * dSPercent) + vMacdS;
           vSmoothingSum = (((vMacdF - vMacdS) - vSmoothingSum) * dSMPercent) + vSmoothingSum;
        }  
        
        vMac = (vMacdF-vMacdS) - vSmoothingSum;
        if (vLastMac > vMac){
            setBarFgColor(Color.red,2);
        } else {
            setBarFgColor(Color.green,2);
        }
        vLastMac = vMac;
    	return new Array(vMacdF - vMacdS, vSmoothingSum, vMac); // Fast, Slow, Histogram
    }
    
    
    
    
    
    
                                                         macd3
     /******************/
     var slow = new MAStudy(26, 0, "Close", MAStudy.EXPONENTIAL);
     var fast = new MAStudy(12, 0, "Close", MAStudy.EXPONENTIAL);
     function preMain() {
     
     setStudyTitle("MACD");
     
     
     setCursorLabelName("Fast", 0);
     setCursorLabelName("Signal", 1);
     setCursorLabelName("Hist", 2);
     setDefaultBarFgColor(Color.red, 1);
     setDefaultBarFgColor(Color.blue, 0);
     setDefaultBarFgColor(Color.green,2);
     setPlotType(PLOTTYPE_HISTOGRAM, 2);
     }
     
     var XA_1 = 0;
     var vHIST = 0.0;
     function main(nSignal) {
     
     if (nSignal == null)
     nSignal = 9;
     
    
     var HIST;
     var K = 2 / (nSignal + 1);
     var MACD = fast.getValue(MAStudy.MA) - slow.getValue
     (MAStudy.MA);
     var XA = K * MACD + (1 - K) * XA_1;
     var HIST = MACD - XA
    
     if (getBarState() == BARSTATE_NEWBAR)
     XA_1 = XA;
     
     vHIST = HIST
     return new Array(MACD,XA,HIST);
     }
     
     /******************/
    Attached Files

  • #2
    Re: Reply to post 'ongoing MACD problem'

    Thanks for the info Christineesq. I'll check this out tonite.
    m.

    --- eSignal Bulletin Board Mailer <[email protected]> wrote:
    > Hello mattgundersen,
    >
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    >
    Matt Gundersen

    Comment


    • #3
      I checked it out...

      Currently the signal is always computed using a simple MA. In the next version of eSignal, there will be a new option that allows the signal to be computed using a simple MA (the default) or an exponential MA.

      Will that solve the problem?

      m.
      Matt Gundersen

      Comment


      • #4
        Matt,

        I suggest you have the default EMA, as that is what most people expect MACD to use. If you want to keep it simple for historical (to advanced charts) reasons, I would make you you document it very well.
        Garth

        Comment


        • #5
          Re: Reply to post 'ongoing MACD problem'

          Hey Garth, the problem I foresee in making the default EMA is that there are
          many others with advanced charts using the MACD as it has been working since
          the inception of Advanced Charts. That is using the simple MA for the signal
          line. If the default now becomes MA, their MACDs won't function as they are
          accustomed.

          However, if someone wants to make the signal line an EMA by default, they can
          edit the MACD study settings and do a set as default for the study settings.

          m.


          --- eSignal Bulletin Board Mailer <[email protected]> wrote:
          > Hello mattgundersen,
          >
          > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          >
          Matt Gundersen

          Comment


          • #6
            Right, that's what I was saying...though compatibility rather than historical might have been the better term for me to use.

            Again, if this is the tact you take, I would recommend documenting it very well.
            Garth

            Comment

            Working...
            X