Announcement

Collapse
No announcement yet.

High/Low on Friday

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

  • High/Low on Friday

    I am working on a study in which I would like to compare todays high or low to Thursday and Fridays high/low. Once the next thursday and friday pass the value becomes that high/low . Any idea how to just capture the previous thursday/friday high low numbers?

  • #2
    Hello Jeff,

    What you need to do is create some global variables to store these values. Then on each bar you would get the date of the bar and then assign a local variable to the day of the week.

    var myDate = getValue("time");

    The obove creates a Date Object, which you would then use to look at the day of the week using it's .getDay() method.

    var dayOfWeek = myDate.getDay();

    The dayOfWeek variable will contain a number from 0 to 6. Sunday is 0, therefore Thursday is 4 and Friday is 5. Then add a condition that checks for the value of 4 and assign the daily high and low to the global variables.

    PHP Code:
    if (dayOfWeek == 4) {  // Thu
            
    nThuHigh high(0inv("D"));
            
    nThuLow low(0inv("D"));

    You would create the equivalent condition for Fri and repeat the process. At that point you would have four variables that store the most recent daily high and low for the two days.
    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
      Jason, thank you for your reply. With your help I have made progress. I am stumped on one detail: I want the High/Low of Thursday or Friday whichever day has the highest or lowest value. if thurs h=1200 fri h=1000 thurs low = 900 Friday low =800. I want the values of 1200 and 800. In addition what approach should I take to look back specifically to those 2 days. I understand the process of, if today is Thursday = true the value = x, but if today is Tuesday how do I look back to those two days to get the highest high and lowest low for the previous Thursday and Friday?

      Comment


      • #4
        Hello Jeff,

        To collect the max or min values between those two days you would only need two global variables. You would then use the Math Object's Math.max() and Math.min() functions to collect the highest and lowest values. You won't need to "look back" to get the values from the previous as long as the values are assigned to global variables (i.e. declared outside of main() ). They will remain available on subsequent days until the new Thursday and Friday arrive, at which point you will need to reset the variables at the beginning of the day on Thursday.

        PHP Code:
        if (dayOfWeek == || dayOfWeek == 5) {  // Thu or Fri
                
        if (dayOfWeek == && day(-1) != day(0) ) {
                        
        // beginnig of day on thu, reset variables
                        
        nTFHigh high(0inv("D"));
                        
        nTFLow low(0inv("D"));
                }
                
        nTFHigh Math.max(nTFHighhigh(0inv("D")) );
                
        nTFLow Math.min(nTFLowlow(0inv("D")) );

        The day(-1) != day(0) detects the first bar of the day for the current day being processed. When that is true and the dayOfWeek is equal to 4, the first bar of Thursday has been found.
        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
          Resetting the variable

          If we need to keep the values till after the present Friday has passed, that is keep the previous Thu Fri - Highest High and Lowest Low till after the present Thu Fri -Highest High and Lowest Low have been determined, how can the efs be modified.


          Can that be done by changing the line where begining of Thu resets the variable

          PHP Code:
          if (dayOfWeek == && day(-1) != day(0) ) { 
          by the following where begining of Mon Resets the variable or there is a different tact to it

          PHP Code:
          if (dayOfWeek == && day(-1) != day(0) ) { 
          Thanks for any help

          AK

          Comment


          • #6
            Hello akiri,

            One method would be to create two sets of global variables where one stores the previous week's high and low and the other stores the current weeks. When the Thursday of the current week is found, pass the values of the current week variables to the previous week variables. Then assign the new current weeks values to the current week variables.

            Add the global variables, nTFHigh_1 and nTFLow_1.
            Then, inside the condition that detects the beginning of the current Thursday, pass the current week variables to the previous week variables.


            PHP Code:
            var nTFHigh null;
            var 
            nTFLow null;

            // previous week global variables
            var nTFHigh_1 null
            var 
            nTFLow_1 null;

            function 
            main() {

            ...

            if (
            dayOfWeek == || dayOfWeek == 5) {  // Thu or Fri
                    
            if (dayOfWeek == && day(-1) != day(0)) {
                            
            // add the following
                            
            if (getBarState() == BARSTATE_NEWBAR) { // for real time processing
                                
            nTFHigh_1 nTFHigh;
                                
            nTFLow_1 nTFLow;
                            }

                            
            // beginnig of day on thu, reset variables
                            
            nTFHigh high(0inv("D"));
                            
            nTFLow low(0inv("D"));
                    }
                    
            nTFHigh Math.max(nTFHighhigh(0inv("D")) );
                    
            nTFLow Math.min(nTFLowlow(0inv("D")) );
            }

            ...

            return new Array(
            nTFHigh_1nTFLow_1);

            If you want to plot the previous week's TFHigh/Low, you would then return the nTFHigh_1 and nTFLow_1 variables from main()'s return statement.
            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


            • #7
              Code Check Please

              JasonK thanks for the code I tried to implement a version and there is no error but no output either. Here is the code for it. Could anybody point me in the right direction

              I am trying to draw the highest high and lowest low of 2 days Thu and Fri last week and retain that line till end of next Friday (that is till a new highest high and lowest low of current Thu Fri set in)

              PHP Code:
              var t1 addLibrary("shUtilities.efsLib");   
              function 
              preMain() {

                  
              setPriceStudy(true);
                  
              setStudyTitle("Test");

              }

              var 
              myDate null;
              var 
              dayOfWeek null;
              var 
              nTFHigh null;
              var 
              nTFLow null;
              var 
              nTFHigh_1 null;
              var 
              nTFLow_1 null;

              function 
              main() {

              var 
              myDate getValue("Time");
              var 
              dayOfWeek myDate.getDay();

              if (
              dayOfWeek == || dayOfWeek == 5) {  // Sun=0 Mon=1 Tue=2 Wed=3 Thu=4 Fri=5
                      
              if (dayOfWeek == && day(-1) != day(0) ) {
                           if (
              getBarState() == BARSTATE_NEWBAR) {
                              
              nTFHigh_1 nTFHigh;
                              
              nTFLow_1 nTFLow;
                          }
                          
              nTFHigh high(0inv("D"));
                          
              nTFLow low(0inv("D"));
                      }
                      
              nTFHigh Math.max(nTFHighhigh(0inv("D")) );
                      
              nTFLow Math.min(nTFLowlow(0inv("D")) );

              }

              //return new Array(nTFHigh_1, nTFLow_1);


                  
              var nBarIndex null
                  var 
              nTime
                  var 
              nPrice
                 

                 
              //get the rawtime value for the current bar 
                 
              nTime getValue"rawtime"); 

                 if ( 
              nTime != null ) { 

                  
              //get the bar index to the first bar of the date in nTime 
                  
              nBarIndex Math.abs(getFirstBarIndexOfDaynTime ));

                
                  
              drawLineRelative(-nBarIndex,nTFHigh_1(0),3,nTFHigh_1(0),PS_DASH,3,Color.black,"nTFhigh_1");
                  
              drawTextAbsolute(3nTFHigh_1"nTFhigh_1=" +nTFHigh_1.round2(), Color.blacknullText.FRAME Text.VCENTER Text.BOLD"Arial"14"nTFhigh_1");

                  
              drawLineRelative(-nBarIndex,nTFLow_1,3,nTFLow_1,PS_DASH,3,Color.black,"nTFLow_1");
                  
              drawTextAbsolute(3nTFLow_1"nTFLow_1=" +nTFLow_1.round2(), Color.blacknullText.FRAME Text.VCENTER Text.BOLD"Arial"14"nTFLow_1");
               
              return;
              }

              Comment


              • #8
                Hello akiri,

                The first thing you need to add is an initial validation condition for the global variables, nTFHigh and nTFLow. It's not necessary to do this for nTFHigh, but is a good programming practice. Add the highlighted conditional block before your conditional block that assigns the values for these variables on Thursdays and Fridays.



                This is particularly important for nTFLow because it is declared outside of main() as null. Therefore the Math.min() function will always assign null to the variable. When plotted on the chart, it will be null or 0.

                The reason your current formula doesn't plot anything is caused by two issues. First your return statement in main() is not returning any values to be plotted. However, prior to the return statement at the end of main() you are executing some drawing functions that do not have valid parameters. You're making a function call out of a global variable, nTFHigh_1(0). With the (0) added to the end of the variable, EFS is trying execute a function with that name while passing 0 as a parameter. This is valid syntax but because the function does not exist in your formula EFS exits the formula. Change these parameters to remove the (0).



                At this point your code should generate an error that nTFHigh_1 has no properties. This occurs at initialization or the beginning of processing because on the first bar that gets processed, nTFHigh_1 is still null. To correct this error you can add a conditional check for a non-null value of this variable in the associated if() statement that also validates nTime.



                The next issue that you will encounter is the use of a method, .round2(). This function again, does not exist in the core functions of EFS and causes an exit. This may be a function defined within the shUtilities library that you've added at the top of your formula, but you are not using it correctly. You may want to review Steve's documentation on his library functions. One alternative you could use is the .toFixed(2) function in it's place.



                At this point, you can return some values from the return statement to plot values. Try the following.

                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


                • #9
                  Thanks

                  JasonK

                  Thanks for the help and the explanations.

                  Its working now, instead of toFixed I am using priceFormatNumber and that way on bond and notes chart it shows correct formatting.

                  In version 10 the text flashes intermittently on the chart for some time, and then the flashing stops. The lines do not flash

                  I don't have any flashing codes in there. Any thoughts?

                  Anybody else experiencing that problem with their efs scripts.

                  Comment


                  • #10
                    Hello akiri,

                    You're most welcome. Good thinking on the formatPriceNumber().

                    Regarding the flashing graphics in 10.0, we are aware of that problem. It should be fixed in the next version. There may be a work-around we can explore for the time being. Please post your completed formula code that has the flashing. Alternatively you may revert back to 8.0 until the next release is available.
                    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


                    • #11
                      Thank You

                      Jason thanks, I can live with the intermittent flashing for now, will wait for the new version of esignal.

                      akiri

                      Comment


                      • #12
                        akiri
                        Try replacing the drawXxxAbsolute() calls which are causing the issue with drawXxxRelative() and see if that resolves the issue in the interim
                        Alex

                        Comment


                        • #13
                          Thanks

                          Alexis thanks for the suggestion, but that did not resolve the issue. I will wait for the esignal upgrade.

                          Comment


                          • #14
                            akiri
                            You are most welcome.
                            I would be curious to see the script you are using so as to run some tests on it because as far as I can see at my end drawTextRelative() should work. Just to confirm this see the enclosed animation showing two running copies of the script posted in this thread, one using drawTextAbsolute() - which as expected was flashing - and the other using drawTextRelative() which appeared to work fine.
                            Alex

                            PS. Note that the value os nTFHigh is different from what you may see at your end because I displaced it by 0.0052 to move it closer to where the market was trading

                            Comment


                            • #15
                              Shifted to TextRelative

                              Alex, I replaced all to TextRelative, and now they are working fine
                              I think there were some TextAbsolute, that I had not replaced when I tested intially

                              Thanks again

                              AK

                              Comment

                              Working...
                              X