Announcement

Collapse
No announcement yet.

efsExternal - To Pass or Not To Pass That is the Question!

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

  • efsExternal - To Pass or Not To Pass That is the Question!

    This works:

    PHP Code:
    var bInit false;

    var 
    iEFSLIB01 "Z_SCRATCH"  ;

    var 
    iEFS01 "_fTDI";

    var 
    iEFS01P01 12 ;

    var 
    iEFS01P02 "close" ;

    function 
    main() {

    if(
    bInit == false) {

    xPathToEFS "/"iEFSLIB01 +"/" iEFS01 +".EFS" ;

    xStudy efsExternalxPathToEFS );

    bInit true ; }

      
    debugPrint"xStudy.gv0      : " xStudy.getValue(0)  + "\n" );
      
    debugPrint"xPathToEFS      : " xPathToEFS  "\n" );

      
    debugPrint"----------------: "  "\n" );

    return ( 
    xStudy.getValue(0) );


    It returns the value to my chart.

    But if I change the line:

    xStudy = efsExternal( xPathToEFS );

    to:

    xStudy = efsExternal( xPathToEFS , iEFS01P01 );

    then xStudy is null.

    What is the reason passing ONE parameter causes this to happen?

    It is pass all or none?

    Here's the function I am calling:

    PHP Code:

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


    _fTDI.EFS 


    Description    : This Indicator plots the Trend Detection Index
    Provided By    : TS Support, LLC for eSignal                   
    Modified by : Alexis C. Montenegro 08/04/2006               
                  - converted to efs2 syntax                    
                  - added multiple time frame/symbol capability 
                  - added moving average                        
     ************************************/

    var fpArray = new Array();

    function 
    preMain(){
        
    setStudyTitle("Trend Detection Index");
        
    setCursorLabelName("TDI",0);
        
    setCursorLabelName("MAofTDI",1);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1);
        
    setDefaultBarThickness(1,0);
        
    setDefaultBarThickness(1,1);
        
    askForInput();
            
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(12);
        }
        
    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("MAType"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("sma");
            
    addOption("ema");
            
    addOption("wma");
            
    setDefault("sma");
        }
        
    fpArray[x] = new FunctionParameter("MALength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(3);
        }
        
    fpArray[x] = new FunctionParameter("LineColor1"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color1");
            
    setDefault(Color.blue);
        }
        
    fpArray[x] = new FunctionParameter("LineColor2"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color2");
            
    setDefault(Color.red);
        }
        
    fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Show Parameters");
            
    setDefault(false);
        }
    }

    var 
    bInit false;
    var 
    xTDI  null;
    var 
    xMATDI null;

    function 
    main(Length,Source,Symbol,Interval,MAType,MALength,LineColor1,LineColor2,Params){
            
        if(
    bInit==false){
            if(
    Symbol == nullSymbol getSymbol();
            if(
    Interval == nullInterval getInterval();
            var 
    vSymbol Symbol+","+Interval;
            
    xTDI efsInternal("calcTDI"Length,eval(Source)(vSymbol));
            
    xMATDI = eval(MAType)(MALength,xTDI);
            
    setDefaultBarFgColor(LineColor1,0);
            
    setDefaultBarFgColor(LineColor2,1);
            
    addBand(0,PS_SOLID,1,Color.lightgrey,"0");
            
    setShowTitleParameters(eval(Params));
            
    bInit true;
        }

        return  (
    getSeries(xTDI) );
    }

    xMOM null;

    function 
    calcTDI(periodsource){
        if (
    xMOM == nullxMOM mom(period,source);
        var 
    MomSum     0;
        var 
    MomSumAbs  0
        var 
    MomAbsSum  0;
        var 
    MomAbsSum2 0;
        for (var 
    i=0i<period-1i++){
            
    MomSum += xMOM.getValue(-i);
        }
        
    MomSumAbs Math.abs(MomSum);
        for (var 
    i=0i<period-1i++){
            
    MomAbsSum += Math.abs(xMOM.getValue(-i));
        }
        for (var 
    i=0i<period*2-1i++){
            
    MomAbsSum2 += Math.abs(xMOM.getValue(-i));
        }
        var 
    ret MomSumAbs - (MomAbsSum2 MomAbsSum);    
        return 
    ret;


  • #2
    I decided to do some TESTING...

    I put debug in the both functions to see what, if anything, is going on!

    When I pass EVERY parameter or NO parameters, then efsExternal evaluates _fTDI correctly.

    I am NOT understanding this at all, now...but I will.

    PHP Code:
    var bInit false;

    var 
    iEFSLIB01 "Z_SCRATCH"  ;

    var 
    iEFS01 "_fTDI";

    var 
    iEFS01P01 12 ;

    var 
    iEFS01P02 "close" ;

    var 
    xParm01 null ;

    var 
    xParm02 null ;

    var 
    fpArray = new Array();

    function 
    preMain(){
        var 
    iDebug = new FunctionParameter("iDebug"FunctionParameter.BOOLEAN);
        
    iDebug.setDefaultfalse );


        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(12);
        }
        
    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("MAType"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("sma");
            
    addOption("ema");
            
    addOption("wma");
            
    setDefault("sma");
        }
        
    fpArray[x] = new FunctionParameter("MALength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(3);
        }
        
    fpArray[x] = new FunctionParameter("LineColor1"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color1");
            
    setDefault(Color.blue);
        }
        
    fpArray[x] = new FunctionParameter("LineColor2"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color2");
            
    setDefault(Color.red);
        }
        
    fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Show Parameters");
            
    setDefault(false);
        }

    // premain

    function mainiDebug,
                   
    Length,Source,Symbol,Interval,MAType,MALength,LineColor1,LineColor2,Params ) {

    if(
    bInit == false) {

    xParm01 = eval(iEFS01P01) ;
    xParm02 = eval(iEFS01P02) ;

    xPathToEFS "/"iEFSLIB01 +"/" iEFS01 +".EFS" ;

    xStudy efsExternalxPathToEFS Length,Source,Symbol,Interval,MAType,MALength,LineColor1,LineColor2,Params);

    bInit true ; }


    if(
    iDebug == true) {

      
    debugPrint"  "  "\n" );

      
    debugPrint"xParm02         : " xParm02  "\n" );
      
    debugPrint"xParm01         : " xParm01  "\n" );
      
    debugPrint"xStudy.gv0      : " xStudy.getValue(0)  + "\n" );
      
    debugPrint"xPathToEFS      : " xPathToEFS  "\n" );

      
    debugPrint"----------------: "  "\n" );
    }


    return ( 
    xStudy.getValue(0) );


    PHP Code:
    /*************************************


    _fTDI.EFS 


    Description    : This Indicator plots the Trend Detection Index
    Provided By    : TS Support, LLC for eSignal                   
    Modified by : Alexis C. Montenegro 08/04/2006               
                  - converted to efs2 syntax                    
                  - added multiple time frame/symbol capability 
                  - added moving average                        
     ***********************************/

    var fpArray = new Array();

    function 
    preMain(){
        
    setStudyTitle("_fTDI");
        
    setCursorLabelName("_fTDI",0);
        
    setCursorLabelName("MAofTDI",1);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1);
        
    setDefaultBarThickness(1,0);
        
    setDefaultBarThickness(1,1);
        
    askForInput();
            
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(12);
        }
        
    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("MAType"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("sma");
            
    addOption("ema");
            
    addOption("wma");
            
    setDefault("sma");
        }
        
    fpArray[x] = new FunctionParameter("MALength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(3);
        }
        
    fpArray[x] = new FunctionParameter("LineColor1"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color1");
            
    setDefault(Color.blue);
        }
        
    fpArray[x] = new FunctionParameter("LineColor2"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color2");
            
    setDefault(Color.red);
        }
        
    fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Show Parameters");
            
    setDefault(false);
        }
    }

    var 
    bInit false;
    var 
    xTDI  null;
    var 
    xMATDI null;

    function 
    main(Length,Source,Symbol,Interval,MAType,MALength,LineColor1,LineColor2,Params){
            
        if(
    bInit==false){
            if(
    Symbol == nullSymbol getSymbol();
            if(
    Interval == nullInterval getInterval();
            var 
    vSymbol Symbol+","+Interval;
            
    xTDI efsInternal("calcTDI"Length,eval(Source)(vSymbol));
            
    xMATDI = eval(MAType)(MALength,xTDI);
            
    setDefaultBarFgColor(LineColor1,0);
            
    setDefaultBarFgColor(LineColor2,1);
            
    addBand(0,PS_SOLID,1,Color.lightgrey,"0");
            
    setShowTitleParameters(eval(Params));
            
    bInit true;
        }




      
    debugPrint"  "  "\n" );


      
    debugPrint"Params          : " Params  "\n" );
      
    debugPrint"LineColor2      : " LineColor2  "\n" );
      
    debugPrint"LineColor1      : " LineColor1  "\n" );
      
    debugPrint"MAType          : " MAType  "\n" );
      
    debugPrint"Interval        : " Interval  "\n" );
      
    debugPrint"Symbol          : " Symbol  "\n" );
      
    debugPrint"Source          : " Source "\n" );
      
    debugPrint"Length          : " Length  "\n" );


      
    debugPrint"---- _fTDI -----: "  "\n" );


        return  (
    getSeries(xTDI) );
    }

    xMOM null;

    function 
    calcTDI(periodsource){
        if (
    xMOM == nullxMOM mom(period,source);
        var 
    MomSum     0;
        var 
    MomSumAbs  0
        var 
    MomAbsSum  0;
        var 
    MomAbsSum2 0;
        for (var 
    i=0i<period-1i++){
            
    MomSum += xMOM.getValue(-i);
        }
        
    MomSumAbs Math.abs(MomSum);
        for (var 
    i=0i<period-1i++){
            
    MomAbsSum += Math.abs(xMOM.getValue(-i));
        }
        for (var 
    i=0i<period*2-1i++){
            
    MomAbsSum2 += Math.abs(xMOM.getValue(-i));
        }
        var 
    ret MomSumAbs - (MomAbsSum2 MomAbsSum);    
        return 
    ret;

    Comment


    • #3
      Could this be a bug?

      Could this be a BUG?!

      Passing NO parameters works.

      Passing ALL paramenters works.

      Passing ONE parameter does NOT work.

      Could this be a BUG?!


      I searched the Knowledgebase for efsExternal

      This is all there is:


      efsExternal( pathToEFS [, parameters] [, sym/inv] )

      New in EFS2. Returns a series object representing the values as calculated from the given external EFS script. You would then use the getSeries() function to extract a specific series value if multiple series are returned.


      Note: If you pass a series object to the efsExternal() function, be sure to pass the series as the last parameter if you want to force efsExternal() to execute in the series' sym/inv context.



      Parameters



      pathToEFS
      the path and filename of the EFS script to call

      parameters
      optional. parameters, if any, required by the EFS script you are calling

      sym/inv
      optional. if used, the external EFS will be loaded into the specified symbol or interval's context



      Usage

      function main() {
      var myVar;
      var myPlot;

      ...
      ...

      //call an external EFS called "myCustomEFS.efs" and load it into
      //the context of IBM 15-min bars. we also pass three parameters
      //to the script.
      myVar = efsExternal( "myCustomEFS.efs", 20, 5, sym( "IBM,15" ));

      //assuming that "myyCustomEFS.efs" returned 3 values, we would use
      //the following logic to retrieve just the 2nd return value. The first
      //value returned would be seriesIndex 0, second value would be
      //seriesIndex 1, etc.
      myPlot = getSeries( myVar, 1 );

      return myPlot;
      }

      I KNOW THERE'S A SIMPLE SOLUTION!!!

      Comment


      • #4
        buzzhorton
        It is not a bug. If you pass no parameters the called efs will use the ones that are included in that script. If instead you pass one parameter then you have to pass also all the other parameters that the efs is expecting in the same order in which they are listed in the main definition of that script
        Alex

        Comment


        • #5
          Originally posted by Alexis C. Montenegro
          buzzhorton
          It is not a bug. If you pass no parameters the called efs will use the ones that are included in that script. If instead you pass one parameter then you have to pass also all the other parameters that the efs is expecting in the same order in which they are listed in the main definition of that script
          Alex
          Thanks, Alexis.

          I had just found something else you wrote and was going to ask you:

          Originally posted by Alexis C. Montenegro
          shaeffer
          The reason it is not working is because the efs that you are calling requires several parameters. You can see this by going in the Edit Studies window for jagc.
          So if you want to pass the inv(60) parameter to that efs then you also have to pass ALL the parameters that the efs is expecting in the same order in which they are defined. Your call to the jagc efs should therefore be structured as follows
          xJag = efsExternal("/My Formulas/JagC.efs", pds, slw, triggerLen, emaLen, inv(60));
          You will need to replace pds, slw, triggerLen and emaLen with the required values. If you do not know in what format these parameters need to be then you will need to contact the author of that script
          Alex
          Now the REAL question is...

          WHAT'S THE REASON THIS IS NOT CLEARLY DOCUMENTED IN THE KNOWLEDGEBASE.

          Had it been, that would have saved me a couple of hours!

          But, thanks again, Alexis, I can now move forward.

          Comment


          • #6
            This:

            parameters
            optional. parameters, if any, required by the EFS script you are calling


            should read:


            parameters
            optional. parameters, if any, required by the EFS script you are calling. If you pass parameters you must pass ALL parameters required by the EFS script you are calling.

            Comment


            • #7
              Hello Avery,

              Thank you for the suggestion. I've added this to the notes for the KB article.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment

              Working...
              X