Announcement

Collapse
No announcement yet.

100 % CPU Usage

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

  • 100 % CPU Usage

    Take a quick look at this EFS script:

    function preMain() {
    }

    // Global Variables

    var dLastVol = 0;
    var dTickID = 0;
    var study1 = new MAStudy(10, 0, "Close", MAStudy.Simple);
    var study2 = new MAStudy(50, 0, "Close", MAStudy.Simple);

    function preMain() {
    setPriceStudy(true);
    }


    function main() {

    var vMA1 = study1.getValue(MAStudy.MA);
    var vMA2 = study2.getValue(MAStudy.MA);

    // Data Values
    var dClose = close(0);
    var dLow = low(0);
    var dHigh = high(0);
    var dOpen = open(0);
    var dVolume = volume(0);
    if (volume(0) < dLastVol)
    {
    //New Candle
    dLastVol =0
    }
    var dCurVol = (volume(0) - dLastVol);
    dLastVol = volume(0);
    dTickID ++;

    //Time Values
    var tYear = getYear(0);
    var tMonth = getMonth(0);
    var tDay = getDay(0);
    var tHour = getHour(0);
    var tMinute = getMinute(0);
    var tSecond = getSecond(0);

    //Print Data Values
    debugPrint("MA Val: " + vMA1 + "\n");
    debugPrint("Open : " + dOpen + "\n");
    debugPrint("High : " + dHigh + "\n");
    debugPrint("Low : " + dLow + "\n");
    debugPrint("Close : " + dClose + "\n");
    debugPrint("Vol : " + dVolume + "\n");
    debugPrint("Tick Vol: " + dCurVol + "\n");
    debugPrint("Tick ID: " + dTickID + "\n");

    //Print Time Values
    debugPrint("\n");
    debugPrint("Date: " + tMonth +"/"+ tDay + "/" + tYear + "\n");
    debugPrint("Time: " + tHour +":"+ tMinute + "." + tSecond + "\n");

    return (vMA1);

    }

    It doesnt really do much, just prints out the values of the current market data. But the minute I apply it to the chart or reload the saved version it locks my CPU for 25-30 seconds any ideas on why this occurs???

    Thanks

  • #2
    Re: Reply to post '100 % CPU Usage'

    debugPrint is a cpu hog and slow, try limiting your time template to a few
    days, instead of Dynamic 0:00-0:00

    Comment


    • #3
      I believe it is all the debugPrint statements. They are extremely time consuming. These are run for every historical bar. The more output that goes to the formula output screen, the longer they take to process. Try commenting them all out and see what happens.

      Comment


      • #4
        CPU hog

        I realize it hogs the CPU, but what is happenning when I apply the script? Does it process the entire chart? its supposed to just process the current candle (0)???

        Comment


        • #5
          Re: Reply to post '100 % CPU Usage'

          if you want to process the current candle

          if(getCurrentBarIndex()==0){
          .....
          }

          ----- Original Message -----
          From: <[email protected]>
          To: <[email protected]>
          Sent: Monday, January 26, 2004 3:35 PM
          Subject: Reply to post '100 % CPU Usage'


          > Hello dloomis,
          >
          > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          >

          Comment


          • #6
            Yes, it processes every single bar in the chart, unless you do something similar to what Dave suggested. Take your debugPrint statements, and put them in his if statement. Then they will only process on the latest bar, then each new one as they come in.

            Comment


            • #7
              bar ref

              Why does it do that if in my script i say:

              var dClose = close(0);
              var dLow = low(0);
              var dHigh = high(0);
              var dOpen = open(0);
              var dVolume = volume(0);

              doesnt the 0 specify the current bar?
              just trying to get a handle on this is all....

              Thanks

              Comment


              • #8
                Yes, but it will do it to every bar unless you do what Dave suggested.

                Fibbgann
                Excellent book on JavaScript for beginners

                Comment


                • #9
                  Re: Reply to post '100 % CPU Usage'

                  The zero does refer to the current bar, that is correct. But every line of
                  code is executed on every tick, so all these debug stmts get executed when
                  you reload the efs. And every tick after that.

                  ----- Original Message -----
                  From: <[email protected]>
                  To: <[email protected]>
                  Sent: Monday, January 26, 2004 3:58 PM
                  Subject: Reply to post '100 % CPU Usage'


                  > Hello dloomis,
                  >
                  > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  >

                  Comment


                  • #10
                    I saw the question on your other post and I now understand the confusion but what is happenning when I apply the script I assumed you meant initial load, or when you reload. That processes all the historical bars in the chart.

                    Once they have all been processed, the efs will process every tick, unless instructed to do otherwise. This will also give you problems. You have to put an if statement in there to process once the bar is completed. The following is true every bar


                    PHP Code:
                           if (/* getValue("rawtime",0) != nLastRawTime || */ getBarState() == BARSTATE_NEWBAR) {     
                            
                    nLastRawTime getValue("rawtime",0);
                            
                    barcount++;
                    ....


                    I would recommend using getBarState() == BARSTATE_NEWBAR if the bars are over 1 minute and getValue("rawtime",0) != nLastRawTime if they are under one minute.

                    Comment


                    • #11
                      Less than 1 minute bars

                      How can you display less than 1 minute bars? i only see 1 minute, and tick, is there a finer grainularity you can reach somehwere?

                      Does anyone know where to get historical tick data? I have found Tickdata.com but i need data that includes contract volume, and they do not. just looking for the eMini S&P.

                      Thanks,
                      Gavin

                      Comment


                      • #12
                        press the comma key, and you will see a window pop up. The example image has a 3 Second, continuous eMini contract selected.
                        Attached Files

                        Comment

                        Working...
                        X