Announcement

Collapse
No announcement yet.

if and or else statements

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

  • if and or else statements

    I am trying to compair two values in a pre test befor executing a control statement within an if statement.

    The syntax I am using is as follows...

    total = if ((tangent1 > 0) && (momDelta < 0)) {
    tangent1 - Math.abs (momDelta);
    }else {
    tangent1 + momDelta;
    }

    I keep getting a syntax error on the pre test line. I am trying to do something like this.

    If Tangent 1 is greater than 0 and Mom Delta is less than 0, then do this.

    Also, is my math (abs.) function done properly as well???

    Also later on in the code I am trying to test to see if a value for (x) is greater than or equal to (y). The syntax I am using for that is


    If (x > || == y) {
    tangent1 + mom;
    }
    else {
    mom - tangent1;
    }

    Any help is appreciated,

    John

  • #2
    Re: if and or else statements

    John
    In the first snippet of code the syntax used to assign a value to the variable total is incorrect. It should be
    PHP Code:
    if ((tangent1 0) && (momDelta 0)) {
        
    total tangent1 Math.abs (momDelta);
    }else {
        
    total tangent1 momDelta;

    As to the second snippet of code the comparison operator you need to use is >= in place of >||== which is not valid syntax. For a description of all the available operators see this article in the EFS KnowledgeBase
    Alex


    Originally posted by xoprofittaker
    I am trying to compair two values in a pre test befor executing a control statement within an if statement.

    The syntax I am using is as follows...

    total = if ((tangent1 > 0) && (momDelta < 0)) {
    tangent1 - Math.abs (momDelta);
    }else {
    tangent1 + momDelta;
    }

    I keep getting a syntax error on the pre test line. I am trying to do something like this.

    If Tangent 1 is greater than 0 and Mom Delta is less than 0, then do this.

    Also, is my math (abs.) function done properly as well???

    Also later on in the code I am trying to test to see if a value for (x) is greater than or equal to (y). The syntax I am using for that is


    If (x > || == y) {
    tangent1 + mom;
    }
    else {
    mom - tangent1;
    }

    Any help is appreciated,

    John

    Comment


    • #3
      Thanks

      Thanks Alexis. That helped out a lot.

      John

      Comment


      • #4
        John
        My pleasure and I am glad to hear that it helped
        Alex


        Originally posted by xoprofittaker
        Thanks Alexis. That helped out a lot.

        John

        Comment


        • #5
          Same issue in another file

          Another file with the same problem. I think I've made the appropriate changes as per your last response, however I keep getting a syntax error on line 33.

          AS for the function main I am going though the File share section. I get confused when trying to plot more thatn one line or histogram in the same pane.

          Ny help is greatly appreciated.

          John
          Attached Files

          Comment


          • #6
            Hi,

            Note that both plots can't occupy the same pane as they are calculated because one is in the under 200k scale range and the other is in the millions scale range.

            Attached are some corrections to the syntax that allowed the plots to show.

            The "calculator-Both.efs" code will only show one plot since the other is way out of range as explained above. The other two efs files are the studies as you programed them as separate studies which you can load up on the same chart.

            I'm learning just like you. I found the videos, javascrip guide, and other links very helpful for syntax and functions.

            Hope it helps.
            Attached Files

            Comment


            • #7
              For clarification, the following statement is incorrect:

              "Note that both plots can't occupy the same pane"

              They occupy the same pane but you can't see them because of the large difference in scale.

              Comment


              • #8
                Clarification

                Thanks for your response to my post. However you are incorrect. If you look at the math in the original file that I posted and compare it to the math in the file you included, you will notice that you removed some brackets(). The way I coded the math it returns the total volume or issues trading either up or down as a percentage. Since it's impossible for the sum of all the volume being traded to exceed 100 percent (likewise with issues) it is possible to plot them both in the same pane.

                Thanks for your reply though, I guess I may not have made it clear as to what it was that I was trying to accomplish.

                Thanks,

                John

                Comment


                • #9
                  You are right, I should have figured out you were calculating percentages.

                  Here is a working efs that plots the histogram for the AdvDecIssues and a line for the AdvDecVolume.

                  I still had to modify some brackets() from your original but I believe it is what you are looking for.
                  Attached Files
                  Last edited by waynecd; 04-28-2008, 10:58 PM.

                  Comment


                  • #10
                    Not returning negative values

                    This code seems to be working fine with the exception that for some reason it does not return negative values.

                    I want the 0 line in the histogram to represent a 50/ 50 balance with 50 % of the issues (or volume) advancing and 50% declining. 50 - 50=0. A reading of +20 would mean that 70% were advancing. 70 - 50 = 20. If declining issues or volume were being returned, the same calculation would have to be performed 70 - 50 = 20, however the 20 would then have to be turned into a negative. That's what line 32 & 33 is about, multiplying the 20 * 2 so that 40 can be subtracted from 20 leaving a -20. This subtractinon is then performed as the first condition in the if statement at line 51. Thus a -20 would mean that 70% were declining.

                    The final if statement paints the histogram bar green with a possitive number and red for a declining (negative) value.

                    The math in the file works, but for some reason the negative values are not being plotted.

                    Any help is appreciated.

                    Thanks,

                    John
                    Attached Files

                    Comment


                    • #11
                      Re: Not returning negative values

                      John
                      The reason negative values are not being returned is because you inserted a closing curly bracket } in line 82 of your formula whereas it should have been in line 76 to close the conditional statement. As it was written the return statement was being executed only when advDecVolume was greater than 0
                      Also you do not need to set the histogram base to -50 so you can comment out or delete that statement in preMain
                      Alex

                      PS. I have merged the thread with this one since it is related to the same subject


                      Originally posted by xoprofittaker
                      This code seems to be working fine with the exception that for some reason it does not return negative values.

                      I want the 0 line in the histogram to represent a 50/ 50 balance with 50 % of the issues (or volume) advancing and 50% declining. 50 - 50=0. A reading of +20 would mean that 70% were advancing. 70 - 50 = 20. If declining issues or volume were being returned, the same calculation would have to be performed 70 - 50 = 20, however the 20 would then have to be turned into a negative. That's what line 32 & 33 is about, multiplying the 20 * 2 so that 40 can be subtracted from 20 leaving a -20. This subtractinon is then performed as the first condition in the if statement at line 51. Thus a -20 would mean that 70% were declining.

                      The final if statement paints the histogram bar green with a possitive number and red for a declining (negative) value.

                      The math in the file works, but for some reason the negative values are not being plotted.

                      Any help is appreciated.

                      Thanks,

                      John

                      Comment


                      • #12
                        Thanks Alexis

                        I looked and looked and couldn't figure that out. Thanks. It works beautifully now.

                        Did you get the PM I sent you last weak???

                        Thanks,

                        John

                        Comment


                        • #13
                          John
                          You are most welcome and I am glad to hear the study is working fine.
                          Alex

                          P.S. I did receive the PM and will respond to it once I have some time


                          Originally posted by xoprofittaker
                          I looked and looked and couldn't figure that out. Thanks. It works beautifully now.

                          Did you get the PM I sent you last weak???

                          Thanks,

                          John

                          Comment


                          • #14
                            Stopping re - scaling

                            As you mentioned in your last post, I could remove or comment out the setHistogramBase -50. However I noticed that with that line left in the code, the indicator on the negative side of the histogram, is more acuratly displayed, with 25% being depicted as half of the distance to the bottom of the payne. What I am trying to avoid is a situation where the indicator is returning a value of say 15%, and because that is the largest value being returned in the visible indicator pane, it is rescaled and plotted out so it takes up the entire pane, as if it were returning a value of 50%.

                            On the negative side of the histogram it looks fine with the set histogramBase at -50, hovever on the top side, a value of 10 will go all the way to the top of the pane.

                            I've tried adding another setHistogramBase with a value of 50 just above the existing setHistogramBase -50, but that didn't do anything.

                            I thought about trying to plot out another histogram plot in the background that would return a constant value of 50 and color it white, but that seems like an antiquated way to go.

                            I've tried adding other bands, like at 20 and 30, but that didn't do anything, as the bands just disapeared if the histogram didn't return a value large enough to plot up to 20 or 30.

                            Is there any way that I could make the range of the indicator pane display 50 above the zero line and beneath it, regardless of the the size of the histogram being plotted???

                            Thanks,

                            John

                            Comment


                            • #15
                              John
                              To accomplish what you want you need to use the setStudyMax() and setStudyMin() functions.
                              See the EFS KnowledgeBase for the description and syntax of these functions
                              Alex


                              Originally posted by xoprofittaker
                              As you mentioned in your last post, I could remove or comment out the setHistogramBase -50. However I noticed that with that line left in the code, the indicator on the negative side of the histogram, is more acuratly displayed, with 25% being depicted as half of the distance to the bottom of the payne. What I am trying to avoid is a situation where the indicator is returning a value of say 15%, and because that is the largest value being returned in the visible indicator pane, it is rescaled and plotted out so it takes up the entire pane, as if it were returning a value of 50%.

                              On the negative side of the histogram it looks fine with the set histogramBase at -50, hovever on the top side, a value of 10 will go all the way to the top of the pane.

                              I've tried adding another setHistogramBase with a value of 50 just above the existing setHistogramBase -50, but that didn't do anything.

                              I thought about trying to plot out another histogram plot in the background that would return a constant value of 50 and color it white, but that seems like an antiquated way to go.

                              I've tried adding other bands, like at 20 and 30, but that didn't do anything, as the bands just disapeared if the histogram didn't return a value large enough to plot up to 20 or 30.

                              Is there any way that I could make the range of the indicator pane display 50 above the zero line and beneath it, regardless of the the size of the histogram being plotted???

                              Thanks,

                              John

                              Comment

                              Working...
                              X