Announcement

Collapse
No announcement yet.

If - If Else

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

  • If - If Else

    I can't seem to get this simple IF condition to work:

    // Hours when the system can trade Long or Short positions : 9am to 11:30am and 2pm to 4:12pm
    // or from 9am to 4:12 according to the Lunch_Break switch:
    if ( Lunch_Break == true )
    ( ( (vTime.getHours() >= (9+TimeZone_vs_NYC)) && (vTime.getHours() < (12+TimeZone_vs_NYC))
    && ! ( (vTime.getHours()==(11+TimeZone_vs_NYC)) && (vTime.getMinutes() >= 30) ) )
    || ( (vTime.getHours() >= (14+TimeZone_vs_NYC)) && (vTime.getHours() == (16+TimeZone_vs_NYC) && vTime.getMinutes() == 12) ) );
    else if ( Lunch_Break == false)
    ( (vTime.getHours() >= (9+TimeZone_vs_NYC)) && (vTime.getHours() < (16+TimeZone_vs_NYC) && vTime.getMinutes() == 12) );
    {

    Separately, both instructions are executing correctly but only the else if condition is executed even if the switch is set to true.

    Thank you again for your kind help.

    Cheers.

    Andrei

  • #2
    Re: Reply to post 'If - If Else'

    I usually create the current time

    time=vTime.getHours()*100+vTime.getMinutes()

    then compare time to the times I want


    if(time>=930 && time <1200)
    etc.

    Comment


    • #3
      Yes indeed but in this case it is to allow for different Time Zones as I am in the PT (or -3).

      Cheers.

      Andrei

      Comment


      • #4
        Re: Reply to post 'If - If Else'

        then

        time= (hr+timezone)*100+minutes


        ----- Original Message -----
        From: <[email protected]>
        To: <[email protected]>
        Sent: Sunday, January 04, 2004 11:47 AM
        Subject: Reply to post 'If - If Else'


        > Hello dloomis,
        >
        > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        >

        Comment


        • #5
          Is there a reason you appear to be using the getValue("time") method for this rather than the getHour(), getMinute(), etc?

          The first way creates a JS date object which is very heavy weight, the other calls use the newer "rawtime" functionality - which has much less impact on your system.

          Garth
          Garth

          Comment


          • #6
            Garth,

            I thought the way Dave is accessing time is correct for minimizing CPU load.
            There are two types of Date/Time operations you can perform in EFS:

            ยท Date/Time operations on the System Date (e.g., determining and manipulating the cpu Date/Time):

            Date Operations
            Following that link, Date Operations you see the description of what is use to obtain actual system time. The second recommendation is Date/Time operations on the actual price data (e.g., determining and manipulating the Date/Time of a particular bar):. This method gets bartime.

            Based on my understanding, as per the previous link, the specific method advised against is using getValue
            Notes from eSignal:

            In the early days of EFS, we discovered that using getValue("time", ...) put an extra load on the CPU. We do not recommend using getValue("time", ...).
            Please let me know if I am off base on this, as I use the same method in my efs's except in playback mode where bartime is the only effective measure of time.

            Regards,

            Steve
            Last edited by Guest; 01-06-2004, 02:53 AM.

            Comment


            • #7
              Steve,

              You are correct, but missing a few points...

              1) It is the original poster who seems to be using getValue("time")

              2) You can tell this is an ALMOST (which is why I said appeared to be using...) a sure bet from two things:

              a) The use of vtime as a pointer to the date object. People who use the vtime variable are almost all working from older, pre-rawtime EFS's.

              b) The fact that they are using vtime.gethours etc instead of the gethour() routine. Again this points to bad habits from old EFS studies.

              3) There are some legit reasons to use getValue("time") vs. rawtime. But they are few and far between. So I was curious if there was a valid reason, or if they were using getValue("rawtime") or if there was just lack of understanding on which to use.

              4) I have seen many recent EFS studies pumped out that still use getValue("time") with no valid reason to do so vs. using rawtime. These will quickly kill a users system...and many users may load these formula's without really understanding that it can and will cause issues.

              Garth
              Garth

              Comment


              • #8
                Sorry for not being too quick on the uptake Garth, I misunderstood the post. I am glad you clarified, I just missed it. Thanks!

                Regards,

                Comment


                • #9
                  Tested JavaScript date object, excessive use can negatively impact efs performance

                  I had used a method to obtain clock time in a lot of my code using this method:
                  var vTime = new Date();
                  var vHour = vTime.getHours();
                  var vMin = vTime.getMinutes();
                  var vSec = vTime.getSeconds();
                  (this method tested slow)
                  Garth explained to me that this uses the JS date object which is extremely slow. This is discussed in the efs help file as follows:


                  Notes from eSignal:

                  In the early days of EFS, we discovered that using getValue("time", ...) put an extra load on the CPU. We do not recommend using getValue("time", ...).

                  Instead, use one of the getYear(...), getMonth(...), getDay(...), getHour(...), getMinute(...), getSecond(...) functions. or getValue("rawtime", ...)

                  rawtime is the number of seconds elapsed since 1/1/1970.

                  see the

                  efs helpfile link

                  I also had another routine, which used the methods described directly above where I used

                  var vHour = getHour(n);
                  var vMin = getMinute(n);
                  var vSec = getSecond(n);
                  (this method tested fast)
                  Since my efs's are very fast, I believed, especially since the eSignal efs help file was not clear, that my original method was extremely fast. Boy, was I wrong. Here are the results of some testing I performed
                  10,000 loops calling the JavaScript date object takes 4532 miliseconds

                  10,000 loops calling the recommended method takes 656 miliseconds

                  I repeated the testing and the JavaScript date object took even longer
                  The bottom line is that an efs should minimize the use of the slow method (especially on the history bars which are processed during initial load) which uses the JavaScript date object.

                  Thanks again Garth, this has helped me out quite a bit.

                  Comment

                  Working...
                  X