Announcement

Collapse
No announcement yet.

Making a MACD with t3 averages

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making a MACD with t3 averages

    Hello,

    I have been using Alex's T3 ma functions in an ma crossover efs, to gain an extra bar on the crossing of the MA's I have been trying to make a MACD type indicator from these MA's.

    I am using a cheat for a signal line at present (value for prev bar), but would like to use an MA, is there anyway to make an ema of the difference, using a series of the difference.

    Thanks in advance.

    Paul Murray.

    here is current efs.
    Attached Files

  • #2
    Already have a version using t3 averages coded in loops.
    Attached Files

    Comment


    • #3
      Paul
      There are several ways this could be done One of them is to use the efsInternal() function to pass the two series to a separate function in which you calculate the difference between their values. The efsInternal() function then returns a series which you can use as a source for the ema function. This process is explained in detail in this post which you may want to review. The only difference is that in that example I use efsExternal() instead of efsInternal().
      The enclosed revision of your efs includes comments with regards to the changes made
      Alex

      PHP Code:
      //Alexis C. Montenegro © January 2005                       
      //Use and/or modify this code freely. If you redistribute it
      //please include this and/or any other comment blocks and a 
      //description of any changes you make.   

      //Paul Murray
      //Making a MACD type indicator from a cross of T3 moving averages

      //ACM - Modified original to create a MACD with Signal line

      // NOTE:                                                                          
      // This efs requires amStudies.efsLib in the FunctionLibrary folder.              
      // If you do not have this file you can download it at the link below.            
      //http://share.esignal.com/groupcontents.jsp?folder=Formulas-Libraries&groupid=10

      var fpArray = new Array();

      var 
      lastrawtime 0;
      var 
      BarCount 0;

      var 
      grID 0;  

      function 
      preMain() {

          
      setPriceStudy(false);
          
      setStudyTitle("T3 MA 3,5 cross MACD");
          
      setCursorLabelName("T3_1",0);
          
      setCursorLabelName("T3_2",1); 
          
      setCursorLabelName("T3_3",2);    
          
      setDefaultBarFgColor(Color.blue,0);
          
      setDefaultBarFgColor(Color.red,1); 
          
      setPlotType(PLOTTYPE_LINE,0);
          
      setPlotType(PLOTTYPE_INSTANTCOLORLINE,1);
          
      setDefaultBarThickness(2,0);
          
      setDefaultBarThickness(2,1);   
       
      //    askForInput();
       
          
      addBand(0PS_DASH3Color.black);     

                 
          var 
      x=0;
          
      fpArray[x] = new FunctionParameter("Length1"FunctionParameter.NUMBER);
       
      with(fpArray[x++]){
              
      setLowerLimit(1);  
              
      setDefault(5);
          }
          
      fpArray[x] = new FunctionParameter("Length2"FunctionParameter.NUMBER);
       
      with(fpArray[x++]){
              
      setLowerLimit(1);  
              
      setDefault(3);
          }      
          
      fpArray[x] = new FunctionParameter("Factor"FunctionParameter.NUMBER);
       
      with(fpArray[x++]){
              
      setUpperLimit(1); 
              
      setLowerLimit(0);  
              
      setDefault(0.7);
          }
       
      fpArray[x] = new FunctionParameter("Source"FunctionParameter.STRING);
       
      with(fpArray[x++]){
              
      addOption("open"); 
              
      addOption("high");
              
      addOption("low");
              
      addOption("close");
              
      addOption("hl2");
              
      addOption("hlc3");
              
      addOption("ohlc4"); 
              
      setDefault("close"); 
          }
       
      fpArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
          
      with(fpArray[x++]){
              
      setDefault();
       }
       
      fpArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
       
      with(fpArray[x++]){
              
      setDefault();
          }
          
      fpArray[x] = new FunctionParameter("Offset"FunctionParameter.NUMBER);
       
      with(fpArray[x++]){
              
      setDefault(0);
          }
          
      fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
       
      with(fpArray[x++]){
              
      setName("Show Parameters");
              
      setDefault(false);
          }
       
      fpArray[x] = new FunctionParameter"Linecolor1"FunctionParameter.COLOR);
       
      withfpArray[x] ) {
        
      setDefaultColor.blue );
       }      
       
      fpArray[x] = new FunctionParameter"Linecolor2"FunctionParameter.COLOR);
       
      withfpArray[x] ) {
        
      setDefaultColor.red );
       }  
       
      fpArray[x] = new FunctionParameter"Alerts"FunctionParameter.NUMBER);
       
      withfpArray[x] ) {
              
      setUpperLimit(2); 
              
      setLowerLimit(1);
        
      setDefault(2);
       }   
      }

      var 
      amLib addLibrary("amStudies.efsLib");

      var 
      bInit false;
      //var xT3 = null;//removed by ACM
      var xT31 null;//added by ACM - was missing
      var xT32 null;//added by ACM - was missing
      var xMACD null;//added by ACM
      var xSig  null;//added by ACM

      var vLastAlert = -1;
      var 
      vLastxAlert = -1;
      var 
      vLastaAlert = -1;

      //var macd=0;//removed by ACM

      function main(Length1Length2FactorSourceSymbolIntervalOffsetParamsLinecolor1Linecolor2Alerts) {

          if(
      bInit == false){
              
      withamLib ) {
              if(
      Symbol == nullSymbol getSymbol();
              if(
      Interval == nullInterval getInterval();
              var 
      vSymbol Symbol+","+Interval;
              
      xT31 offsetSeries(amT3(Length1Factor, eval(Source)(sym(vSymbol))), Offset);
              
      xT32 offsetSeries(amT3(Length2Factor, eval(Source)(sym(vSymbol))), Offset);
              
      xMACD efsInternal("calcMACD"xT31xT32); //added by ACM
              
      xSig ema(3xMACD); //added by ACM - replace 3 with other value or variable
              
      setShowTitleParameters(eval(Params));
              
      setDefaultBarFgColorLinecolor1);
              
      setDefaultBarFgColorLinecolor2);
              
      bInit true;
              }
          }

          var 
      x1 getSeries(xMACD); //modified by ACM - was missing var
          
      var x2 getSeries(xSig); //modified by ACM - was missing var
        
          //F_1=xT31.getValue(-1); //removed by ACM
          //F_2=xT32.getValue(-1); //removed by ACM
        
          //macd=x2-x1;//removed by ACM
          //sig=F_2-F_1;//removed by ACM
          
          
      return new Array(x1,x2);
      }
        
      function 
      gID() {
          
      grID ++;
          return( 
      grID );
      }
      //function added by ACM
      function calcMACD(avg1,avg2){
          if(
      avg1.getValue(0)==null || avg2.getValue(0)==null) return;//null check
          
      return (avg2.getValue(0) - avg1.getValue(0));
      }
      //end function 

      Comment


      • #4
        Thanks Alex,

        thats great, I shall now have to create some more t3 indicators to see if I can get it to work for me.

        Paul.

        Comment


        • #5
          "The only difference is that in that example I use efsExternal() instead of efsInternal()."

          What is the reason you used efsExternal() instead of efsInternal()?

          Comment


          • #6
            Paul
            You are most welcome

            buzzhorton
            As I explain in that thread I used efsExternal() to illustrate how to create a study by combining multiple EFSs. Here is an excerpt from the thread:
            "In this example I will be showing how we can use the efsExternal() function to combine multiple EFSs to create an indicator. Some of the advantages to using the efsExternal() function instead of merging the separate EFS into a single script are that we are less likely to introduce logic or syntax errors due to naming of the variables, incorrect placement of the code, etc and more importantly that it is easier to write the script."

            Alex

            Comment


            • #7
              Have added a Histogram and some color, will post a piccie.

              I think efsexternal can wait for a while, I'm having enough fun with efsinternal.

              Paul.

              Comment


              • #8
                Here it is:
                Attached Files

                Comment


                • #9
                  Hello again,

                  have put bollinger bands around the t3 MACD (I love to play with efs).

                  the results are shown here

                  http://share.esignal.com/groupconten...ng&groupid=860

                  They are currently being done with loops for the MA and the standard dev.

                  I would like to use efs2 and efsinternal, but I get errors (incorrect argument comes up in a window - not written to the efs debugger) and a crash not long after the message is shown.

                  the code I have added is:

                  PHP Code:
                   xSig ema(3xMACD); //ACM added - replace 3 with other value or variable
                  xBBm middleBB(202xMACD);
                  xBBu upperBB(202xMACD);
                  xBBl lowerBB(202xMACD); 
                  followed by

                  PHP Code:
                  var x3 getSeries(xBBu); 
                  var 
                  x4 getSeries(xBBm); 
                  var 
                  x5 getSeries(xBBl); 
                  any ideas?

                  Paul.

                  Comment


                  • #10
                    Paul
                    I can duplicate the problem and am looking into it. Once I have some information I will post it here
                    Alex

                    Comment


                    • #11
                      Hi Alex,

                      this is a tricky one, I thought I had done something wrong, glad you can reproduce it, but the BB middle line is only an MA, and the code already uses an MA via efsinternal for the signal line.

                      Paul.

                      Comment


                      • #12
                        Paul
                        From what I can see the problem is caused by the Bollinger functions when these are used with certain series. I have passed on this information to eSignal's developers.
                        In the mean time you can use the enclosed revision of your script which offers a workaround I have come up with to resolve the issue.
                        Given that the Bollinger functions seem to accept without problems a moving average as the source I have added a 1 period simple moving average (ie xTemp) to act as a proxy for the xMACD series. At that point all the Bollinger functions can use xTemp as the source without causing any problems. Comments on the changes are included in the script.
                        Alex

                        PHP Code:
                        //Alexis C. Montenegro © January 2005                       
                        //Use and/or modify this code freely. If you redistribute it
                        //please include this and/or any other comment blocks and a 
                        //description of any changes you make.   
                         
                        //Paul Murray
                        //Making a MACD type indicator from a cross of T3 moving averages
                         
                        //ACM - Modified original to create a MACD with Signal line
                        //ACM - Added BB with temporary workaround
                         
                        // NOTE:                                                                          
                        // This efs requires amStudies.efsLib in the FunctionLibrary folder.              
                        // If you do not have this file you can download it at the link below.            
                        //http://share.esignal.com/groupcontents.jsp?folder=Formulas-Libraries&groupid=10
                         
                        var fpArray = new Array();
                         
                        var 
                        lastrawtime 0;
                        var 
                        BarCount 0;
                         
                        var 
                        grID 0;  
                         
                        function 
                        preMain() {
                         
                            
                        setPriceStudy(false);
                            
                        setStudyTitle("T3 MA 3,5 cross MACD");
                            
                        setCursorLabelName("T3_1",0);
                            
                        setCursorLabelName("T3_2",1); 
                            
                        setCursorLabelName("T3_3_BBu",2); //added by ACM
                            
                        setCursorLabelName("T3_3_BBm",3); //added by ACM
                            
                        setCursorLabelName("T3_3_BBl",4); //added by ACM
                            
                        setDefaultBarFgColor(Color.blue,0);
                            
                        setDefaultBarFgColor(Color.red,1); 
                            
                        setDefaultBarFgColor(Color.magenta,2); //added by ACM
                            
                        setDefaultBarFgColor(Color.magenta,3); //added by ACM
                            
                        setDefaultBarFgColor(Color.magenta,4); //added by ACM
                            
                        setPlotType(PLOTTYPE_LINE,0);
                            
                        setPlotType(PLOTTYPE_INSTANTCOLORLINE,1);
                            
                        setDefaultBarThickness(2,0);
                            
                        setDefaultBarThickness(2,1);   
                         
                        //    askForInput();
                         
                            
                        addBand(0PS_DASH3Color.black);     
                         
                                   
                            var 
                        x=0;
                            
                        fpArray[x] = new FunctionParameter("Length1"FunctionParameter.NUMBER);
                         
                        with(fpArray[x++]){
                                
                        setLowerLimit(1);  
                                
                        setDefault(5);
                            }
                            
                        fpArray[x] = new FunctionParameter("Length2"FunctionParameter.NUMBER);
                         
                        with(fpArray[x++]){
                                
                        setLowerLimit(1);  
                                
                        setDefault(3);
                            }      
                            
                        fpArray[x] = new FunctionParameter("Factor"FunctionParameter.NUMBER);
                         
                        with(fpArray[x++]){
                                
                        setUpperLimit(1); 
                                
                        setLowerLimit(0);  
                                
                        setDefault(0.7);
                            }
                         
                        fpArray[x] = new FunctionParameter("Source"FunctionParameter.STRING);
                         
                        with(fpArray[x++]){
                                
                        addOption("open"); 
                                
                        addOption("high");
                                
                        addOption("low");
                                
                        addOption("close");
                                
                        addOption("hl2");
                                
                        addOption("hlc3");
                                
                        addOption("ohlc4"); 
                                
                        setDefault("close"); 
                            }
                         
                        fpArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
                            
                        with(fpArray[x++]){
                                
                        setDefault();
                         }
                         
                        fpArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
                         
                        with(fpArray[x++]){
                                
                        setDefault();
                            }
                            
                        fpArray[x] = new FunctionParameter("Offset"FunctionParameter.NUMBER);
                         
                        with(fpArray[x++]){
                                
                        setDefault(0);
                            }
                            
                        fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
                         
                        with(fpArray[x++]){
                                
                        setName("Show Parameters");
                                
                        setDefault(false);
                            }
                         
                        fpArray[x] = new FunctionParameter"Linecolor1"FunctionParameter.COLOR);
                         
                        withfpArray[x] ) {
                          
                        setDefaultColor.blue );
                         }      
                         
                        fpArray[x] = new FunctionParameter"Linecolor2"FunctionParameter.COLOR);
                         
                        withfpArray[x] ) {
                          
                        setDefaultColor.red );
                         }  
                         
                        fpArray[x] = new FunctionParameter"Alerts"FunctionParameter.NUMBER);
                         
                        withfpArray[x] ) {
                                
                        setUpperLimit(2); 
                                
                        setLowerLimit(1);
                          
                        setDefault(2);
                         }   
                        }
                         
                        var 
                        amLib addLibrary("amStudies.efsLib");
                         
                        var 
                        bInit false;
                         
                        var 
                        xT31 null;
                        var 
                        xT32 null;
                        var 
                        xMACD null;
                        var 
                        xSig  null;
                        var 
                        xTemp null;//added by ACM for temporary workaround
                        var xBBm null;//added by ACM
                        var xBBu null;//added by ACM
                        var xBBl null;//added by ACM
                         
                        var vLastAlert = -1;
                        var 
                        vLastxAlert = -1;
                        var 
                        vLastaAlert = -1;
                         

                        function 
                        main(Length1Length2FactorSourceSymbolIntervalOffsetParamsLinecolor1Linecolor2Alerts) {
                         
                            if(
                        bInit == false){
                                
                        withamLib ) {
                                if(
                        Symbol == nullSymbol getSymbol();
                                if(
                        Interval == nullInterval getInterval();
                                var 
                        vSymbol Symbol+","+Interval;
                                
                        xT31 offsetSeries(amT3(Length1Factor, eval(Source)(sym(vSymbol))), Offset);
                                
                        xT32 offsetSeries(amT3(Length2Factor, eval(Source)(sym(vSymbol))), Offset);
                                
                        xMACD efsInternal("calcMACD"xT31xT32); 
                                
                        xSig ema(3xMACD); 
                                
                        xTemp sma(1,xMACD);//added by ACM as temporary workaround
                                
                        xBBm middleBB(202xTemp);//added by ACM - uses temporary workaround instead of xMACD
                                
                        xBBu upperBB(202xTemp);//added by ACM - uses temporary workaround instead of xMACD
                                
                        xBBl lowerBB(202xTemp);//added by ACM - uses temporary workaround instead of xMACD
                                
                        setShowTitleParameters(eval(Params));
                                
                        setDefaultBarFgColorLinecolor1);
                                
                        setDefaultBarFgColorLinecolor2);
                                
                        bInit true;
                                }
                            }
                         
                            var 
                        x1 getSeries(xMACD); 
                            var 
                        x2 getSeries(xSig); 
                            var 
                        x3 getSeries(xBBu);//added by ACM
                            
                        var x4 getSeries(xBBm);//added by ACM
                            
                        var x5 getSeries(xBBl);//added by ACM
                         
                                
                            
                        return new Array(x1,x2x3x4x5);
                        }
                          
                        function 
                        gID() {
                            
                        grID ++;
                            return( 
                        grID );
                        }
                         
                        function 
                        calcMACD(avg1,avg2){
                            if(
                        avg1.getValue(0)==null || avg2.getValue(0)==null) return;
                            return (
                        avg2.getValue(0) - avg1.getValue(0));

                        Comment


                        • #13
                          Hi Alex,

                          that is a real nifty solution, thanks, will post the code on my fileshare as well (after replacing my colours on the chart).

                          Paul.
                          Last edited by pmurraymc; 09-07-2006, 01:52 AM.

                          Comment

                          Working...
                          X