Announcement

Collapse
No announcement yet.

Summation Function?

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

  • Summation Function?

    Is there a "Summation Function" in efs to short and speedup my code?

    PHP Code:
    var myVar null;
    function 
    main()
    {
        
        if (
    myVar == null) {myVar close();}

        return (
    myVar.getValue(0)+myVar.getValue(-1)+myVar.getValue(-2)+myVar.getValue(-3)+myVar.getValue(-4)-myVar.getValue(-5))/4;
        

    e.g.

    PHP Code:
    var myVar null;
    function 
    main()
    {
        
        if (
    myVar == null) {myVar close();}

        return (
    Summation(myVar.getValue(),5) - myVar.getValue(-5))/4;
        

    Franz

  • #2
    Franz
    To create the sum shown in your example just do a for loop as in the code enclosed below
    Alex

    PHP Code:
    var myVar null;
     
    function 
    main(){
     
        var 
    Length 5;
        var 
    Sum 0;
        var 
    AvgSum 0;
     
        if(
    myVar==nullmyVar close();
        
        if(
    myVar.getValue(-Length)==null) return;//null check
     
        
    for (var i=0i<Lengthi++){
            
    Sum += myVar.getValue(-i);
        }
     
        
    AvgSum = (Sum-myVar.getValue(-5))/4
     
        
    return AvgSum;

    Comment


    • #3
      Alex,

      thank you for you post!

      But your code is 60% slower (Total Time in EFS Performance Monitor) than my "long" line.

      On a 3 day 2T test I got 563 ms and 55446 calls with your code and 343 ms and 55446 calls with my.

      I think, we cannot optimize no more this code-example, although your code is more simply, if we had still more "close-values".


      Its maybe possible to reduce series-length, e.g. myVar to 5 (I need only 5 Values and not all closes in the chart) or optimizes the efs2-engine this?
      Franz

      Comment


      • #4
        Franz
        FWIW the results I get on the Performance Monitor indicate that there is virtually no difference between the two methods.
        In the following two sets of images you can see the results of one of these tests which were taken while loading the efs on a 1 minute chart over 60 days and measuring the performance of each formula on its own so as to avoid favoring either one. The average range of the tests measured between 0.017 milliseconds and 0.025 milliseconds for either efs.





        As you can see above the measurements on first load are within a tenth of a millisecond (ie a tenth of a thousandth of a second) on average. Total load time of your script was 461 ms (ie 0.461 seconds) and of my script 470 ms (ie 0.470 seconds)
        I also ran the test using Tick Replay to see how the two efs would perform in real time. In the following two images you can see the results taken over 3 days of a 10T chart of ES H6.





        In real time the method I suggested actually returned slightly better results on average but even in this case we are looking at insignificant differences ie within perhaps 0.5 second total time over the course of three days.
        So my suggestion is to not get too focused on the Performance Monitor unless you see macroscopic differences in the average times. Also consider that all the time measurements shown in the Performance Monitor are expressed in milliseconds.
        Alex

        Comment


        • #5
          Alex,

          thank you for your detailed illustrating!

          I tested it now with 2 separate charts and the first load of the indicators (before it, I used the same chart and reloaded the indicators), but I see although a something more larger differentiated than with you.

          But you are right, if did not differentiate is so large, should I use rather the more "comfortable" code.


          I was only surprised, that on my machine that differentiated was so large and if I use many functions which are interlocked, the time adds itself, so that I have to wait 5-10 or more additional seconds, if I use the more comfortable code.
          Attached Files
          Franz

          Comment


          • #6
            Franz
            When running tests with the Performance Monitor I would suggest running one efs at a time so as to ensure that the process is not affected by other factors [caching etc].
            As to the extra load time you are experiencing that could be related to other inefficiencies in the code you are using but without seeing how it is structured it is impossible to determine what could be causing it.
            All I can tell you is what I am able to verify at my end and that is that the difference - if any - between those two methods is marginal at best.
            Alex

            Comment

            Working...
            X