Announcement

Collapse
No announcement yet.

problem while staement

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

  • problem while staement

    Hi Guys,
    I'm looking for the lowest open() or close() and the highest open() or close() in the last 14 candles. The following works but returns over 40 values.... might be because its 5 in the morning but i just can't see how it does it... any ideas ? Seems to me there should only be 14 values returned.

    t_MHigh = null;
    t_MLow = null;

    i = 1;
    while (i <= 14){
    if(t_MHigh == null || close(-i) > t_MHigh) t_MHigh = close(-i);
    if(open(-i) > t_MHigh) t_MHigh = open(-i);

    if(t_MLow == null || close(-i) < t_MLow) t_MLow = close(-i);
    if(open(-i) < t_MLow) t_MLow = open(-i);

    debugPrintln( t_MHigh + " " + t_MooseLow + "\n");
    i = i + 1;
    }

    maybe just a better way ?

  • #2
    Chris747,

    Is it because "t_MooseLow " is not defined which is causing the debug statement to terminate skipping the next step?

    Comment


    • #3
      Hi Steve and thanks,
      It is declared...sorry... that was a problem i just created in putting the script up here

      t_MHigh = null;
      t_MLow = null;

      i = 1;
      while (i <= 14){
      if(t_MHigh == null || close(-i) > t_MHigh) t_MHigh = close(-i);
      if(open(-i) > t_MHigh) t_MHigh = open(-i);

      if(t_MLow == null || close(-i) < t_MLow) t_MLow = close(-i);
      if(open(-i) < t_MLow) t_MLow = open(-i);

      debugPrintln( t_MHigh + " " + t_MLow + "\n");
      i = i + 1;
      }

      like i say... it does work, just returns more than 40 values with the debugPrintln statement

      Comment


      • #4
        Chris747
        While the formula loads it executes one time on each bar so you should have 14 entries for each bar on the chart
        Alex

        Comment


        • #5
          Thanks Alex,
          In fact I have it being triggered on a specific case so it's not running every time the program loads. On further investigation, the problem only seems to occur when i run it over a weekend in my playbacks.

          I've tried using LLV and HHV but that causes my script to reload for some reason occasionly.

          Comment


          • #6
            Chris747

            In fact I have it being triggered on a specific case so it's not running every time the program loads
            That is not apparent from the code snippet you posted. You need to post a complete working code example that illustrates the problem for someone to be able to replicate what you are seeing
            Alex

            Comment


            • #7
              Chris,

              I enclosed a complete* efs which was written to write all of the steps with a tr.ace in them to file. To make this work*, you will have to install the associated library file from here*

              I am not at a location where I can run this efs, but it is relatively straightforward and taken from example (3)a in the referenced library help file. I guarantee you will be able to figure out your issue(s) if you use this method of troubleshooting in your code.



              PHP Code:
              // Chris747 Trace example
              var t1 addLibrary("shUtilities v1.efsLib");   // Library declaration, outside main
              var tr t1.trace(true); // (3) Trace Utility declaration, outside main

              var bInit false;
              var 
              nTitle "example Chris747";

              function 
              preMain(){
               
              setPriceStudy(true);
               
              setStudyTitle(nTitle);
               
              setCursorLabelName("1st",0);
               
              setDefaultBarFgColor(Color.blue0);
               
              setDefaultBarThickness(1,0);
               
              debugClear();
              }

              function 
              main() {
               if(
              bInit == false){
                
              bInit true;
               }
               if (
              getBarState() == BARSTATE_NEWBAR) {
                
              t_MHigh null;
                
              t_MLow null;
                
                
              1;
                
              tr.ace("1: bar = "+getCurrentBarCount());
                while (
              <= 14){
                
                 
              tr.ace("2: i = "+i+" t_MHigh = "+t_MHigh+" close(-i) = "+close(-i)); 
                 if(
              t_MHigh == null || close(-i) > t_MHigh){
                  
              t_MHigh close(-i);
                  
              tr.ace("3: i = "+i+" t_MHigh = "+t_MHigh+" close(-i) = "+close(-i)); 
                  
              tr.ace("4: (t_MHigh == null) = "+(t_MHigh == null)+" (close(-i) > t_MHigh) = "+(close(-i) > t_MHigh)); 
                 }
                
                 
              tr.ace("5: i = "+i+" t_MHigh = "+t_MHigh+" open(-i) = "+open(-i)); 
                 if(
              open(-i) > t_MHigh){
                  
              t_MHigh open(-i);
                  
              tr.ace("6: i = "+i+" t_MHigh = "+t_MHigh+" open(-i) = "+open(-i)); 
                  
              tr.ace("7: (open(-i) > t_MHigh) = "+(open(-i) > t_MHigh)); 
                   }
                
                 
              tr.ace("8: i = "+i+" t_MLow = "+t_MLow+" close(-i) = "+close(-i)); 
                 if(
              t_MLow == null || close(-i) < t_MLow){
                  
              t_MLow close(-i);
                  
              tr.ace("9: i = "+i+" t_MLow = "+t_MLow+" close(-i) = "+close(-i)); 
                  
              tr.ace("10: (t_MLow == null) = "+(t_MLow == null)+" (close(-i) < t_MLow) = "+(close(-i) < t_MLow)); 
                 }
                 
                 
              tr.ace("11: i = "+i+" t_MLow = "+t_MLow+" open(-i) = "+open(-i)); 
                 if(
              open(-i) < t_MLow){
                  
              t_MLow open(-i);
                  
              tr.ace("12: i = "+i+" t_MLow = "+t_MLow+" open(-i) = "+open(-i)); 
                  
              tr.ace("13: (open(-i) < t_MLow) = "+(open(-i) < t_MLow)); 
                 }
                 
                 
              1;
                }
               
              tr.ace("");// a linefeed for readability    
               
              }

              Comment


              • #8
                Hi Steve,
                As usual.. my undying gratitude for taking the time to help me with this. That utility showed me exactly where the problem was.

                "Teach a man to fish...... "

                Thanks,
                Chris

                PS - funny thing, since i posted that question, i now get a response to EVERY post on the bulletin board EVERY time someone responds to a question, whether its mine or otherwise...lol...obviously something broken somewheres.

                Comment


                • #9
                  Hi Chris,

                  You are most welcome, I am pleased the Trace utility worked out for you. I use the same library version of the Trace utility, as this one is particularly
                  fast and easy to use. It helps me figure out similarly difficult issues in my efs code as well.

                  Comment

                  Working...
                  X