Announcement

Collapse
No announcement yet.

GlobalVariable dont work with efsInternal

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

  • GlobalVariable dont work with efsInternal

    With the following simple code, I get only <none> as result instead of ((high() + low())/2 + 1).


    PHP Code:
    var hdl2;

    function 
    main()
    {
        
    hdl2 = (high() + low()) /2;

        return 
    efsInternal("test");
        
    }

    function 
    test()
    {

        return (
    hdl2 1);


    How can I use GlobalVariables in functions, which I use with efsInternal-call?
    Franz

  • #2
    franzmey,

    The variable within the function being called is declared as unique to the function called by efsInternal(). If I understand your question correctly, here is a link to an explanation I posted previously. It all has to do with the function being declared independent of the efs in which it is contained, which, if you think about it, has to be that way for efsInternal() to work. I hope this helps

    Comment


    • #3
      Steve,

      thank you for the link.

      I read it and see, that efs2 dont uses my global variable in my simple way, because the efs2-engine uses instances...


      I have about 40 functions, the most are dependent of other functions. I used efsInternal to make at 30 functions "sma" and some offsets of functions-values. Without efs2 I cant manage this.

      For 2 day 5 min datas, the efs-file needed 52 seconds to load, the same functions in TradeStation needed 1-2 seconds.

      I set already setcomputeonclose, but its a very long time for the indicator.

      Now I try global variables, to make less calls, but it dont work.


      I am surprised however nevertheless, why the direct function call works and efsInternal call not.

      PHP Code:
      var hdl2;

      function 
      main()
      {

          
      hdl2 = (high() + low()) /2;
         
          return 
      test();
          
      }



      function 
      test()
      {

          return (
      hdl2 1);



      I get also an offset caused by efsInternal & sma used, see link.
      Last edited by franzmey; 01-10-2006, 09:39 AM.
      Franz

      Comment


      • #4
        franzmey,

        Even though your main efs has been set to compute on close, I suspect your functions that are being called using efsInternal() are being processed every tick. That is because you have passed control to the efs2 engine, and it is ensuring all of these disparate efs's are sequenced correctly. I believe this is to ensure coordination between the potentially different timeframes.

        If you have 30 functions that you are calling with efsInternal(), you are placing a significant load on your PC due to the efs2 engine having to sequence them all. To verify this in your application(s), try placing a single debugPrintln statement in one of the functions being called using efsInternal(). you can try placing this statement in one of the functions that are being called using efsInternal. (pls make sure you have the debug window enabled btw. )

        debugPrintln (" "+getCurrentBarCount());

        As a comment, It seems that you are using a very powerful tool for a relatively simple purpose. Perhaps you should be using non-efs2 functionality (using internal functions) which, I suspect, is more in line with the TradeStation functionality you mentioned

        Comment


        • #5
          Steve, thank you again for your answer!

          Perhaps you should be using non-efs2 functionality (using internal functions) which, I suspect, is more in line with the TradeStation functionality you mentioned
          I think its maybe the best, but how e.g. can I manage the next simple questions all without efsInternal:

          - simple sma, ema, wma of a value (or function return)
          - simple offset of a value (or function return), e.g. offsetSeries(sma(14, efsInternal("myCalc")),-3);
          - call a value of an function xbars ago, myseries = efsInternal("myCalc"); abc = myseries.getValue(-8);
          Franz

          Comment


          • #6
            I am referring more-so to having to use 30 different functions, all declared separately as separate efs2 objects. So, using the examples you listed
            Originally posted by franzmey
            I think its maybe the best, but how e.g. can I manage the next simple questions all without efsInternal:

            - simple sma, ema, wma of a value (or function return)
            - simple offset of a value (or function return), e.g. offsetSeries(sma(14, efsInternal("myCalc")),-3);
            - call a value of an function xbars ago, myseries = efsInternal("myCalc"); abc = myseries.getValue(-8);
            My question back to you is do you truly need 30 different functions all treated in such a manner that you require they return a series object which could be used as an input series into another efs2 object? Or rather, do you just need to have the ability to recall previous values of a function return, where the use of getValue() or the saving of separate arrays could be used to access the historical data in an efficient manner.

            To try and address your issues further and get into specifics, you will have to post some actual working examples of your code which demonstrate the problems you are having.

            Should you choose to move onto this next phase of troubleshooting, either myself or someone else in the community will be able to assist you in trying to address those issues.

            Comment


            • #7
              I wrote today new lines to delete old functions and reduce the efsInternal-calls. E.g. I wrote my own sma-routine, so I dont have to page out small functions. Produced variables are then global, until I use efsInternal. Nearly 20 functions I deleted and the speed of the code is very fast to the comparison from old code. In a 2 day 2T chart, I have reduced the calls from 120.000 on less than 40.000. I still more look for improvements, but its difficulty to understand, why e.g. next code not working:

              PHP Code:
              function main() {
                return 
              sma(10low(-2));

              I now, low(-2) isnt a series.

              Next code works with normal low, but not the low(-2):
              PHP Code:
              function main() {
                return 
              sma(10low());

              Without additionally function and efsInternal, I am 4 times so fast with next code!
              PHP Code:
              var myArray = new Array();
              function 
              main()
              {
                  
              Avg 0;
                  
              smaLength 10;
                  for (
              1smaLength+1i++)
                  {
                      
              myArray[i] = low(-2*i);
                      
                      
              Avg Avg myArray[i];
                  }

                  return 
              Avg smaLength;


              Franz

              Comment


              • #8
                Franz
                sma(10,low(-2)) will not work because the sma() function requires a series object as the source and low(-2) is not a series but a value.
                In the second example you are correctly passing a series to the sma() function however you are not implementing any of the suggestions I provided to you in another thread which would make the code more efficient ie

                PHP Code:
                var myAvg null
                function main(){
                    if(
                myAvg==nullmyAvg sma(10,low());
                    return 
                myAvg.getValue(-2);

                The above example will return the same as what you are trying to accomplish with sma(10,low(-2)).
                Alex

                Comment


                • #9
                  Hi franzmey,

                  It is good to see that you are realizing some success on this, however there are still problems as Alex pointed out. Regarding your code, it looks like you are trying to get an offset moving average. The way you are implementing that in your function is incorrect as you are averaging every other value because you are multiplying by two.

                  Here is a simple, fully functional efs that shows how to calculate offset series and return them to the chart.


                  PHP Code:
                  function preMain(){
                   
                  setPriceStudy(true);
                   
                  setShowTitleParameters(false);
                   
                  setStudyTitle("3 ma");
                   
                  setShowCursorLabel(true);
                      
                   
                  setCursorLabelName("s1"0);
                   
                  setCursorLabelName("s2"1);
                   
                  setCursorLabelName("s2(-4)"2);
                      
                   
                  setDefaultBarFgColor(Color.blue0);
                   
                  setDefaultBarFgColor(Color.red1);
                   
                  setDefaultBarFgColor(Color.green2);
                      
                   
                  setDefaultBarThickness(2,0);
                   
                  setDefaultBarThickness(2,1);
                   
                  setDefaultBarThickness(2,2);
                  }

                  var 
                  bInit false;
                  var 
                  s1;var s2;

                  function 
                  main(){
                       if(
                  bInit == false){
                       
                  bInit == true;
                       
                  s1 offsetSeries(sma(10,low()), 2);
                          
                       
                  // note, zero offset study can be written either of the next two ways
                       
                  s2 sma(10,low());
                       
                  //s2 = offsetSeries(sma(10,low()), 0); 
                   
                  }

                   if (
                  s1==null||s2==null)return;

                   return new Array(
                  s1.getValue(0),s2.getValue(0),s2.getValue(-4));

                  I hope this is of some help.

                  Comment


                  • #10
                    Alex, Steve,

                    thank you both for the constant and very good assistance!


                    you are not implementing any of the suggestions I provided to you in another thread which would make the code more efficient
                    I wrote for myself next efs-code:
                    PHP Code:
                    var Lm2sma;
                    function 
                    main() {
                      
                        
                    Lm2sma sma(10efsInternal("Lm2"));
                        return 
                    Lm2sma.getValue(0);
                       
                    }


                    function 
                    Lm2()
                    {
                        return 
                    low(-2);

                    but the result was not the same of my other indicator:
                    PHP Code:
                    var myArray = new Array();
                    function 
                    main()
                    {
                        
                    Avg 0;
                        
                    smaLength 10;
                        for (
                    1smaLength+1i++)
                        {
                            
                    myArray[i] = low(-2*i);
                            
                            
                    Avg Avg myArray[i];
                        }

                        return 
                    Avg smaLength;


                    so I dont wrote the first code.

                    The way you are implementing that in your function is incorrect as you are averaging every other value because you are multiplying by two.
                    myArray[i] = low(-2*i); is for the for-loop, I thought I get the correct result for my low(-2) with this "own sma".

                    PHP Code:
                    myArray[1] = low(-2);
                    myArray[2] = low(-4);
                    myArray[3] = low(-6);
                    ...
                    myArray[10] = low(-20);


                    Avg = (myArray[1] + myArray[2] + myArray[3] + ... + myArray[10]) / 10
                    Isnt it the solution for an own sma with low(-2)?



                    Is the line:
                    PHP Code:
                    if (s1==null||s2==null) return; 
                    important for performance?
                    Last edited by franzmey; 01-13-2006, 06:07 PM.
                    Franz

                    Comment


                    • #11
                      Hi franzmey,

                      You are most welcome.

                      Originally posted by franzmey
                      so I dont wrote the first code.



                      myArray[i] = low(-2*i); is for the for-loop, I thought I get the correct result for my low(-2) with this "own sma".

                      PHP Code:
                      myArray[1] = low(-2);
                      myArray[2] = low(-4);
                      myArray[3] = low(-6);
                      ...
                      myArray[10] = low(-20);


                      Avg = (myArray[1] + myArray[2] + myArray[3] + ... + myArray[10]) / 10
                      Isnt it the solution for an own sma with low(-2)?
                      your moving average function is different than any I have seen. Your moving average as you have written equates to this

                      Avg = (low(-2)+low(-4)+low(-6)+low(-8)+low(-10)+low(-12)+low(-14)+low(-16)+low(-18)+low(-20))/10;

                      you skip every other previous low value, e.g. 3,5,7,9,11,13,15,17,19

                      I expected something more like this:

                      Avg = (low(-2)+low(-3)+low(-4)+low(-5)+low(-6)+low(-7)+low(-8)+low(-9)+low(-10)+low(-11))/10;

                      If that is what you want however, then I retract my comment.
                      Last edited by Guest; 01-13-2006, 06:30 PM.

                      Comment


                      • #12
                        With the next changes it works.

                        PHP Code:
                        var myArray = new Array();
                        function 
                        main()
                        {

                            
                        Avg 0;
                            
                        smaLength 10;
                            for (
                        0smaLengthi++)
                            {
                                
                        2;
                                
                        myArray[i] = low(-j);
                                
                                
                        Avg Avg myArray[i];
                            }

                            
                        Avg Avg smaLength;
                            
                            return 
                        Avg;

                        your moving average function is different than any I have seen
                        You are right, mistake in reasoning of me.

                        I assumed that the next bar of low(-2) is low(-4), but thats not true, the next bar value of low(-2) is low(-3).

                        Thanks for your reference!


                        you skip every other previous low value, e.g. 3,5,7,9,11,13,15,17,19
                        With j = i * 2; it seems to function.
                        Last edited by franzmey; 01-13-2006, 07:27 PM.
                        Franz

                        Comment


                        • #13
                          franzmey,

                          Originally posted by franzmey
                          With j = i * 2; it seems to function.
                          It cannot be a multiplication as you will be in the same situation as before.

                          PHP Code:
                          var myArray = new Array();
                          function 
                          main()
                          {
                              var 
                          Avg 0;
                              var 
                          smaLength 10;
                              var 
                          = -2;
                              for (
                          0smaLengthi++)
                              {
                                  
                          Avg += low(n-i);
                              }
                               return 
                          Avg smaLength;

                          Comment


                          • #14
                            Steve,

                            I updated my previous post ("j = i + 2;"), thats my version, which I wanted to show (its maybe to late for me, I should go to the bed ).


                            Is the line:
                            PHP Code:
                            if (s1==null||s2==null) return; 
                            important for you (performance)?
                            Last edited by franzmey; 01-13-2006, 07:48 PM.
                            Franz

                            Comment


                            • #15
                              Originally posted by franzmey

                              Is the line:
                              PHP Code:
                              if (s1==null||s2==null) return; 
                              important for you (performance)?
                              A check for null is always good practice, and will have no impact on your efs performance.

                              If you wanted, the efs I posted could easily be rewritten to include the technique Alex used to check for null as follows:

                              PHP Code:
                              function preMain(){
                               
                              setPriceStudy(true);
                               
                              setShowTitleParameters(false);
                               
                              setStudyTitle("3 ma");
                               
                              setShowCursorLabel(true);
                                  
                               
                              setCursorLabelName("s1"0);
                               
                              setCursorLabelName("s2"1);
                               
                              setCursorLabelName("s2(-4)"2);
                                  
                               
                              setDefaultBarFgColor(Color.blue0);
                               
                              setDefaultBarFgColor(Color.red1);
                               
                              setDefaultBarFgColor(Color.green2);
                                  
                               
                              setDefaultBarThickness(2,0);
                               
                              setDefaultBarThickness(2,1);
                               
                              setDefaultBarThickness(2,2);
                              }

                              var 
                              bInit false;
                              var 
                              s1;var s2;

                              function 
                              main(){
                               if(
                              s1==null)s1 offsetSeries(sma(10,low()), 2);
                               if(
                              s2==null)s2 sma(10,low());   
                               return new Array(
                              s1.getValue(0),s2.getValue(0),s2.getValue(-4));

                              Comment

                              Working...
                              X