Announcement

Collapse
No announcement yet.

Multiple returns from efsLib

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

  • Multiple returns from efsLib

    Hi,

    I'm trying to understand efsLib creation and retrieving multiple returns. The only forum reference I found and tried to follow is at: http://forum.esignalcentral.com/show...ighlight=myLib

    However it returns "TypeError: LagReturn has no properties"

    Any help is appreciated to include good links/resources for coding and retrieving multiple data from efsLib.

    Both the efsLib and the calling efs follow:

    efsLib:
    PHP Code:
    var bInit false;
    var 
    L0_1 0;
    var 
    L1_1 0;
    var 
    L2_1 0;
    var 
    L3_1 0;

    var 
    L0 0;
    var 
    L1 0;
    var 
    L2 0;
    var 
    L3 0;

    var 
    xhl2 null;

    function 
    Laguerre(gamma) {

        if(
    gamma == null)
            
    gamma 0.8;
            
        if (
    bInit == false) {
            
    xhl2 hl2();
            
    bInit true;
        }
        
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    L0_1 L0;
            
    L1_1 L1;
            
    L2_1 L2;
            
    L3_1 L3;
        }

        var 
    Filt 0;
        var 
    FIR 0;
        var 
    sum 0
        var 
    0;

        
    L0 = (gamma) * xhl2.getValue(0) + gamma L0_1;
        
    L1 = -gamma L0 L0_1 gamma L1_1;
        
    L2 = -gamma L1 L1_1 gamma L2_1;
        
    L3 = -gamma L2 L2_1 gamma L3_1;

        
    Filt = (L0 L1 L2 L3) / 6;

        for (
    = - 3<= 0i++) {
            if (
    == || == -3)
                
    1;
            else
                
    2;

            
    sum += xhl2.getValue(i);
        }

        
    FIR sum 6;

        
        if (
    getCurrentBarCount() < 50) return;
        return new Array(
    FiltFIR);

    Calling efs:

    PHP Code:
    //http://forum.esignalcentral.com/showthread.php?threadid=16410&highlight=myLib
    //calls "LaguerreFilter.efsLib"
    debugClear();
    var 
    aFPArray = new Array();
    var 
    LAGUER addLibrary ("LaguerreFilter.efsLib");

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("FIR");
        
        
    setCursorLabelName("Filt"0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(20);
        
        
    setCursorLabelName("FIR"1);
        
    setDefaultBarFgColor(Color.green1);
        
    setDefaultBarThickness(21);
        
        var 
    0;
        
        
    aFPArray[x] = new FunctionParameter("gamma"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]) {
            
    setName("Gamma");
            
    setLowerLimit(0.01);
            
    setDefault(0.8);
        }
        
    }
    var 
    bInit false;
    var 
    vFilt null;
    var 
    vFIR null;

    function 
    main(gamma) {
        if (
    bInit == false) {
            
    vFilt efsInternal("fLAGUER"0gamma);
            
    vFIR =  efsInternal("fLAGUER"1gamma);
            
    bInit true;
        }

        var 
    xFilt getSeries(vLAGUER0);
        var 
    xFIR getSeries(vLAGUER1);

        return new Array(
    xFiltxFIR);
    }
    /****efsInternal*********/
    var LagReturn null;

    function 
    fLAGUER(n,g) {

        if (
    LagReturn == nullLagReturn LAGUER.Laguerre(g);

        return 
    LagReturn[n];

    wayne
    Last edited by waynecd; 05-24-2009, 11:49 PM.

  • #2
    The code below is just the efs script "LaguerreFilter.efs" with code split out between the calling efs and the efsLib and should include the following credits:

    /*********************************

    Provided By:

    eSignal (Copyright c eSignal), a division of Interactive Data
    Corporation. 2008. All rights reserved. This sample eSignal
    Formula Script (EFS) is for educational purposes only and may be
    modified and saved under a new file name. eSignal is not responsible
    for the functionality once modified. eSignal reserves the right
    to modify and overwrite this EFS file with each new release.

    Description:

    Four-Element Laguerre Filter by John Ehlers

    Version: 1.0 09/24/2008

    Notes:

    This moving average indicator allows to avoid whipsaw trades and strike a balance
    between the amount of smoothing and the amount of lag by using some modern math tools
    like Laguerre transform filter. This filter is the next generation tool comparing to
    either the usual MovAvg or FIR (finite impulse response) filters.


    Formula Parameters: Default:

    Gamma - damping factor 0.8

    **********************************/

    Comment


    • #3
      wayne, did you figure this out yet?? It can sometimes be frustrating to hunt down errors. I've not had any time to offer any assistance or play with your code because of other projects.

      let me know if you're still stuck??
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Thanks Brad,

        No luck yet. Will continue to test to see if I can get it to work. If I do, I will post it.

        Regards,

        wayne

        Comment


        • #5
          Wayne,

          It's a bit beyond me. However, having tried it out, compared it against the original Laguerre Filter and read the other thread you refer to, it looks to me as if you are mixing up a few concepts that don't quite work. When I try and run your code with debugs in, it tells me that an attempt is being made to execute the fLAGUER internal function BEFORE any attempt is made to execute the code in your main() section.

          The statement

          PHP Code:
          vFilt efsInternal("fLAGUER"0gamma); 
          looks like you used the related efsExternal type statement as a model. As far as I'm aware, efsInternal doesn't work that way. In the statement:

          PHP Code:
          myVar efsExternal("xyz.efs"param1); 
          from the other thread you refer to, myVar is actually being initialised as a kind of function reference or pointer, i.e. it is a type of declarative statement. So that myVar can be referred to as if it were the function.

          When you later use the statement:

          PHP Code:
          var xFilt getSeries(vLAGUER0); 
          This should really be:

          PHP Code:
          var xFilt getSeries(vFilt0); 
          to be consistent with the way in which that efsExternal code is used. Clearly this doesn't work either, I guess because efsInternal is not meant to be used in that way, i.e. declarative.

          I'm not entirely sure that it's the best use of efsLib either, i.e. to hold what is essentially another main() function. Although I suppose to a degree efsLib can just be a container for common code no matter what the type. I believe efsExternal is now implemented as simply efs(). You could try and transfer your LaguerreFilter efsLib code to a .efs and just use efs() to execute it as common code from multiple places.

          Sorry that I can't offer more useful advice but as you may guess I have never attempted to use the combination of efsInternal and efsLib this way.

          Regards.

          Comment


          • #6
            Hi Sandpiper,

            Thanks, good eye.
            PHP Code:
            var xFilt getSeries(vFilt0); 
            I wasn't able to get the multiple outputs from the efsLib. The only way it worked for me was by creating a separate function for each output within the efsLib as follows:

            Calling efs in formula folder:
            PHP Code:
            //http://forum.esignalcentral.com/showthread.php?threadid=16410&highlight=myLib
            //calls "LaguerreFilter.efsLib"
            debugClear();
            var 
            aFPArray = new Array();
            var 
            LAGUER addLibrary ("LaguerreFilter1a.efsLib");

            function 
            preMain() {
                
            setPriceStudy(true);
                
            setStudyTitle("FIR");
                
                
            setCursorLabelName("Filt"0);
                
            setDefaultBarFgColor(Color.red0);
                
            setDefaultBarThickness(20);
                
                
            setCursorLabelName("FIR"1);
                
            setDefaultBarFgColor(Color.green1);
                
            setDefaultBarThickness(21);
                
                var 
            0;
                
                
            aFPArray[x] = new FunctionParameter("gamma"FunctionParameter.NUMBER);
                
            with(aFPArray[x++]) {
                    
            setName("Gamma");
                    
            setLowerLimit(0.01);
                    
            setDefault(0.8);
                }
                
            }
            var 
            bInit false;
            var 
            vFilt null;
            var 
            vFIR null;
            var 
            vhl2 null;
            var 
            zhl2 null;

            function 
            main(gamma) {
                if (
            bInit == false) {
                    
            vhl2 hl2();
                    
            bInit true;
                }
                
            zhl2 vhl2.getValue(0);
                
            vFilt LAGUER.fFilt(gamma,zhl2);
                
            vFIR LAGUER.fFIR(vhl2);

                return new Array(
            vFiltvFIR);

            efsLib in FunctionLibrary folder;

            PHP Code:
            var bInit false;
            var 
            L0_1 0;
            var 
            L1_1 0;
            var 
            L2_1 0;
            var 
            L3_1 0;

            var 
            L0 0;
            var 
            L1 0;
            var 
            L2 0;
            var 
            L3 0;

            function 
            fFilt(gamma,xhl2) {

                if(
            gamma == null)
                    
            gamma 0.8;
                    
                
                if (
            getBarState() == BARSTATE_NEWBAR) {
                    
            L0_1 L0;
                    
            L1_1 L1;
                    
            L2_1 L2;
                    
            L3_1 L3;
                }

                var 
            Filt 0;

                
            L0 = (gamma) * xhl2 gamma L0_1;
                
            L1 = -gamma L0 L0_1 gamma L1_1;
                
            L2 = -gamma L1 L1_1 gamma L2_1;
                
            L3 = -gamma L2 L2_1 gamma L3_1;

                
            Filt = (L0 L1 L2 L3) / 6;


                
                if (
            getCurrentBarCount() < 50) return;
                return 
            Filt;
            }

            function 
            fFIR(yhl2){

                var 
            FIR 0;
                var 
            sum 0
                var 
            0;
                for (
            = - 3<= 0i++) {
                    if (
            == || == -3)
                        
            1;
                    else
                        
            2;

                    
            sum += yhl2.getValue(i);
                }

                
            FIR sum 6;
                if (
            getCurrentBarCount() < 50) return;
                return 
            FIR;

            wayne
            Last edited by waynecd; 05-26-2009, 10:39 PM.

            Comment


            • #7
              Well, nothing I've tried works other than what I already posted. I just streamlined the previous code a little.

              Calling efs in formula folder:
              PHP Code:
              //http://forum.esignalcentral.com/showthread.php?threadid=30720
              //http://forum.esignalcentral.com/showthread.php?threadid=16410&highlight=myLib
              //calls "LaguerreFilter.efsLib"
              debugClear();
              var 
              aFPArray = new Array();
              var 
              LAGUER addLibrary ("LaguerreFilter.efsLib");

              function 
              preMain() {
                  
              setPriceStudy(true);
                  
              setStudyTitle("FIR");
                  
                  
              setCursorLabelName("Filt"0);
                  
              setDefaultBarFgColor(Color.red0);
                  
              setDefaultBarThickness(20);
                  
                  
              setCursorLabelName("FIR"1);
                  
              setDefaultBarFgColor(Color.green1);
                  
              setDefaultBarThickness(21);
                  
                  var 
              0;
                  
                  
              aFPArray[x] = new FunctionParameter("gamma"FunctionParameter.NUMBER);
                  
              with(aFPArray[x++]) {
                      
              setName("Gamma");
                      
              setLowerLimit(0.01);
                      
              setDefault(0.8);
                  }
              }
              var 
              bInit false;
              var 
              vFilt null;
              var 
              vFIR null;

              function 
              main(gamma) {

                  
              vFilt LAGUER.fFilt(gamma);
                  
              vFIR LAGUER.fFIR();

                  return new Array(
              vFiltvFIR);

              efsLib in FunctionLibrary folder (note: not even a copy of the *.efsLib can be in the same folder as the calling *.efs;
              PHP Code:
              //NOTE: THIS EFSLIB FILE CANNOT BE IN THE SAME DIRECTORY AS THE CALLING EFS and must be named the same as specified in the calling efs.
              //http://forum.esignalcentral.com/showthread.php?threadid=30720
              /*********************************
              Provided By:  

                  eSignal (Copyright c eSignal), a division of Interactive Data 
                  Corporation. 2008. All rights reserved. This sample eSignal 
                  Formula Script (EFS) is for educational purposes only and may be 
                  modified and saved under a new file name.  eSignal is not responsible
                  for the functionality once modified.  eSignal reserves the right 
                  to modify and overwrite this EFS file with each new release.

              Description:        

                  Four-Element Laguerre Filter by John Ehlers 

              Version:            1.0  09/24/2008

              Notes:

                  This moving average indicator allows to avoid whipsaw trades and strike a balance
                  between the amount of smoothing and the amount of lag by using some modern math tools
                  like Laguerre transform filter. This filter is the next generation tool comparing to 
                  either the usual MovAvg or FIR (finite impulse response) filters.    


              Formula Parameters:                     Default:

                  Gamma - damping factor              0.8

              **********************************/
              var bInit false;
              var 
              L0_1 0;
              var 
              L1_1 0;
              var 
              L2_1 0;
              var 
              L3_1 0;

              var 
              L0 0;
              var 
              L1 0;
              var 
              L2 0;
              var 
              L3 0;

              var 
              bInit false;
              var 
              xhl2 null;

              function 
              fFilt(gamma) {

                  if (
              bInit == false) {
                      if(
              gamma == nullgamma 0.8;
                      
              xhl2 hl2();
                      
              bInit true;
                  }
                  
                  if (
              getBarState() == BARSTATE_NEWBAR) {
                      
              L0_1 L0;
                      
              L1_1 L1;
                      
              L2_1 L2;
                      
              L3_1 L3;
                  }
                  var 
              vhl2 xhl2.getValue(0);
                  var 
              Filt 0;

                  
              L0 = (gamma) * vhl2 gamma L0_1;
                  
              L1 = -gamma L0 L0_1 gamma L1_1;
                  
              L2 = -gamma L1 L1_1 gamma L2_1;
                  
              L3 = -gamma L2 L2_1 gamma L3_1;

                  
              Filt = (L0 L1 L2 L3) / 6;


                  
                  if (
              getCurrentBarCount() < 50) return;

                  return 
              Filt;
              }
              var 
              b1Init false;
              var 
              yhl2 null;

              function 
              fFIR(){
                  if (
              b1Init == false) {
                      
              yhl2 hl2();
                      
              b1Init true;
                  }

                  var 
              FIR 0;
                  var 
              sum 0
                  var 
              0;
                  for (
              = - 3<= 0i++) {
                      if (
              == || == -3)
                          
              1;
                      else
                          
              2;

                      
              sum += yhl2.getValue(i);
                  }

                  
              FIR sum 6;
                  if (
              getCurrentBarCount() < 50) return;

                  return 
              FIR;

              Comment

              Working...
              X