Announcement

Collapse
No announcement yet.

I got a problem in my new formula...

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

  • I got a problem in my new formula...

    Hello i coded a formula and ever when i'm running it i get an error message...
    here is the sourcecode

    Ps: i defined var a... ( var a = 2; )
    PHP Code:
    ...
    if(
    nInputLength == 100){
    var 
    1;
    }
    if(
    nInputLength == 0){
    var 
    0;
    }
    if(var 
    == && nInputLength 0){
    setBarBgColor(Color.RGB(0,255,0));
    var 
    1;
    }
    if(var 
    == && nInputLength 100){
    setBarBgColor(Color.RGB(255,0,0));
    var 
    0;
    }
    ... 
    and this is the wonderful notice of the formula output:
    syntax error:
    if(var a == 0 && nInputLength < 100){
    ...^
    can anybody tell me whats wrong in there and has anybody got a list with all these messages and its meanings ???
    thanks and regards eric

  • #2
    Hello eric,

    You only need to initialize the variable once with var. Try the following.

    PHP Code:
    if(nInputLength == 100){
     
    1;
    }
    if(
    nInputLength == 0){
     
    0;
    }
    if(
    == && nInputLength 0){
    setBarBgColor(Color.RGB(0,255,0));
     
    1;
    }
    if(
    == && nInputLength 100){
    setBarBgColor(Color.RGB(255,0,0));
     
    0;

    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
      sorry but this wasn't the problem ... the syntax error did not disappear ... is it possible that there is something wrong in the condition ?

      if(a == 1 && nInputLength > 0){
      ...

      should i modifie nInputLength

      regards erilein

      Comment


      • #4
        Hello Eric,

        There's not enough information here to determine the problem. Please post your complete formula so I can test it.
        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


        • #5
          Hello Eric,

          In your code you sent via PM, there are still two "var" that need to be removed from your last two if statements. Try the following.

          PHP Code:
          function preMain() {
              
          setStudyTitle("StochasticRSI-Neu");
              
          setCursorLabelName("S-RSI");
              
          setStudyMin(0);
              
          setStudyMax(100);
            
              
          addBand(20PS_SOLID1Color.black);
              
          addBand(80PS_SOLID1Color.black);
                 
          }

          var 
          aryRSI        null;
          var 
          nRsiCount     0;
          var 
          a             2;

          function 
          main(nInputLength) {
              if(
          nInputLength == null) {
                  
          nInputLength 15;
              }
              
              var 
          nBarState getBarState();
              if(
          nBarState == BARSTATE_ALLBARS) {
                  
          aryRSI null;
                  
          nRsiCount 0;
              }

              if(
          aryRSI == null) {
                  
          aryRSI = new Array(nInputLength);
                  
          nRsiCount 0;
              }
              
              var 
          vRSI call("/Library/RSIEnhanced.efs"nInputLength);
              if(
          vRSI == null)
                  return;
              

              if(
          nRsiCount nInputLength) { // prime the array
                  
          aryRSI[nRsiCount] = vRSI;
                  
          nRsiCount++;
                  return;
              } 
              
              
              if(
          nBarState == BARSTATE_NEWBAR) {
                  
          aryRSI.shift();
                  
          aryRSI.push(vRSI);
              } else if(
          nBarState == BARSTATE_CURRENTBAR) {
                  
          aryRSI[nInputLength-1] = vRSI;
              }
              
              var 
          vRSIHH aryRSI[0];
              var 
          vRSILL aryRSI[0];
              var 
          i;
              
              for(
          1nInputLengthi++) {
                  
          vRSIHH Math.max(vRSIHHaryRSI[i]);
                  
          vRSILL Math.min(vRSILLaryRSI[i]);
              }
              
              var 
          vStochRSI = ((vRSI vRSILL) / (vRSIHH vRSILL)) * 100;
              
          if(
          nInputLength == 100){
           
          1;
          }
          if(
          nInputLength == 0){
           
          0;
          }
          if(
          == && nInputLength 0){ setBarBgColor(Color.RGB(0,255,0));
           
          1;
          }
          if(
          == && nInputLength 100){ setBarBgColor(Color.RGB(255,0,0));
           
          0;
          }
              return 
          vStochRSI;

          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


          • #6
            i dont know but there seems to be a other problem in this formula because backgroundcolor doesnt work... anyway

            regards erilein

            Comment


            • #7
              Hello Eric,

              The calls to setBarBgColor() aren't occurring because a = 2. Therefore, your two if statements that check for a = 1 or 0 always returns false. You need to change some logic in your formula. Try changing "var a = 2;" to "var a = 1;".

              Use the debugPrintln() function to test your formula's logic to make sure that certain code blocks are executing as you expect them to. You can pass information (i.e. strings, variables, numbers etc.) from your formula to this function to see if your formula is doing what you want. To see the results of the debugPrintln() function, open your Formula Output Window from Tools --> EFS.

              Edit your formula to do the following and you'll see that "a" always equals 2.

              PHP Code:
                  debugPrintln("at bar index: " getCurrentBarIndex() + "   a = " a);
                  if(
              == && nInputLength 0){ 
                      
              setBarBgColor(Color.RGB(0,255,0));
                      
              1;
                  }
                  if(
              == && nInputLength 100){ 
                      
              setBarBgColor(Color.RGB(255,0,0));
                      
              0;
                  } 
              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
                why does the variable a not change ( i am setting a =1 when the line == 100 and i set it 0 when the line = 0...)
                ...pls help
                regards eric

                Comment


                • #9
                  Hello Eric,

                  No problem. First, let's take a look at your complete formula.





                  On line 14 you initialize the variable, a, and set it equal to 2. This is done in the global scope, so a will retain it's value between executions of your formula. Inside your main() function, there isn't any code being executed that changes the value of a to 1 or 0. There are four lines of code that would change the value of a on lines 63, 66, 71 and 75 if the if() statements they are inside of returned true. However, these if() statements return false, so their code blocks are not being executed. Thus, a's initial value of 2 is never changed.

                  Look at line 62 first. nInputLength is set to 15 on line 18. So the if() statements on lines 62 and 65 return false and lines 63 and 66 don't execute. The only way these two if() statements will return true and change the value of a is if you go to "Edit Studies" and set the value of nInputLength to 100 or 0. Only then will a be set to 0 or 1. Otherwise, a will still be equal to 2 so that when the if() statements on lines 69 and 73 check to see if a is equal to 1 or 0, they both return false. Does this make sense?

                  Tell me what you are expecting this formula to do. Perhaps I can help you find a solution.
                  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


                  • #10
                    hi... ok i think i understood what you mean... but thats not realy the same i was planing...

                    ok here is my idea...



                    The red marked things are the changingpoints (upper point - change a to 1 and the low points - change a to 0)

                    The other lines between the changingpoints are only for control
                    (is the nleght > than 0 (when a is 1 ...) and is the nleght < 100 when a = 0 ...) when they reach 100 or 0 a would be changed again...

                    i want to color the background of the chart ( Crossingpoint 1 - Crossingpoint 2 red and Crossingpoint 2 - 3 green)
                    i hope you understand what i mean (i am not sure about that because i learn english only at school...)

                    please help ... regards erilein

                    Comment


                    • #11
                      Hello Eric,

                      I believe the attached will do what you want. Try it out and let me know.

                      Here's the change you need to make to your code. Instead of checking nInputLength you need to check the value of vStochRSI, which is your line being returned to your chart.

                      PHP Code:
                      if(vStochRSI >= 100){
                              
                      1;
                      }
                      if(
                      vStochRSI <= 0){
                              
                      0;
                      }

                      if(
                      == 1){ 
                              
                      setBarBgColor(Color.RGB(255,0,0));
                      }
                      if(
                      == 0){ 
                              
                      setBarBgColor(Color.RGB(0,255,0));

                      Attached Files
                      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


                      • #12
                        thank you for your great help... everything is working fine...
                        regards eric

                        Comment

                        Working...
                        X