Announcement

Collapse
No announcement yet.

McGinley Dynamic

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

  • McGinley Dynamic

    Has anyone seen the McGinley Dynamic Indicator floating around for eSig?

    McGinley Dynamic:
    Ref(Mov(C,12,E),-1)+((C-(Ref(Mov(C,12,E),-1))) / (C/(Ref(Mov(C,12,E),-1))*125))



    which I would think goes something like this:
    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("McGinley Dynamics");
        
    setCursorLabelName("McG_D"0);
        
    setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(1,0);
            
        var 
    fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(12);
        
        var 
    fp2 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);
        
    fp2.setLowerLimit(0);        
        
    fp2.setDefault(125);
        
        var 
    vMcGD null;

    }

    function 
    main(MALength,Smoothing) {

        var 
    i=0;
       
        
    McGD = (ema(MALengthclose(i-1))) + (close(i)- (ema(MALengthclose(i-1)))) / (close(i) / (ema(MALengthclose(i-1))*Smoothing));
            
        
        return 
    McGD;

    but my coding is not so hot, so I'm not quite sure what to do here.

  • #2
    Re: McGinley Dynamic

    AngusF
    The syntax of ema(MALength, close(i-1)) is invalid in as much as you are passing a value instead of a series to the ema() function.
    Furthermore you do not need to define close as the source as this is the default unless another series is passed as a source
    In Metastock the Ref() function is used to call the prior value of a study so you can simply use ema(12,-1) where -1 references the prior value of the study. As I explained above close() is unnecessary as it is implied by default.
    In its most basic form the equation for the McGinley as you posted it would then be as shown in the following screenshot



    I would suggest that you review the syntax and examples provided in this article of the EFS KnowledgeBase regarding the Moving Average functions. Also see this thread for a complete set of examples on the usage of efs2 functions.
    Alex


    Originally posted by Angus F
    Has anyone seen the McGinley Dynamic Indicator floating around for eSig?

    McGinley Dynamic:
    Ref(Mov(C,12,E),-1)+((C-(Ref(Mov(C,12,E),-1))) / (C/(Ref(Mov(C,12,E),-1))*125))



    which I would think goes something like this:
    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("McGinley Dynamics");
        
    setCursorLabelName("McG_D"0);
        
    setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(1,0);
            
        var 
    fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(12);
        
        var 
    fp2 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);
        
    fp2.setLowerLimit(0);        
        
    fp2.setDefault(125);
        
        var 
    vMcGD null;

    }

    function 
    main(MALength,Smoothing) {

        var 
    i=0;
       
        
    McGD = (ema(MALengthclose(i-1))) + (close(i)- (ema(MALengthclose(i-1)))) / (close(i) / (ema(MALengthclose(i-1))*Smoothing));
            
        
        return 
    McGD;

    but my coding is not so hot, so I'm not quite sure what to do here.

    Comment


    • #3
      Re: Re: McGinley Dynamic

      Hi Alexis,
      Yet again you were immensely helpful, thank you.

      I do have one question though:
      When I add "colour coding" for up and down, I don't get any output. Maybe you have some advice.

      Thanks again,
      Angus.
      PHP Code:
      /* McGinley Dynamic */



      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("McGinley Dynamics");
          
      setCursorLabelName("McG_D"0);
          
      setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
          
      setDefaultBarFgColor(Color.red0);
          
      setDefaultBarThickness(2,0);
              
           var 
      fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
          
      fp1.setLowerLimit(1);        
          
      fp1.setDefault(12);
          
          var 
      nMcGD null;

      }

      function 
      main (MALength) {
            
          
      nMcGD ema(MALength,-1) + (  (close(0)- (ema(MALength,-1))) / ((close(0)) / (ema(MALength,-1))*125));

          

          
           if (
      nMcGD.getValue(0) >= nMcGD.getValue(-1)) {
               
      setDefaultBarFgColor(Color.lime,0);
           } else if (
      nMcGD.getValue(0) < nMcGD.getValue(-1) {
               
      setDefaultBarFgColor(Color.red,0);
           }
          
                   
          return 
      nMcGD;




      Originally posted by Alexis C. Montenegro
      AngusF
      The syntax of ema(MALength, close(i-1)) is invalid in as much as you are passing a value instead of a series to the ema() function.
      Furthermore you do not need to define close as the source as this is the default unless another series is passed as a source
      In Metastock the Ref() function is used to call the prior value of a study so you can simply use ema(12,-1) where -1 references the prior value of the study. As I explained above close() is unnecessary as it is implied by default.
      In its most basic form the equation for the McGinley as you posted it would then be as shown in the following screenshot



      I would suggest that you review the syntax and examples provided in this article of the EFS KnowledgeBase regarding the Moving Average functions. Also see this thread for a complete set of examples on the usage of efs2 functions.
      Alex

      Comment


      • #4
        Re: Re: Re: McGinley Dynamic

        Angus
        The variable nMcGD is not a series but a single value hence you cannot use the getValue() method of the series object to retrieve its values.
        See this post for some examples on how to access prior values of a variable that is not a series
        Alex


        Originally posted by Angus F
        Hi Alexis,
        Yet again you were immensely helpful, thank you.

        I do have one question though:
        When I add "colour coding" for up and down, I don't get any output. Maybe you have some advice.

        Thanks again,
        Angus.
        PHP Code:
        /* McGinley Dynamic */



        function preMain() {
            
        setPriceStudy(true);
            
        setStudyTitle("McGinley Dynamics");
            
        setCursorLabelName("McG_D"0);
            
        setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
            
        setDefaultBarFgColor(Color.red0);
            
        setDefaultBarThickness(2,0);
                
             var 
        fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
            
        fp1.setLowerLimit(1);        
            
        fp1.setDefault(12);
            
            var 
        nMcGD null;

        }

        function 
        main (MALength) {
              
            
        nMcGD ema(MALength,-1) + (  (close(0)- (ema(MALength,-1))) / ((close(0)) / (ema(MALength,-1))*125));

            

            
             if (
        nMcGD.getValue(0) >= nMcGD.getValue(-1)) {
                 
        setDefaultBarFgColor(Color.lime,0);
             } else if (
        nMcGD.getValue(0) < nMcGD.getValue(-1) {
                 
        setDefaultBarFgColor(Color.red,0);
             }
            
                     
            return 
        nMcGD;

        Comment


        • #5
          Alex,

          This is the way I interpreted the ref() function, but it still seems to be giving me headaches.
          Thank you,
          Angus.

          I hope I'm not giving you a headache with all these petty questions?

          PHP Code:

          /* McGinley Dynamic */

          var bInit false;
          var 
          BarCntr 0;

          function 
          preMain() {
              
          setPriceStudy(true);
              
          setStudyTitle("McGinley Dynamics");
              
          setCursorLabelName("McG_D"0);
              
          setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
              
          setDefaultBarFgColor(Color.red0);
              
          setDefaultBarThickness(2,0);
                  
               var 
          fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
              
          fp1.setLowerLimit(1);        
              
          fp1.setDefault(12);
              
              var 
          nMcGD null;
              

          }

          function 
          main (MALength) {

              var 
          nGD;
              var 
          npGD;
              var 
          myRef;
              
              if (
          bInit == false) {      
              
          nMcGD ema(MALength,-1) + (  (close(0)- (ema(MALength,-1))) / ((close(0)) / (ema(MALength,-1))*125));
              
          bInit true;
              }
              
              
          nGD nMcGD.getValue(0);
              
              if (
          getBarState() == BARSTATE_NEWBAR) {
                 
          BarCntr +=1;
          }      
              if (
          BarCntr MALength) {
              
              
          myRef ref(-1);
              if (
          myRef != null) {
                
          npGD myRef[0];
                }
          }      
              
             if (
          nGD >= npGD) {
                  
          setDefaultBarFgColor(Color.lime,0);
             } else if (
          nGD npGD) {
                  
          setDefaultBarFgColor(Color.red,0);
             }
              
                       
              return 
          nMcGD;

          Comment


          • #6
            Angus
            There are several errors in your script.
            - remove the entire bInit routine that encloses the calculation of the nMcGD variable. Anything contained in that routine will execute one time only when the formula is loaded [or reloaded]. The nMcGD variable instead needs to be calculated on every iteration of the efs
            - delete line 34 ie nGD = nMcGD.getValue(0); as it is invalid. As I explained in my previous reply the variable nMcGD is not a series but a value and specifically the current value of the indicator. So use this variable name in your conditions and not nGD
            - remove lines 42 to 44 (included) as they are unnecessary. myRef is the previous value of your indicator so use that in your conditions and not npGD
            Once you make these changes the formula will work
            Alex


            Originally posted by Angus F
            Alex,

            This is the way I interpreted the ref() function, but it still seems to be giving me headaches.
            Thank you,
            Angus.

            I hope I'm not giving you a headache with all these petty questions?

            PHP Code:

            /* McGinley Dynamic */

            var bInit false;
            var 
            BarCntr 0;

            function 
            preMain() {
                
            setPriceStudy(true);
                
            setStudyTitle("McGinley Dynamics");
                
            setCursorLabelName("McG_D"0);
                
            setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
                
            setDefaultBarFgColor(Color.red0);
                
            setDefaultBarThickness(2,0);
                    
                 var 
            fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
                
            fp1.setLowerLimit(1);        
                
            fp1.setDefault(12);
                
                var 
            nMcGD null;
                

            }

            function 
            main (MALength) {

                var 
            nGD;
                var 
            npGD;
                var 
            myRef;
                
                if (
            bInit == false) {      
                
            nMcGD ema(MALength,-1) + (  (close(0)- (ema(MALength,-1))) / ((close(0)) / (ema(MALength,-1))*125));
                
            bInit true;
                }
                
                
            nGD nMcGD.getValue(0);
                
                if (
            getBarState() == BARSTATE_NEWBAR) {
                   
            BarCntr +=1;
            }      
                if (
            BarCntr MALength) {
                
                
            myRef ref(-1);
                if (
            myRef != null) {
                  
            npGD myRef[0];
                  }
            }      
                
               if (
            nGD >= npGD) {
                    
            setDefaultBarFgColor(Color.lime,0);
               } else if (
            nGD npGD) {
                    
            setDefaultBarFgColor(Color.red,0);
               }
                
                         
                return 
            nMcGD;

            Comment


            • #7
              Alex,

              You are a legend, thank you so much, that's perfect!!!

              Angus.

              Here's the code:

              PHP Code:
              /* McGinley Dynamic */

              var BarCntr 0;

              function 
              preMain() {
                  
              setPriceStudy(true);
                  
              setStudyTitle("McGinley Dynamics");
                  
              setCursorLabelName("McG_D"0);
                  
              setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
                  
              setDefaultBarFgColor(Color.red0);
                  
              setDefaultBarThickness(2,0);
                      
                   var 
              fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
                  
              fp1.setLowerLimit(1);        
                  
              fp1.setDefault(12);
                  
                  var 
              nMcGD null;
              }

              function 
              main (MALength) {    
                  var 
              myRef;
                           
                  
              nMcGD ema(MALength,-1) + (  (close(0)- (ema(MALength,-1))) / ((close(0)) / (ema(MALength,-1))*125));
                      
                  if (
              getBarState() == BARSTATE_NEWBAR) {
                     
              BarCntr +=1;
              }      
                  if (
              BarCntr MALength) {    
                  
              myRef ref(-1);      
              }          
                 if (
              nMcGD >= myRef) {
                      
              setDefaultBarFgColor(Color.lime,0);
                 } else if (
              nMcGD myRef) {
                      
              setDefaultBarFgColor(Color.red,0);
                 }
                              
                  return 
              nMcGD;

              Comment


              • #8
                "I created this in 1990 and it was published in the Market Technician's Assn Journal in
                Summer 1997. I can e-mail you the pages of that article. The equation is:
                D = D1 + (I - D1) / ( N * (I/D1)^4)
                where D1 = yesterday's Dynamic, I = today's price, N = smoothing factor.
                If you want the indicator to fit as closely as, say, a 20da MA, make N = 60% of 20.
                Larger fits more loosely, stays out of consolidations longer.
                This automatically speeds up when the market does and vice versa."

                The above was written by the author of the indicator, and seems to my layman's interpretation that the formula uses the previous bars indicator value in it's calculation, whereas the example here uses the ema as a basis for each new calculation. What effect does this have on the result? My feeble attempts at recoding have been unsuccessful.

                This indicator is a great find as presented here by Angus, and any improvement would make it more so.

                Cheers

                Merv

                Comment


                • #9
                  Angus
                  You are welcome
                  Alex


                  Originally posted by Angus F
                  Alex,

                  You are a legend, thank you so much, that's perfect!!!

                  Angus.

                  Here's the code:

                  PHP Code:
                  /* McGinley Dynamic */

                  var BarCntr 0;

                  function 
                  preMain() {
                      
                  setPriceStudy(true);
                      
                  setStudyTitle("McGinley Dynamics");
                      
                  setCursorLabelName("McG_D"0);
                      
                  setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
                      
                  setDefaultBarFgColor(Color.red0);
                      
                  setDefaultBarThickness(2,0);
                          
                       var 
                  fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
                      
                  fp1.setLowerLimit(1);        
                      
                  fp1.setDefault(12);
                      
                      var 
                  nMcGD null;
                  }

                  function 
                  main (MALength) {    
                      var 
                  myRef;
                               
                      
                  nMcGD ema(MALength,-1) + (  (close(0)- (ema(MALength,-1))) / ((close(0)) / (ema(MALength,-1))*125));
                          
                      if (
                  getBarState() == BARSTATE_NEWBAR) {
                         
                  BarCntr +=1;
                  }      
                      if (
                  BarCntr MALength) {    
                      
                  myRef ref(-1);      
                  }          
                     if (
                  nMcGD >= myRef) {
                          
                  setDefaultBarFgColor(Color.lime,0);
                     } else if (
                  nMcGD myRef) {
                          
                  setDefaultBarFgColor(Color.red,0);
                     }
                                  
                      return 
                  nMcGD;

                  Comment


                  • #10
                    /*
                    "I created this in 1990 and it was published in the Market Technician's Assn Journal in
                    Summer 1997. I can e-mail you the pages of that article. The equation is:
                    D = D1 + (I - D1) / ( N * (I/D1)^4)
                    where D1 = yesterday's Dynamic, I = today's price, N = smoothing factor.
                    If you want the indicator to fit as closely as, say, a 20da MA, make N = 60% of 20.
                    Larger fits more loosely, stays out of consolidations longer.
                    This automatically speeds up when the market does and vice versa."

                    The above was written by the author of the indicator, and seems to my layman's interpretation that the formula uses the previous bars indicator value in it's calculation, whereas the example here uses the ema as a basis for each new calculation. What effect does this have on the result? My feeble attempts at recoding have been unsuccessful.

                    This indicator is a great find as presented here by Angus, and any improvement would make it more so.

                    Cheers

                    Merv
                    */

                    Hi,
                    I tried to create a code that is more faithful to the original formula. It is not a masterpiece of style, but seems to do its job.
                    Putting on a graph the first version and my version does not seem to differ greatly from a simple ema.
                    It seems to me that there is something wrong in the formula.
                    Any idea or suggestion is welcome.
                    Greetings.
                    Massimo

                    /* McGinley Dynamic */

                    var BarCntr = 0;

                    function preMain() {
                    setPriceStudy(true);
                    setStudyTitle("McGinley Dynamics");
                    setCursorLabelName("McG_D", 0);
                    //setPlotType(PLOTTYPE_INSTANTCOLORLINE, 0);
                    setDefaultBarFgColor(Color.red, 0);
                    setDefaultBarThickness(2,0);

                    var fp1 = new FunctionParameter("MALength", FunctionParameter.NUMBER);
                    fp1.setLowerLimit(1);
                    fp1.setDefault(12);

                    var nMcGD = null;
                    var nMcGD_1 = null;
                    }

                    function main (MALength) {
                    if (getBarState()==BARSTATE_NEWBAR) {
                    BarCntr=BarCntr+1;
                    debugPrintln("BarCntr "+BarCntr);
                    if (BarCntr<MALength) return;
                    if (BarCntr==MALength) {
                    nMcGD=ema(MALength).getValue(0);
                    debugPrintln("BarCntr==MALength "+BarCntr+" EMA "+nMcGD);
                    }
                    nMcGD_1=nMcGD;
                    debugPrintln("EMA-1 "+nMcGD_1);
                    }
                    if (BarCntr>MALength) {
                    nMcGD=nMcGD_1+((close(0)-nMcGD_1)/(Math.floor(0.6*MALength)*Math.pow((close(0)/nMcGD_1),4)));
                    //if (nMcGD==null) return;
                    if (nMcGD >= nMcGD_1) {
                    setDefaultBarFgColor(Color.lime,0);
                    } else if (nMcGD < nMcGD_1) {
                    setDefaultBarFgColor(Color.red,0);
                    }

                    return nMcGD;
                    }
                    }

                    Comment

                    Working...
                    X