Announcement

Collapse
No announcement yet.

ibarHour = getHour(0) Is ibarHour a number? Why does it not read it as a number?

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

  • ibarHour = getHour(0) Is ibarHour a number? Why does it not read it as a number?

    I have a program that will not work and I can't figure out why. In funciton main() I am reading the minute, hour, and day of the bars in a one minute chart. I can place a debugPrintln() immediately after where it reads what ibarHour is and it will give it to me. But when it comes time to read these numbers as ibarMinute, ibarHour, and ibarDay in an if statement it will not read the numbers, especially in this line:
    if(ibarHour = 9 && ibarMinute = 30) {
    Is ibarHour a number or something else?

    The goal is to determine the slope, intercept and r2 for data between 9:30 AM and 10:30 AM EST.

    Been working on this for 9 hours with no luck, can anyone help out please??? If I am not clear in explanation, please let me know.

    PHP Code:
    debugClear()

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("First Hour Trading");
        
    setShowCursorLabel(false);
    }

    function 
    main() {
        
        var 
    ibarHour getHour(0);
        var 
    ibarMinute getMinute(0);
        var 
    ibarDay getDay(0);
        
        
    iLength 60;
        
        if(
    ibarHour && ibarMinute 30) { //This line produces an error, why??
                
    var isumx 0;
                var 
    vsumy 0;
                var 
    vmultxy 0;
                var 
    vsquaredy 0;
                var 
    vsquaredx 0;
            }
        }
            
        if(
    ibarHour 10 && ibarMinute <= 30) {  //calculates from 10:00 to 10:30 AM
                
    var isumx isumx 1;
                var 
    vsumy vsumy close(0);
                var 
    vmultxy =  vmultxy + (isumx close(0));
                var 
    vsquaredy vsquaredy + (close(0) * close(0));
                var 
    vsquaredx vsquaredx + (isumx isumx);
            }
        }
             
        if(
    ibarHour && ibarMinute <= 59) { //Calculates from 9:30 to 10:00 AM and adds them to the one above.
                
    isumx isumx 1;
                
    vsumy vsumy close(0);
                
    vmultxy =  vmultxy + (isumx close(0));
                
    vsquaredy vsquaredy + (close(0) * close(0));
                
    vsquaredx vsquaredx + (isumx isumx);
            }
        }
      
    // Calculates slope, intercept, and r2      
        
    slope = (iLength * (vmultxy vsumy isumx))/(iLength * (vsquaredx isumx isumx));
        
    intercept = (vsumy slope isumx)/iLength;
        
    r1 = (iLength vmultxy isumx vsumy);
        
    r2 = ((iLength vsquaredx isumx isumx) * (iLength vsquaredy vsumy vsumy));
        
    rsquare = (r1 r2) * (r1 r2);
        
              
        return;


  • #2
    Re: ibarHour = getHour(0) Is ibarHour a number? Why does it not read it as a number

    WantToLearn
    If you look at the message in the Formula Output Window it tells you the reason for the error ie that you have an invalid assignement.
    This is because in your conditional statement you are using an assignement operator = instead of a comparison operator ==
    You may want to review section 2.5 Most Commonly Used Operators in the Beginner Tutorial2: Commonly Used Core Javascript which is in the EFS KnowledgeBase in the Help Guides and Tutorials folder
    Alex


    Originally posted by WantToLearn
    I have a program that will not work and I can't figure out why. In funciton main() I am reading the minute, hour, and day of the bars in a one minute chart. I can place a debugPrintln() immediately after where it reads what ibarHour is and it will give it to me. But when it comes time to read these numbers as ibarMinute, ibarHour, and ibarDay in an if statement it will not read the numbers, especially in this line:
    if(ibarHour = 9 && ibarMinute = 30) {
    Is ibarHour a number or something else?

    The goal is to determine the slope, intercept and r2 for data between 9:30 AM and 10:30 AM EST.

    Been working on this for 9 hours with no luck, can anyone help out please??? If I am not clear in explanation, please let me know.

    PHP Code:
    debugClear()

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("First Hour Trading");
        
    setShowCursorLabel(false);
    }

    function 
    main() {
        
        var 
    ibarHour getHour(0);
        var 
    ibarMinute getMinute(0);
        var 
    ibarDay getDay(0);
        
        
    iLength 60;
        
        if(
    ibarHour && ibarMinute 30) { //This line produces an error, why??
                
    var isumx 0;
                var 
    vsumy 0;
                var 
    vmultxy 0;
                var 
    vsquaredy 0;
                var 
    vsquaredx 0;
            }
        }
            
        if(
    ibarHour 10 && ibarMinute <= 30) {  //calculates from 10:00 to 10:30 AM
                
    var isumx isumx 1;
                var 
    vsumy vsumy close(0);
                var 
    vmultxy =  vmultxy + (isumx close(0));
                var 
    vsquaredy vsquaredy + (close(0) * close(0));
                var 
    vsquaredx vsquaredx + (isumx isumx);
            }
        }
             
        if(
    ibarHour && ibarMinute <= 59) { //Calculates from 9:30 to 10:00 AM and adds them to the one above.
                
    isumx isumx 1;
                
    vsumy vsumy close(0);
                
    vmultxy =  vmultxy + (isumx close(0));
                
    vsquaredy vsquaredy + (close(0) * close(0));
                
    vsquaredx vsquaredx + (isumx isumx);
            }
        }
      
    // Calculates slope, intercept, and r2      
        
    slope = (iLength * (vmultxy vsumy isumx))/(iLength * (vsquaredx isumx isumx));
        
    intercept = (vsumy slope isumx)/iLength;
        
    r1 = (iLength vmultxy isumx vsumy);
        
    r2 = ((iLength vsquaredx isumx isumx) * (iLength vsquaredy vsumy vsumy));
        
    rsquare = (r1 r2) * (r1 r2);
        
              
        return;

    Comment


    • #3
      I spent a lot of time trying to figure this out. I even did it the "right" way but there must have been some other things wrong so I did not get it.

      I reread the section you referred me to and applied and it worked on the first change. Some of the simpliest things can give me the biggest problems (but I won't make this mistake again!).

      Once again, a big thank you Alex for straightening me out.



      if (ibarHour == 9 && ibarMinute == 30) {

      Comment


      • #4
        WantToLearn
        You are welcome
        Alex


        Originally posted by WantToLearn
        I spent a lot of time trying to figure this out. I even did it the "right" way but there must have been some other things wrong so I did not get it.

        I reread the section you referred me to and applied and it worked on the first change. Some of the simpliest things can give me the biggest problems (but I won't make this mistake again!).

        Once again, a big thank you Alex for straightening me out.



        if (ibarHour == 9 && ibarMinute == 30) {

        Comment

        Working...
        X