Announcement

Collapse
No announcement yet.

Out of memory error while running EFS script

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

  • Out of memory error while running EFS script

    Hi,

    I am hitting out of memory error for my EFS script after it is loaded on the chart for about 2 to 3 hours. The script is attached to about 10 charts. The EFS script will run on each chart on a tick basis ( meaning the setComputenCLose() function is disabled ).
    I am not hitting the out of memory error with setComputeOnCLose() is enabled, which indirectly means that the more number of times my script is executed, the chances of it failing is higher with out of memory error . The esignal program hangs when the above error happens.

    Is there a way I could clear memory or do some sort of garbage collection thru EFS. Any help is highly appreciated.

    thanks
    Francis

  • #2
    Hello Francis,

    If you're running out of memory on a tick-by-tick basis and not under COC, sounds like you may have some logic that is creating some new objects on each execution. To troubleshoot further, please attach your formula code.
    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


    • #3
      One comon problem, along the lines Jason mentions, that I have seen is when creating new lines or other drawXXX() calls. If you create a unique object or line for each call, instead of one per NEWBAR, then it is easy to kill the system (either it lags badly or runs out of memory, or both). Whats worse., even though new objects are drawn and tracked, they often overlay each other visually, so you don't notice this is happening.

      Just a thought...

      Garth
      Garth

      Comment


      • #4
        Jason & Garth,

        Thanks for the reply

        I have a 'drawlinerelative' function call which is called on a tick basis. Would it be the cause of the problem? Also are the objects created in main() are destoyed after the each tick?

        Below is the main extract of the code.

        Golbal declarations..

        var aKeltnerH = new Array(20);
        var aKeltnerL = new Array(20);
        var aKeltnerC = new Array(20);

        var aKeltner = new Array();
        .
        .

        function main() {
        var today = new Date();
        h = today.getHours();
        s = today.toString();
        d = today.getDay();

        if (getBarState() == BARSTATE_NEWBAR) {
        BarCntr +=1;
        }
        .
        .
        .


        vHigh = high(0);
        vLow = low(0);

        for (i = 0; i < 20; ++i) {
        vHigh = Math.max(high(-i), vHigh);
        vLow = Math.min(low(-i), vLow);
        }

        drawLineRelative(-20, vHigh, 0, vHigh, PS_SOLID, 2, Color.red, "High");
        drawLineRelative(-20, vLow, 0, vLow, PS_SOLID, 2, Color.green, "Low");

        aKeltner = Keltner();

        nKeltnerHigh = aKeltner[0];
        nKeltnerCentral = aKeltner[1];
        nKeltnerLow = aKeltner[2];

        aKeltnerH.unshift(nKeltnerHigh);
        aKeltnerC.unshift(nKeltnerCentral);
        aKeltnerL.unshift(nKeltnerLow);

        return new Array(aKeltner[0],aKeltner[1],aKeltner[2] );

        }


        function Keltner()
        {
        if ( getBarState() == BARSTATE_ALLBARS ) {
        return null;
        }


        nBarCounter = BarCntr;


        nCenterLine = ( nCenterLine * ( Period-1 ) + close(-1) ) / Period;
        nAvgRange = ( nAvgRange * ( Period - 1 ) + high(-1)-low(-1) ) / Period;
        nUpperBand = nCenterLine + ( nAvgRange * ATRs );
        nLowerBand = nCenterLine - ( nAvgRange * ATRs );

        if ( nBarCounter > Period ) {
        return new Array( nUpperBand, nCenterLine, nLowerBand );

        }



        Thanks
        Francis

        Comment


        • #5
          FrancisB,

          You are using drawLineRelative() in a way that shouldn't cause problems on a tick by tick basis.

          Instead I believe it is the unshift() method. You are saving values into your array on every tick, and I believe you only want to save it on each NEWBAR.

          Based on the code you posted it doesn't even look like you need the arrays at all, so unless you are using the arrays elsewhere you can just remove the declarations and unshift() statements.
          Garth

          Comment


          • #6
            Garth,

            Thanks for the reply. I plan to use the values in the array to build some conditions for generating signals. I had defined the array size 20, so my understanding was that the unshift array operations should be within that limit.


            I will change the code to do the unshift array operations to be executed only for a new bar and see if the error goes away. Have to wait until the market opens on monday. I will update the post with the results.

            thanks
            Francis

            Comment


            • #7
              FrancisB,

              Just FYI - unshift() changes the size of the array. Using unshift() as you are, you don't have to specify any size when declaring the array.
              Garth

              Comment


              • #8
                Hello Francis,

                Also be aware that the unshift() method used by itself adds an element to the array each time you call it. Your array is continuing to grow by one element on each execution of main(). If you only need to maintain the most recent 20 values, you can drop off the oldest element of each array using the pop() method. This will solve the memory problem.

                aKeltnerH.pop();
                aKeltnerC.pop();
                aKeltnerL.pop();

                aKeltnerH.unshift(nKeltnerHigh);
                aKeltnerC.unshift(nKeltnerCentral);
                aKeltnerL.unshift(nKeltnerLow);
                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


                • #9
                  FrancisB,

                  You are most welcome. I'm glad I could help.
                  Garth

                  Comment


                  • #10
                    Hi Jason,

                    I already added pop() method in the code and now its working fine.
                    Many thanks for helping me to resolve the problem.

                    thanks
                    Francis

                    Comment


                    • #11
                      You're most welcome.
                      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