Announcement

Collapse
No announcement yet.

problem with while loop

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

  • problem with while loop

    the code below works fine if I exclude the if statement

    if(barM >= 570 && barM < 960){

    }

    otherwise it doesn't complete. any ideas?

    Code:
    var sessionArray;
    var ReqLength = 300;
    function sessionData(){
    
        var sSI = getSymbol() + ",60"; 
        var index = 0;
        var barM = 0;
        var nLen = 0;
        var nClose = 0;
        var nRawtime = 0;
        var nHour = 0;
        var nMinute = 0;
    
        sessionArray = new Array();
        while(nLen < ReqLength){
            nClose = getValue("close", -index, 1, sSI)*1;
            nRawtime = getValue("rawtime", -index, 1, sSI)*1;
            nHour = getValue("hour", -index, 1, sSI)*1;
            nMinute = getValue("minute", -index, 1, sSI)*1;
            var tmp = new Object;
            tmp.Close = nClose;
            tmp.Rawtime = nRawtime;
            tmp.Hr = nHour;
            tmp.Mn = nMinute;
            barM = (tmp.Hr*60)+tmp.Mn;
            if(barM >= 570 && barM < 960){
                sessionArray.push(tmp);  
                ++aLen;
            }
            ++index;
        }   
    }
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

  • #2
    also if I replace

    if(barM >= 570 && barM < 960)

    with

    if(barM >= 570)

    it completes ok.

    Code:
    var sessionArray;
    var ReqLength = 300;
    function sessionData(){
    
        var sSI = getSymbol() + ",60"; 
        var index = 0;
        var barM = 0;
        var nLen = 0;
        var nClose = 0;
        var nRawtime = 0;
        var nHour = 0;
        var nMinute = 0;
    
        sessionArray = new Array();
        while(nLen < ReqLength){
            nClose = getValue("close", -index, 1, sSI)*1;
            nRawtime = getValue("rawtime", -index, 1, sSI)*1;
            nHour = getValue("hour", -index, 1, sSI)*1;
            nMinute = getValue("minute", -index, 1, sSI)*1;
            var tmp = new Object;
            tmp.Close = nClose;
            tmp.Rawtime = nRawtime;
            tmp.Hr = nHour;
            tmp.Mn = nMinute;
            barM = (tmp.Hr*60)+tmp.Mn;
            if(barM >= 570 && barM < 960){
                sessionArray.push(tmp);  
                ++nLen;
            }
            ++index;
        }   
    }
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

    Comment


    • #3
      Hi futurenets,

      Have you tried using debugPrintln and troubleshooting yourself? If yes, what did you see, if not, my recommendation is that you give that a shot.


      Steve

      Comment


      • #4
        yes thats how I found the problem. I'm pretty sure this is an internal eSignal efs problem.
        Paul Williams
        Strategy & Applications
        www.futurenets.co.uk

        Comment


        • #5
          ... the process ends prematurely without completing the script.

          something isn't right here.
          Paul Williams
          Strategy & Applications
          www.futurenets.co.uk

          Comment


          • #6
            can someone from eSignal please try this ...

            1. run the following function.
            2. replace "if(barM >= 570){" with "if(barM >= 570 && barM < 960){" and try again.

            the process ends prematurely without completing the script.


            Code:
            var sessionArray;
            var ReqLength = 300;
            function sessionData(){
            
                var sSI = getSymbol() + ",60"; 
                var index = 0;
                var barM = 0;
                var nLen = 0;
                var nClose = 0;
                var nRawtime = 0;
                var nHour = 0;
                var nMinute = 0;
            
                sessionArray = new Array();
                while(nLen < ReqLength){
                    nClose = getValue("close", -index, 1, sSI)*1;
                    nRawtime = getValue("rawtime", -index, 1, sSI)*1;
                    nHour = getValue("hour", -index, 1, sSI)*1;
                    nMinute = getValue("minute", -index, 1, sSI)*1;
                    var tmp = new Object;
                    tmp.Close = nClose;
                    tmp.Rawtime = nRawtime;
                    tmp.Hr = nHour;
                    tmp.Mn = nMinute;
                    barM = (tmp.Hr*60)+tmp.Mn;
                    //if(barM >= 570 && barM < 960){
                    if(barM >= 570){
                        sessionArray.push(tmp);  
                        ++nLen;
                        debugPrintln(sessionArray.length+","+nLen);
                    }
                    ++index;
                } 
            
            }
            Paul Williams
            Strategy & Applications
            www.futurenets.co.uk

            Comment


            • #7
              Hi futurenets.

              I do not believe this is a bug in eSignal. However, in deference to your request, I'll let someone from eSignal address your issue.

              Steve

              Originally posted by futurenets
              can someone from eSignal please try this ...

              1. run the following function.
              2. replace "if(barM >= 570){" with "if(barM >= 570 && barM < 960){" and try again.

              the process ends prematurely without completing the script.


              Code:
              var sessionArray;
              var ReqLength = 300;
              function sessionData(){
              
                  var sSI = getSymbol() + ",60"; 
                  var index = 0;
                  var barM = 0;
                  var nLen = 0;
                  var nClose = 0;
                  var nRawtime = 0;
                  var nHour = 0;
                  var nMinute = 0;
              
                  sessionArray = new Array();
                  while(nLen < ReqLength){
                      nClose = getValue("close", -index, 1, sSI)*1;
                      nRawtime = getValue("rawtime", -index, 1, sSI)*1;
                      nHour = getValue("hour", -index, 1, sSI)*1;
                      nMinute = getValue("minute", -index, 1, sSI)*1;
                      var tmp = new Object;
                      tmp.Close = nClose;
                      tmp.Rawtime = nRawtime;
                      tmp.Hr = nHour;
                      tmp.Mn = nMinute;
                      barM = (tmp.Hr*60)+tmp.Mn;
                      //if(barM >= 570 && barM < 960){
                      if(barM >= 570){
                          sessionArray.push(tmp);  
                          ++nLen;
                          debugPrintln(sessionArray.length+","+nLen);
                      }
                      ++index;
                  } 
              
              }

              Comment


              • #8
                ok thanks. something else ...

                yesterday (May 14) this was working

                var sSI = getSymbol() + ",60";
                aClose = getValue("close", -300, 300, sSI);

                today (May 15) it doesn't work but this does

                var sSI = getSymbol() + ",60";
                aClose = getValue("close", -299, 300, sSI);
                Paul Williams
                Strategy & Applications
                www.futurenets.co.uk

                Comment


                • #9
                  Hi,

                  FWIW I ran the code with "if(barM >= 570 && barM < 960){" on a 1 minute ES #F chart on Saturday (market is closed) and it took a while but it printed to the Output Window correctly. Maybe during real time (and possibly if tested on Tick charts) eSignal is just having trouble keeping up with the real time calculations.

                  Here is the code I used:

                  PHP Code:
                  var sessionArray;
                  var 
                  ReqLength 300;
                  //function sessionData(){
                  function main(){
                      var 
                  sSI getSymbol() + ",60"
                      var 
                  index 0;
                      var 
                  barM 0;
                      var 
                  nLen 0;
                      var 
                  nClose 0;
                      var 
                  nRawtime 0;
                      var 
                  nHour 0;
                      var 
                  nMinute 0;

                      
                  sessionArray = new Array();
                      while(
                  nLen ReqLength){
                          
                  nClose getValue("close", -index1sSI)*1;
                          
                  nRawtime getValue("rawtime", -index1sSI)*1;
                          
                  nHour getValue("hour", -index1sSI)*1;
                          
                  nMinute getValue("minute", -index1sSI)*1;
                          var 
                  tmp = new Object;
                          
                  tmp.Close nClose;
                          
                  tmp.Rawtime nRawtime;
                          
                  tmp.Hr nHour;
                          
                  tmp.Mn nMinute;
                          
                  barM = (tmp.Hr*60)+tmp.Mn;
                          
                  debugPrintln("b - "+barM);
                          if(
                  barM >= 570 && barM 960){
                          
                  //if(barM >= 570){
                              
                  debugPrintln("a - "+barM);
                              
                  sessionArray.push(tmp);  
                              ++
                  nLen;
                              
                  debugPrintln(sessionArray.length+","+nLen);
                          }
                          ++
                  index;
                      } 


                  Ref:
                  PHP Code:
                  aClose getValue("close", -300300sSI); 
                  Not sure but you might check that you had well over 300 bars loaded on the chart via the time template or via going backwards on the chart until you get enough bars loaded.

                  Wayne
                  Last edited by waynecd; 05-15-2010, 05:13 PM.

                  Comment


                  • #10
                    ok thanks Wayne. my orginal code is also working now?
                    Paul Williams
                    Strategy & Applications
                    www.futurenets.co.uk

                    Comment


                    • #11
                      problem resolved here:

                      http://forum.esignal.com/showthread.php?threadid=33529
                      Paul Williams
                      Strategy & Applications
                      www.futurenets.co.uk

                      Comment

                      Working...
                      X