Announcement

Collapse
No announcement yet.

Pre-market Pivot Points

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pre-market Pivot Points

    Looking at Wednesday pre-market intraday charts, pivot point levels shown are extensions of Tuesday's levels (which are based on Monday's OHLC). This corrects once the market opens, at which time Tuesday's OHLC are then used to calculate the pivots for Wednesday.

    Is there a tweak to the PivotPointAll.efs (in the EFS Pivots folder) that so that the pivot point levels display correctly pre-market?

    Thanks
    shaeffer

  • #2
    shaeffer
    It is possible to modify the pivot scripts in such a way that if the system time is less than 9:30 (or equivalent if in a different time zone) then the script uses the current daily bar to calculate the pivots else it uses the prior bar.
    To accomplish this you would do the following (note that for the purpose of this example I will be using the PivotPoint.efs).
    Replace the following section in lines 37-39
    PHP Code:
    var vHigh  xHigh.getValue(-1);
    var 
    vLow   xLow.getValue(-1);
    var 
    vClose xClose.getValue(-1); 
    with the following (comments included with the code)
    PHP Code:
    var myDate = new Date();//create the Date Object
         //then check if system time is less than 9:30 and the bar date corresponds to system date
        //the latter condition is to prevent applying this logic to prior days
        
    if((myDate.getHours()*100)+myDate.getMinutes()<930 && myDate.getDate()==day(0)){//if this evaluates to true
                
    var vHigh  xHigh.getValue(0);//use the current bar's High
                
    var vLow   xLow.getValue(0);//as above for Low
                
    var vClose xClose.getValue(0); //as above for Close
        
    }else{//otherwise
                
    var vHigh  xHigh.getValue(-1);//use yesterday's value for High
                
    var vLow   xLow.getValue(-1);//as above for Low
                
    var vClose xClose.getValue(-1); //as above for Close
        

    In the two screenshots below you can see how the Pivot Point is plotting before and at 9:30 (ET)
    Alex



    Comment


    • #3
      Thanks Alex, it worked great.

      With this change, are var myDate and the subsequent if/else lines read on each tick?

      In the morning, before the 9:30 market open, I typically switch a couple of times between a pre-market and regular market time template. Then just before the open, I switch to the regular hours time template and leave it there all day.

      I'm not concerned about optimized efs efficiency during pre-market, but after 9:30 is there a way to bypass the premarket check lines if they are in fact read on each tick?

      Do EFS's reload when a time template is switched?

      Thanks again
      shaeffer

      Comment


      • #4
        shaeffer

        ...are var myDate and the subsequent if/else lines read on each tick?
        Yes they are.

        but after 9:30 is there a way to bypass the premarket check lines if they are in fact read on each tick?
        It is possible. First declare a global variable (ie outside of preMain and main) called myFlag and set it initially to true. Then replace the code I provided earlier with the following. Comments are included in the code sample.

        PHP Code:
        var StartTime 930;//replace 930 with time of choice
            //the following condition is evaluated once per bar only and checks if the bar time is less
            //than the defined starting time.
            //It is required to ensure that myFlag gets set to true if pre-market bars are formed after the efs 
            //is started
            //impact should be marginal as it executes only once per bar
            
        if(getBarState()==BARSTATE_NEWBAR && (hour(0)*100)+minute(0)<StartTime){
                
        myFlag true;
            }
            
        //the following condition is evaluated 
            //-> once on every bar while the efs is loading and executes the commands if the system time is less than
            //   the defined starting time AND the bar date is the same as the system date ELSE sets myFlag to false
            //-> on every tick if the system time is less than the defined starting time AND the bar date 
            //   is the same as the system date (ie during pre-market) ELSE sets myFlag to false
            
        if (myFlag == true ) {
                var 
        myDate = new Date();
                if((
        myDate.getHours()*100)+myDate.getMinutes()<StartTime && myDate.getDate()==day(0)){
                        var 
        vHigh  xHigh.getValue(0);
                        var 
        vLow   xLow.getValue(0);
                        var 
        vClose xClose.getValue(0); 
                }else{
                    
        myFlag false;
                }
            } 
            
        //the following condition evaluates on every tick after the defined start time (ie as in the original script)
            
        if (myFlag == false ) {
                var 
        vHigh  xHigh.getValue(-1);
                var 
        vLow   xLow.getValue(-1);
                var 
        vClose xClose.getValue(-1); 
            } 
        Do EFS's reload when a time template is switched?
        Yes they do
        Alex

        Comment


        • #5
          Thanks for the reply Alex.

          Before I implement your suggestion, is there a need to evaluate the lines below for every tick, given that the .getValue(-1)'s don't change thru the day?

          Regards
          shaeffer

          PHP Code:
          // the following condition evaluates on every tick after the defined start time (ie as in the original script)
              
          if (myFlag == false ) {
                  var 
          vHigh  xHigh.getValue(-1);
                  var 
          vLow   xLow.getValue(-1);
                  var 
          vClose xClose.getValue(-1);  } 
          P.S. Sorry if I need to be a little obsessed with efs efficiency. With six monitors, I've already had to cut down on the number of symbols, EFSs, charts, studies and other eSignal windows I have open, just to keep the program from stalling. Time & Sales still can't keep up. And as far as I know there are no immediate plans to make the program HT or duo-core processor capable.

          Comment


          • #6
            shaeffer

            ...is there a need to evaluate the lines below for every tick...
            Not necessarily and it can be changed to evaluating once per bar with relative ease.
            First you will need to declare three new global variables specifically vHigh, vLow and vClose and set them to null. Then replace the section of code posted in the prior message(s) with the enclosed one
            At this point you should have enough examples on how the logic is constructed to be able to modify it to any other requirement you may have
            Alex

            PHP Code:
            var StartTime 930;//replace 930 with time of choice
                //the following condition is evaluated once per bar only and checks if the bar time is less
                //than the defined starting time and sets myFlag to true ELSE it sets myFlag to false.
                //It is required to ensure that myFlag gets set to true when pre-market bars are formed and the efs 
                //was started prior to pre-market opening (ie there were no bars yet for the current day)
                
            if(getBarState()==BARSTATE_NEWBAR && (hour(0)*100)+minute(0)<StartTime){
                    
            myFlag true;
                }else {
                    
            myFlag false;
                }
                
            //the following condition is evaluated 
                //-> on every bar while the efs is loading and executes the commands if the system time is less than
                //   the defined starting time AND the bar date is the same as the system date ELSE sets myFlag to false
                //-> on every tick if the system time is less than the defined starting time AND the bar date 
                //   is the same as the system date (ie during pre-market) ELSE sets myFlag to false
                
            if (myFlag == true ) {
                    var 
            myDate = new Date();
                    if((
            myDate.getHours()*100)+myDate.getMinutes()<StartTime && myDate.getDate()==day(0)){
                            
            vHigh  xHigh.getValue(0);
                            
            vLow   xLow.getValue(0);
                            
            vClose xClose.getValue(0); 
                    }else{
                        
            myFlag false;
                    }
                } 
                
            //the following condition evaluates once every bar after the defined start time or while the script loads
                
            if (myFlag == false && getBarState()==BARSTATE_NEWBAR) {
                    
            vHigh  xHigh.getValue(-1);
                    
            vLow   xLow.getValue(-1);
                    
            vClose xClose.getValue(-1); 
                } 

            Comment


            • #7
              Hi Alex,

              Thanks once again for your help. I've followed your suggestions, and the result is below. I inserted three questions as comments within the code - I thought it might be easier than breaking it into pieces. Hopefully I'll be out of questions after this.

              Regards
              shaeffer

              PHP Code:
              var bInit  false;
              var 
              myFlag true;
              var 
              xHigh  null;
              var 
              xLow   null;
              var 
              xClose null
              var 
              vPP null;
              var 
              vR1 null;
              var 
              vS1 null;
              var 
              vR2 null;
              var 
              vS2 null;  

              function 
              main() {

                  if(
              isMonthly() || isWeekly())
                  return;
                  
                  if(
              bInit == false){            
                      
              xHigh  high (inv("D")); 
                      
              xLow   low  (inv("D"));  
                      
              xClose close(inv("D")); 
                      
              bInit true;             
                  }
                  
              var 
              StartTime 630;
                  if(
              getBarState()==BARSTATE_NEWBAR && (hour(0)*100)+minute(0)<StartTime){
                      
              myFlag true;
                  }else {
                      
              myFlag false
                  } 
              // above sets myFlag = true before 6:30, or false after 6:30
              // Question: At first glance, the above time check seems to be repeated below. I read your commments many times,
              // but couldn't understand the distinction between the two. In what case would the EFS not work (or what problems
              //  would occur) if the above if/else lines were not here?

                  
              if (myFlag == true ) {  // if its the morning, before 6:30
                      
              var myDate = new Date();
                      if((
              myDate.getHours()*100)+myDate.getMinutes()<StartTime && myDate.getDate()==day(0)){
                              var 
              vHigh  xHigh.getValue(0);
              // Question: I had to add 'var' in front of vHigh above, otherwise I got a vHigh is not defined error message
              // for the line below starting "if(vHigh == null ||...."  Why?
                              
              vLow   xLow.getValue(0);
                              
              vClose xClose.getValue(0); 
                              
              // in the morning, before 6:30, .getValue(0) gets yesterday's values
                      
              }else{
                          
              myFlag false;
                      } 
              // after 9:30 myFlag = false
                  

                  
              //the following condition evaluates once every bar after the defined start time or while the script loads
                  
              if (myFlag == false && getBarState()==BARSTATE_NEWBAR) {
                      
              vHigh  xHigh.getValue(-1);
                      
              vLow   xLow.getValue(-1);
                      
              vClose xClose.getValue(-1); 
                  }
              // The main Question:  Given that the .getValue(-1) values (above) don't change during the day, why do they need to be
              // retrieved every bar? Which then means that VPP, vR1 etc (below) get recalculated every bar also, even though
              // they don't change thru the day? This seems a big improvement over doing this every tick, but is it still
              // necessary? Or maybe doing this 78 times/day in a 5 minute chart is really no significant computer load.

                  
              if(vHigh == null || vLow == null || vClose == null)
                  return;
                  
                  
              vPP = (vHigh+vLow+vClose)/3;
                  
              vR1 2*vPP-vLow;
                  
              vS1 2*vPP-vHigh;
                  
              vR2 = (vPP-vS1)+vR1;
                  
              vS2 vPP-(vR1-vS1);  
                  
                  return new Array(
              vR2vR1vPPvS1vS2);

              Comment


              • #8
                shaeffer

                Question: At first glance, the above time check seems to be repeated below. I read your commments many times, but couldn't understand the distinction between the two. In what case would the EFS not work (or what problems would occur) if the above if/else lines were not here?
                Although they appear to be similar the time checks are performed on different objects.
                The first one checks the bar time and if that is before 6:30 it sets myFlag to true else it sets it to false.
                The second time check (which occurrs only if myFlag is equal to true) is based on system time (ie. your computer clock) and checks if the system time is before 6:30 AND the bar date is the same as the system date.
                If the condition is true [which can occurr only during today's pre-market) then the efs uses the most recent daily bar (which is actually still yesterday's bar because today's is not yet formed) to compute the pivots. If the condition is instead false it sets myFlag to false in which case the efs will use the prior daily bar to compute the pivots.
                This ensures that the script will reference the appropriate daily bar on historical bars (ie while it is loading) and on today's bars regardless of when you may be running the efs.
                The best way for you to understand how all these conditions impact the calculations of the pivot(s) is to try removing them one at a time and then seeing what happens.

                Question: I had to add 'var' in front of vHigh above, otherwise I got a vHigh is not defined error message for the line below starting "if(vHigh == null ||...." Why?
                That is because the variables vHigh, vLow and vClose need to be declared as global variables. Once you do that (and you remove the var = you added) you will not get any error messages

                The main Question: Given that the .getValue(-1) values (above) don't change during the day, why do they need to be retrieved every bar? Which then means that VPP, vR1 etc (below) get recalculated every bar also, even though they don't change thru the day? This seems a big improvement over doing this every tick, but is it still necessary? Or maybe doing this 78 times/day in a 5 minute chart is really no significant computer load.
                As far as I can tell the average time it takes to execute that condition is less than a 1/10th of a millisecond so I doubt it would have much impact on your computer's resources
                Alex

                Comment


                • #9
                  Thanks once again Alex,

                  I gave myself a good swift kick for neglecting to add vHigh, vLow and vClose as Global variables.

                  I understand now how the correct HLC values are retreived for the current day, both pre-market and not. But assuming a pre-market time template, could you clarify what's happening during loading of prior days bars? In particular:

                  1. Is every bar effectively a new bar as it loads, hence the first time check will set myFlag = true for all previous day, pre-9:30 bars? (I'll reference est here, though I'm on the west coast)

                  2. Then it seems that any previous day, pre-9:30 bars do not need the .getValue(0) values for correct -premarket plotting of pivots levels - is that correct? In other words, previous day, pre-9:30 bars recognize a new historic day has started so the .getValue(-1) values are the correct values for them?

                  Out of curiosity, since the pivots don't change intra-bar (or all day) would using SetComputeOnClose have worked, vs the BarState-NewBar approach? I have other charts where I plot pivot levels but which I never view pre-market, so I'm wondering the best way to modify their pivot efs's to eliminate the every-tick processing. And I don't really care about previous days pre-market pivot values, if that makes any difference.

                  Regards
                  shaeffer

                  Comment


                  • #10
                    shaeffer

                    1. Is every bar effectively a new bar as it loads, hence the first time check will set myFlag = true for all previous day, pre-9:30 bars?
                    On historical bars the efs executes once only on each bar. When it encounters bars with a time stamp prior to 9:30 it sets myFlag to true.

                    2. Then it seems that any previous day, pre-9:30 bars do not need the .getValue(0) values for correct -premarket plotting of pivots levels - is that correct? In other words, previous day, pre-9:30 bars recognize a new historic day has started so the .getValue(-1) values are the correct values for them?
                    That is correct and in fact on those bars the second time check sets myFlag to false (thereby skipping the section of code that retrieves the corresponding current daily bar) because the date of those bars does not match the system date.

                    Out of curiosity, since the pivots don't change intra-bar (or all day) would using SetComputeOnClose have worked, vs the BarState-NewBar approach? I have other charts where I plot pivot levels but which I never view pre-market, so I'm wondering the best way to modify their pivot efs's to eliminate the every-tick processing. And I don't really care about previous days pre-market pivot values, if that makes any difference.
                    As I said before you should have enough information and examples at this point to allow you to try other solutions and/or implement any changes that may best suit your requirements
                    Alex

                    Comment


                    • #11
                      Success! It works, I understand it and I think it is as efficient as it can be.

                      I got the impression that using SetComputeOnClose() would not improve things any.

                      Thanks for your patience Alex

                      Regards
                      shaeffer

                      Comment


                      • #12
                        shaeffer
                        You are most welcome
                        Alex

                        Comment

                        Working...
                        X