Announcement

Collapse
No announcement yet.

efsInternal and efsExternal crashing eSignal

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

  • efsInternal and efsExternal crashing eSignal

    I have created an indicator which is working fine when I apply it to a chart. Now I would like to add averages to the indicator. I have tried using the efsInternal and efsExternal methods, but they both crash my machine. I am using the following code, where Indicator.efs resides in my formula's folder, and 10 is the only input parameter for the indicator. I've also tried switching to efsInternal, and using the calculations in an internal function, but I get the same result. Am I doing something wrong?

    var vExtEfs = efsExternal("Indicator.efs",10);

  • #2
    Re: efsInternal and efsExternal crashing eSignal

    pro_trader
    As far as I can tell those functions appear to be working fine.
    If you search the forums using efsInternal* or efsExternal* as the keywords you will find many working examples that you can use to test
    Alex


    Originally posted by pro_trader
    I have created an indicator which is working fine when I apply it to a chart. Now I would like to add averages to the indicator. I have tried using the efsInternal and efsExternal methods, but they both crash my machine. I am using the following code, where Indicator.efs resides in my formula's folder, and 10 is the only input parameter for the indicator. I've also tried switching to efsInternal, and using the calculations in an internal function, but I get the same result. Am I doing something wrong?

    var vExtEfs = efsExternal("Indicator.efs",10);

    Comment


    • #3
      I've searched extensively but cannot find a solution. Below is the code for the external indicator. It seems to work if I replace my external indicator with a different one, but that doesn't help me accomplish my objective.

      PHP Code:
      var aFPArray        = new Array();  

      function 
      preMain() {     setPriceStudy(false);     
      setDefaultBarFgColor(Color.red0);     
      setDefaultBarFgColor(Color.blue1);          
      aFPArray[0] = new FunctionParameter"Divisor"FunctionParameter.NUMBER);         
      withaFPArray[0] ) {             
      setLowerLimit100 );             
      setUpperLimit2000 );             
      setDefault1000 );         

      }  

      function 
      main(Divisor) {
           if (
      Divisor == nullDivisor 1000;     
      var 
      vClose getValue("Close"01);     
      var 
      vMSFT getValue("Close"01"MSFT");                  
      if(
      vMSFT 0) {         
      return (
      vClose vMSFT Divisor);                       
      } else {     
      return;     


      Comment


      • #4
        pro_trader
        FWIW calling that script using the efsExternal() call you posted in your first message does not appear to be causing any crashes (see enclosed image) and returns the same value as running the called script on its own
        Alex




        Originally posted by pro_trader
        I've searched extensively but cannot find a solution. Below is the code for the external indicator. It seems to work if I replace my external indicator with a different one, but that doesn't help me accomplish my objective.

        PHP Code:
        var aFPArray        = new Array();  

        function 
        preMain() {     setPriceStudy(false);     
        setDefaultBarFgColor(Color.red0);     
        setDefaultBarFgColor(Color.blue1);          
        aFPArray[0] = new FunctionParameter"Divisor"FunctionParameter.NUMBER);         
        withaFPArray[0] ) {             
        setLowerLimit100 );             
        setUpperLimit2000 );             
        setDefault1000 );         

        }  

        function 
        main(Divisor) {
             if (
        Divisor == nullDivisor 1000;     
        var 
        vClose getValue("Close"01);     
        var 
        vMSFT getValue("Close"01"MSFT");                  
        if(
        vMSFT 0) {         
        return (
        vClose vMSFT Divisor);                       
        } else {     
        return;     


        Comment


        • #5
          That is the exact code I am running, and it crashes everytime I put it on a chart. What do I do from here?

          Comment


          • #6
            Three things I'd try:

            1. Don't reload the external efs on every tick. From the efsExternal() documentation:
            PHP Code:
            var xStudy null;

            function 
            main() { 
               
            //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. 
               
            if (xStudy == nullxStudy efsExternal"myCustomEFS.efs"205sym"IBM,15" ) ); 

               
            //assuming that "myCustomEFS.efs" returns only one data series
               
            var myPlot xStudy.getValue(0); 

               return 
            myPlot;

            2. Remove the graphic functions from your external efs (Indicator.efs). Remove:
            PHP Code:
            setDefaultBarFgColor(Color.red0);
            setDefaultBarFgColor(Color.blue1); 
            and maybe remove:
            PHP Code:
            setPriceStudy(false); 
            3. Avoid using Javascript's "with" statement. See Click Here. Avoiding it's use is recommended by Douglas Crockford's JavaScript Coding Conventions Here (scroll up a few lines to "with Statement").

            Use something like this instead:
            PHP Code:
            var p1 = new FunctionParameter"Divisor",  FunctionParameter.NUMBER);
            p1.setLowerLimit100 );
            p1.setLowerLimit2000 );
            p1.setDefault1000 ); 
            (In most cases, I find it unnecessary for the FunctionParameter var, like p1 above, to have global scope - a local variable works fine.)

            Also, note the following (from efsExternal() documentation):

            "This function is not compatible with setComputeOnClose() or the global set compute on close option listed in EFS Settings (Tools-->EFS-->Settings)."
            Last edited by shortandlong; 12-28-2009, 01:39 PM.

            Comment


            • #7
              pro_trader,

              Since I've been doing some multi-symbol EFSs, I've noticed the getValue lines in your code have some potential problems:
              PHP Code:
              function main(Divisor) {
                  if (
              Divisor == nullDivisor 1000;     
                  var 
              vClose getValue("Close"01);     
                  var 
              vMSFT getValue("Close"01"MSFT");                  
                  if(
              vMSFT 0) {         
                      return (
              vClose vMSFT Divisor);                       
                  } else {     
                      return;     
                  }

              Both of the above calls to getValue are returning an array with one element in them, instead of a single price value.

              You might try the code below, which returns a price value, not an array (the documentation has "close" as lower case only, so I changed it as well, also there's no need to use getValue for the close of the charted symbol):
              PHP Code:
              var vClose close (0);     
              var 
              vMSFT getValue("close"0"MSFT"); 
              Personally, I would not use getValue at all - in general it's too slow.

              But, the real problem is that, unlike other ways to get multiple symbols, getValue is synchronous, not it asynchronous. It freezes the EFS until the data is retrieved from the server! The other methods do not do this - instead they return null for any price value and after returning from main do not call main again until all the data is received from the server. This is probably why you're crashing. Rewritten:
              PHP Code:
              var msftSeriesObject null;

              function 
              preMain() {
                  
              setPriceStudy(false);
                  
              setDefaultBarFgColor(Color.red0);
                  
              setDefaultBarFgColor(Color.blue1);

                  var 
              p1 = new FunctionParameter"Divisor",  FunctionParameter.NUMBER);
                  
              p1.setLowerLimit100 );
                  
              p1.setLowerLimit2000 );
                  
              p1.setDefault1000 );
              }

              function 
              main(Divisor) {
                  if (
              Divisor == nullDivisor 1000;

                  if (
              msftSeriesObject == null) {
                      
              msftSeriesObject close (sym ("MSFT"));
                      
              // probably don't have any data yet from server, so return
                      
              return;
                  }

                  var 
              vClose close (0);
                  var 
              vMSFT msftSeriesObject.getValue (0);

                  if(
              vMSFT 0) {
                      return (
              vClose vMSFT Divisor);
                  } else {
                      return;
                  }

              Note that the getValue in msftSeriesObject.getValue (0); is a member function of the series object, not the global getValue you were using.
              Last edited by shortandlong; 12-31-2009, 11:42 AM.

              Comment

              Working...
              X