Announcement

Collapse
No announcement yet.

where is my mistake?

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

  • where is my mistake?

    What is wrong with this code....

    if (
    (varPivot1 > varPivot2) and (varPivot1 > varPivot3)
    varMaxPivot = varPivot1;


    I keep getting syntax error about a missing paren

  • #2
    Hello coolmoss,

    You're missing the close parenth on your if statement. Try this,

    PHP Code:
    if ((varPivot1 varPivot2) && (varPivot1 varPivot3))
    varMaxPivot varPivot1
    or

    PHP Code:
    if ((varPivot1 varPivot2) && (varPivot1 varPivot3)) {
        
    varMaxPivot varPivot1;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Thnanks

      Jason, thanks much. This was kind of embarassing, but in my defense, I've studied all the online resources for EFS and have yet find ALL the syntax in one concise location.

      I know others in my shoes. It would be of TREMENDOUS help, if in the EFS guide, each function had a complete example, arguments and all. Would go a long way in helping us non-programmers learn this stuff. Just a thought.

      Comment


      • #4
        here's an example....

        I'm not trying to be a whiner, just showing you what I mean.

        I went to the EFS function reference and clicked on the link for addLineTool(). It listed the different shapes that can be drawn. It also mentions 3 of the arguments. But it doesn't even mention what x1, y1, x2, y2. Where am I supposed to guess to go to find this out. I assume it has to do with where the object is drawn, but that hardly allows me to use the function without a huge amount of investment in time search out how those arguments work. Now, this keeps happening over and over, the total time to write even simple stuff is overwhelming.

        Thanks for hearing me out on this.

        Comment


        • #5
          Jason, I tried exactly what you had, still getting the same syntax error.

          Comment


          • #6
            FWIW, a little cheese.




            I picked drawing functions and here is what came up



            Then I picked drawline relative and here is what came up



            regarding your syntax error, replace "and" with "&&"

            Comment


            • #7
              Hello coolmoss,

              I overlooked an important detail in your code. Hopefully the info Steve posted helped you figure it out already. If not, all you need to do is change both instances of the and in the code snippet I provided with the logical and symbol, &&. I've already made the change in my previous post so you can copy that code if you like.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment


              • #8
                Jason, yes, I finally figured that out.

                Perhaps you would comment on this:

                I now run syntax check and it shows no errors. I end up with a blank indicator pane, but my return line is null. Setprice study was "true", but I also tried erasing it altogether. I've written simple EFS's before and never had these kind of problems.

                I would swear that at some point I was clicking on the check button and it showed no errors until I loaded chart. Between this and the no error description above, I made no changes, just reloaded several times.

                Any guesses to any of this?

                Comment


                • #9
                  Hello coolmoss,

                  The syntax checker can only check for the general syntax errors. For example, a missing parenthesis or end brace. You should not expect that if the syntax checker says you have no errors, that your formula will work as you're expecting. In addition to the syntax being correct, the code logic also has to produce a logical result. A syntax checker cannot make judgements as to what the programmer is intending to accomplish. Making sure the logic is correct is entirely up to human intervention. The process of making sure the logic is correct is referred to as debugging. For a very basic example of this, take a look at the code below.

                  PHP Code:
                  function preMain() {
                      
                  setPriceStudy(true);
                      
                  setCursorLabelName("MA");
                  }


                  var 
                  vStudy = new MAStudy(100"Close"MAStudy.SIMPLE);
                  var 
                  bVar true;


                  function 
                  main() {
                      var 
                  vMA;
                      
                      if (
                  bVar == false) {
                          
                  vMA vStudy.getValue(MAStudy.MA);
                      }
                      
                      return 
                  vMA;

                  When we run a syntax check on this code, there are no errors. However, if we run this on a chart, the moving average is not getting returned to the chart. The syntax is correct, but the code logic here is the problem. In this example, it's easy to spot the problem. The global variable, bVar, was initialized as true, but in main we are checking to see if it is false in order to set vMA to the current MA value. This formula never gets inside that if statement.

                  When you have a formula with hundreds of lines of code, the logic errors can be hard to spot visually. What you need to do is start placing debugPrintln() statements throughout your code to help pinpoint the problem. I recommend that you don't use too many at once. Moving one statement around will usually do the trick. The function takes a string as a parameter and prints the string to the Formula Output Window. You could simply do debugPrintln("hello"); to see if your code logic is reaching a certain area of your formula. You can also build a string that includes your variables, which is what I'm about to do below.

                  PHP Code:
                  function preMain() {
                      
                  setPriceStudy(true);
                      
                  setCursorLabelName("MA");
                  }


                  var 
                  vStudy = new MAStudy(100"Close"MAStudy.SIMPLE);
                  var 
                  bVar true;


                  function 
                  main() {
                      var 
                  vMA;
                      
                      if (
                  bVar == false) {
                          
                  vMA vStudy.getValue(MAStudy.MA);
                          
                  debugPrintln("hello " vMA);
                      }
                      
                      return 
                  vMA;

                  Now we have a debug line inside the if statement. However, when we run the formula in the chart, nothing gets printed to the output window. This tells us that the conditional if statement is not evaluating to what we were expecting. The next step is to scrutinize that if statement. So we move the debugPrintln() statement outside of the if statement and check the value of bVar.

                  PHP Code:
                  function preMain() {
                      
                  setPriceStudy(true);
                      
                  setCursorLabelName("MA");
                  }


                  var 
                  vStudy = new MAStudy(100"Close"MAStudy.SIMPLE);
                  var 
                  bVar true;


                  function 
                  main() {
                      var 
                  vMA;
                      
                      
                  debugPrintln("hello " bVar);
                      if (
                  bVar == false) {
                          
                  vMA vStudy.getValue(MAStudy.MA);
                      }
                      
                      return 
                  vMA;

                  Now, when you run the formula in the chart we get "hello true" printed to the output window everytime main() is executed. Now we know where the logic error is. We change either the value where bVar is declared or we change the if statement and off we go.

                  This is a simplified example, but the concept is the same no matter how many lines of code you have.

                  Our KnowledgeBase only covers our EFS extensions to the JavaScript 1.5 langauge. We are not currently providing all the information about the core language functions. We have pointed out some external resources to learn more about the core language in our KB article, All About JavaScript - The Foundation of EFS. There are also some helpful guides under Help Guides in the EFS KnowledgeBase that you should read through, if you haven't already.

                  As to the specific problem with your formula, it's nearly impossible to say what the cause is without seeing the code. If you go through this debugging process, I'm sure you discover the problem areas. Let us know how it goes.
                  Jason K.
                  Project Manager
                  eSignal - an Interactive Data company

                  EFS KnowledgeBase
                  JavaScript for EFS Video Series
                  EFS Beginner Tutorial Series
                  EFS Glossary
                  Custom EFS Development Policy

                  New User Orientation

                  Comment

                  Working...
                  X