Announcement

Collapse
No announcement yet.

Syntax questions on multiple time intervals.

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

  • Syntax questions on multiple time intervals.

    If I have a function parameter "nInterval" defined in premain initialized with a value of 60 for example. Can I pass that value to the getBarStateInterval() function?

    I tried getBarStateInterval("nInterval") and getBarStateInterval("+nInterval") which didn't generate a syntax error but doesn't appear be accomplishing what I intended. I'm don't know how to display through debugPrintl() the actual value being passed to getBarStateInterval to diagnose the problem.


    Thank You,

    Glen
    Last edited by demarcog; 12-18-2006, 11:16 AM.
    Glen Demarco
    [email protected]

  • #2
    Glen

    If I have a function parameter "nInterval" defined in premain initialized with a value of 60 for example. Can I pass that value to the getBarStateInterval() function?
    Use nInterval+"" which will convert nInterval to a string as required by the getBarStateInterval() function (see the linked article for the description and syntax)
    Alex

    Comment


    • #3
      Alexis,

      Thank you very much.
      Glen Demarco
      [email protected]

      Comment


      • #4
        Glen
        You are most welcome
        In addition to the method shown in my prior reply another way to convert a value to a string is to use the .toString() method. Using your example you would write nInterval.toString()
        If interested in learning more about JavaScript then see the Core JavaScript Guide which is included in the EFS KnowledgeBase
        Alex

        Comment


        • #5
          Alexis,

          I used your first method and seemed to work fine, then for some reason, the code controlled by getBarStateInterval(nint3+"") was never being executed. (see attached file).

          I was able to get around the problem by combining the buy and sell condition tests together but it was really strange.


          I'll try the origional code with the new method as I'm curious if that code will execute.

          BTW, out of curosity in all the testing of systems you have done, have you found that the performance of systems is improved by looking for similiar criteria on larger time frames?

          I'll attach that snipper of code if you are interested (I'm using the Customer Support - Esignal Forum Menu option to type this and the copy & paste keys are disabled when I access the forum that way.. so I have to attach instead of copy it in this message).

          Thanks Again

          Glen
          Attached Files
          Last edited by demarcog; 12-18-2006, 09:39 PM.
          Glen Demarco
          [email protected]

          Comment


          • #6
            Glen
            As far as I can see it is working at my end. Here is the code I used to run the test
            PHP Code:
            function main(){

                var 
            nint3 20;
                var 
            nint2 10;
                var 
            nint1 =  5;
             
                if (
            getBarStateInterval(nint3+"")  == BARSTATE_NEWBAR) {    
                    
            debugPrintln("new 20 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                } 
                if (
            getBarStateInterval(nint2+"")  == BARSTATE_NEWBAR) {    
                    
            debugPrintln("new 10 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                } 
                if (
            getBarStateInterval(nint1+"")  == BARSTATE_NEWBAR) {    
                    
            debugPrintln("new 5 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                } 
                
                return;

            and enclosed below is the result displayed in the Formula Output Window
            I would suggest that you debug your code line by line to find out where your code is not executing
            Alex

            Comment


            • #7
              Alexis,

              Thanks for taking the time to look into that, I appreciate it.

              I know it sounds bazaar, but it was the 4th time I called getBarStateInterval() that seemed to be ignored.

              I attaced your code with one more call ..
              Attached Files
              Glen Demarco
              [email protected]

              Comment


              • #8
                Glen
                You can have more than 3 getBarStateInterval() calls (see the following code and snapshot of the Formula Output Window) however as far as I know they cannot be to the same interval.

                PHP Code:
                function main(){

                    var 
                nint3 20;
                    var 
                nint2 10;
                    var 
                nint1 =  5;
                    var 
                nint0 =  3;//added variable

                    
                if (getBarStateInterval(nint3+"")  == BARSTATE_NEWBAR) {    
                        
                debugPrintln("new 20 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    if (
                getBarStateInterval(nint2+"")  == BARSTATE_NEWBAR) {    
                        
                debugPrintln("new 10 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    if (
                getBarStateInterval(nint1+"")  == BARSTATE_NEWBAR) {    
                        
                debugPrintln("new 5 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    if (
                getBarStateInterval(nint0+"")  == BARSTATE_NEWBAR) {//changed interval    
                        
                debugPrintln(" 4th added gd new 3 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    
                    return;



                If you need to create multiple getBarStateInterval() conditional statements for the same interval then you need to use the following logic which BTW is the more efficient method regardless.

                PHP Code:
                function main(){

                    var 
                nint3 20;
                    var 
                nint2 10;
                    var 
                nint1 =  5;
                    
                    var 
                nBarState_5 getBarStateInterval(nint1+"");

                    if (
                getBarStateInterval(nint3+"")  == BARSTATE_NEWBAR) {    
                        
                debugPrintln("new 20 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    if (
                getBarStateInterval(nint2+"")  == BARSTATE_NEWBAR) {    
                        
                debugPrintln("new 10 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    if (
                nBarState_5  == BARSTATE_NEWBAR) {    
                        
                debugPrintln("new 5 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    if (
                nBarState_5  == BARSTATE_NEWBAR) {    
                        
                debugPrintln(" 4th added  gd new 5 min bar"+"  "+hour(0)+":"+(minute(0)<10?"0"+minute(0):minute(0)))
                    } 
                    
                    return;

                Notice in the following image that the fourth statement will execute even though it is based on the same interval as the third one.
                Alex

                Comment


                • #9
                  Alexis,

                  Thanks very much for your help. I appreciate the alternative, more efficient technique.

                  Also as an aside, I have been trying to figure out how to get a readable time stamp in the output of my degug statements and love the technique you used.

                  I would be interested in the developers response.


                  Thanks again for all you invaluable assistance.

                  Glen
                  Glen Demarco
                  [email protected]

                  Comment

                  Working...
                  X