Announcement

Collapse
No announcement yet.

Day()

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

  • Day()

    I want to return the day of the week for each bar in a day interval chart. Using Day() I only get today's day which is 2 for Tuesday. How can I find every friday in the chart?
    Thanks.

  • #2
    ratherBgolfing,

    Check the Time folder in my Fileshare (the link is below). There are efs's there that show how to accomplish this. (look at the
    Time Functions 08 14 2006.efs for one).

    Comment


    • #3
      Thanks Steve. Great examples.

      Comment


      • #4
        ratherBgolfing,

        You are most welcome, I am glad this helped out. A note of caution, don't use the "new Date()" object declaration too much, it can be a resource hog if used excessively.

        Comment


        • #5
          Steve,

          Thanks for the tip. I am only using it in a side routine for backtesting; i.e. not in my main system.

          Here is another one for you related to the same problem I am having with Object Series.

          I want to determine the slope of a moving average by simply checking the MA value on the current bar with the MA value 3 bars ago.

          I was comparing e100.getValue(0) with e100.getValue(-3) which of course gagged the routine. I then wasted a lot of time working with arrays like I did to capture getDay per your code...no success. How can I access past values of the MA?

          Thanks in advance.

          By the way...very cool logo.

          Comment


          • #6
            Hi ratherBgolfing,

            I put together an efs that creates a Moving Average series, then contains a function that will calculate and return the slope of a series object. This way you can copy and past the function in your code if you like. I suspect that the problem you were having could be due to null values that were returned when the efs is just starting to execute (insufficient data to perform the calculation you are requesting). In the example, these values are output to the formula output window. I put this efs in my fileshare as well. I hope this helps.

            PHP Code:
            // Moving Average example with added slope function -  S. Hare 8 17 2006
            function preMain() {
             
            setPriceStudy(false);
             
            setStudyTitle("eMA Slope");
             
            setCursorLabelName("eMA",0);
             
            setDefaultBarFgColor(Color.blue,0);
             
            setDefaultBarThickness(2,0);
            }

            var 
            mySlope nulleMA5 nullbInit false// these are global variables, they can be seen in every part of the efs

            function main() {

             if(
            bInit == false){
              
            eMA5 ema(5); //defining a series
              
            bInit true;
             }
             
            mySlope CheckSlope(eMA5); // sending the CheckSlope function a series
             
             
            return mySlope;
            }
             
            function 
            CheckSlope(tmpX){// CheckSlope function S. Hare 8 17 2006
             
            var tmp tmpX.getValue(-3);
             if (
            tmp == null || tmp == 0){ 
              
            debugPrintln ("26: eMA5.getValue(0) = "tmpX.getValue(0)+ ", eMA5.getValue(-3) = "tmpX.getValue(-3));
              return 
            null;
             }
             var 
            time rawtime(-3)-rawtime(0);
             if (
            time ==null || time == 0){ // if the check for zero is not made, there is a potential for over-run when dividing by this number
              
            return null;
             }
             var 
            slope = (tmp tmpX.getValue(0))/time// time base seconds, therefore the slope is price change per second
             
            return slope;

            Attached Files

            Comment


            • #7
              Steve,

              Thanks a lot for all the extra effort. Clearly I will never have your knowledge of efs.

              I loaded the efs into a chart and (-3) still returned null for each instance. When you run your efs do you get values for (-3)?

              Bgolf

              Comment


              • #8
                Hi ratherBgolfing,

                Thanks for the compliment. The efs I posted returns null for the first eight or so values only, as expected (and outputs to formula output window). Subsequently, the values for (-3) start returning. I ran the efs today and everything worked here as expected.

                If you loaded the efs I posted and you are not getting values back, there may be some other issues that we can explore. If you haven't loaded the efs (it wasn't clear to me), please try that and see if that works.

                • What revision are you running? I am running version 8, build 779 on the machine I ran this on.
                • Ensure the moving average declaration in your efs uses a global variable.
                • Try reloading eSignal.

                Comment


                • #9
                  What is the reason you use -3?
                  Last edited by buzzhorton; 08-17-2006, 06:14 PM.

                  Comment


                  • #10
                    Originally posted by stevehare2003
                    Hi ratherBgolfing,

                    If you loaded the efs I posted and you are not getting values back, there may be some other issues that we can explore. If you haven't loaded the efs (it wasn't clear to me), please try that and see if that works.

                    • What revision are you running? I am running version 8, build 779 on the machine I ran this on.
                    • Ensure the moving average declaration in your efs uses a global variable.
                    • Try reloading eSignal.
                    Steve,

                    Yes I loaded your efs into a 5 min Russell emini chart. I only got 8 lines in the output window all of which had (-3) returning 0. So I tried MSFT with same result. I then changed eMA5=ema(5) to eMA5= new MAStudy(50,0,"Close",MAStudy.EXPONENTIAL); and got several hundred lines of output all of which returned 0 for (-3).

                    - I upgraded to version 8.0 build 782 within the last week.
                    - I used your efs unchanged and then as changed above
                    - no need to reload when just installed I would assume?

                    Sorry for the hassle. I assume my problem is my not understanding Series Objects very well/at all.
                    In my efs I use:
                    var myVar = 0; // global
                    then in main:
                    e50= new MAStudy(50,0,"Close",MAStudy.EXPONENTIAL);
                    myVar = e50.getValue(0);
                    drawText(myVar, BelowBar2); // this print value no problem
                    then when I try:
                    myVar = e50.getValue(-3);
                    drawText(myVar, BelowBar2); // this gets error "Parameter 1 drawText function is invalid"
                    then I try (per the getDay code):
                    drawText(myVar[3], BelowBar2); // this gets error : "myVar has no properties"

                    Obviously I have no idea what I am doing at this point.
                    What I want to know is:
                    e50.getValue(0) > e50.getValue(-3)...i.e. is the MA trending up or down?

                    Thanks for sharing the pain.

                    Comment


                    • #11
                      ratherBgolfing,

                      I loaded the latest eSignal version and there were no changes. There were several issues with your code, I will go through that with you tomorrow if that is alright, but for now could you please try running this efs and let me know if this works. I took everything out regarding the slope calculation to help narrow things down.

                      PHP Code:
                      function preMain() {
                       
                      setPriceStudy(true);
                       
                      setStudyTitle("eMA Example");
                       
                      setCursorLabelName("eMA5.getValue(0)",0);
                       
                      setDefaultBarFgColor(Color.blue,0);
                       
                      setDefaultBarThickness(1,0);
                       
                      setCursorLabelName("eMA5.getValue(-3)",1);
                       
                      setDefaultBarFgColor(Color.red,1);
                       
                      setDefaultBarThickness(1,1);
                      }
                      var 
                      eMA5 nullbInit false// these are global variables, they can be seen in every part of the efs
                      function main() {
                       if(
                      bInit == false){
                        
                      debugClear();
                        
                      eMA5 ema(5); //defining a series
                        
                      bInit true;
                       }
                       
                      debugPrintln ("18: eMA5.getValue(0) = "eMA5.getValue(0)+ ", eMA5.getValue(-3) = "eMA5.getValue(-3));
                       return new Array(
                      eMA5.getValue(0),eMA5.getValue(-3));

                      Comment


                      • #12
                        Perfect. Thanks Steve. I knew it should be simple.

                        Just loaded it into chart...first 8 prints were null and then hundreds of accurate prints.

                        I will work into my code and let you know.

                        Thanks again for all the extra effort.

                        Comment


                        • #13
                          OK. I plugged your code into my efs and it works perfectly. The only remaining question is why. The difference between your code and my original code is:

                          you have the global eMA5 set to null; I did not

                          you set: eMA5 = ema(5);
                          I set: var e5 = new MAStudy(5,0,"Close",MAStudy.EXPONENTIAL);

                          otherwise the code it the same; i.e print statements and if's

                          could you please tell me how the code is treated differently and therefore yours works and mine does not?

                          Thanks again Steve for all the great help.

                          Comment


                          • #14
                            Sounds like you didn't create a series and Steve's code did.

                            Comment


                            • #15
                              exactly...any idea why eMA5 = ema(5); creates a series and var e5 = new MAStudy(5,0,"Close",MAStudy.EXPONENTIAL); does not???

                              Comment

                              Working...
                              X