Announcement

Collapse
No announcement yet.

Quaterly Pivot

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

  • Quaterly Pivot

    Hi everybody,

    creating a study that is similar to pivot points I was able to tweek a "monthly pivot points" that I found in here. Now I would like to create that same study for a "quaterly" and later on "yearly" level. Does anybody know, how to change the time reference for it to create these time levels?

    This is from "monthly Pivot":

    if(vInterval == null)
    return null;

    if(vInterval == "M")
    return null;

    if(vInterval == "T")
    return null;

    var vMonth0 = getMonth();
    var vMonth1 = getMonth(-1);
    if (vMonth0 != vMonth1) {
    vBarTime = getValue("time");
    var vTime = new Date();
    if(vBarTime != null) {
    if (vTime.getYear() == vBarTime.getYear()) {
    vIndex = ((vTime.getMonth()+1 - vBarTime.getMonth()+1) * -1)+1;
    } else {
    vIndex = (((vTime.getMonth()+1 + ((vTime.getYear() - vBarTime.getYear()) * 12)) - vBarTime.getMonth()+1) * -1)+1;
    }
    if(vIndex != null) {
    vH = getValueAbsolute("High", vIndex, vSymbol);
    vL = getValueAbsolute("Low", vIndex, vSymbol);
    vC = getValueAbsolute("Close", vIndex, vSymbol);
    if(vH != null && vL != null && vC != null) {
    vLastPP = (vH + vL + vC) / 3;


    I`ll be thankful for any suggestion

    cheers

  • #2
    muecke
    An easy way to calculate the yearly pivots using daily, weekly or monthly charts is with the pivotpoints.efs that is posted in this thread modified by replacing the following line
    PHP Code:
    if(getBarState()==BARSTATE_NEWBAR&&getDay()!=getDay(-1)) { 
    with the following and save the efs with a different name.
    PHP Code:
    if(getBarState()==BARSTATE_NEWBAR&&getYear()!=getYear(-1)) { 
    For the quarterly pivots you can use the same efs but you first need to determine the beginning of each quarterly period from scratch as that is not an interval that is provided by eSignal.
    So prior to the condition shown above you first need to define a date object and then create the condition that identifies the starting day of each quarter as in the following example
    PHP Code:
    var vTime getValue("time");//create date object using bar time
        
        
    var Condition = (month(0)!=month(-1)) && //Condition is true if this is the first day of a month AND
                        
    (vTime.getMonth()==|| //the month is April OR
                         
    vTime.getMonth()==|| //July OR
                         
    vTime.getMonth()==|| //October OR
                         
    vTime.getMonth()==0); //January 
    At this point you can replace the original condition (shown earlier in this message) with the following
    PHP Code:
    if(getBarState()==BARSTATE_NEWBAR&&Condition) { 
    In this case I replaced the original getDay(0)!=getDay(-1) with the variable Condition
    Implement these simple changes and save the efs with a different name.
    If you have any problems post the code as you have modified and someone will be available to assist you.
    Alex

    Comment


    • #3
      Hi Alex,

      grazie mille per l'aiuto.

      Yearly works perfectly fine. Quaterly does not recognize the change of the year, so it plots the same lines over last quarter of the year and first of the next year.
      Have an idea, how to get around that?

      Thanks a million


      this is the code:
      PHP Code:
      function preMain() {

          
      setPriceStudy(true);
          
      setStudyTitle("Fibonacci Zones Quaterly");
          
      setCursorLabelName("R2"0);
          
      setCursorLabelName("R1"1);
          
      setCursorLabelName("PP"2);
          
      setCursorLabelName("S1"3);
          
      setCursorLabelName("S2"4);
          
      setCursorLabelName("R3"5);
          
      setCursorLabelName("S3"6);
          
      setDefaultBarFgColor(Color.RGB(255,0,0), 0);
          
      setDefaultBarFgColor(Color.RGB(255,0,0), 1);
          
      setDefaultBarFgColor(Color.RGB(0,0,0), 2);
          
      setDefaultBarFgColor(Color.RGB(255,0,0), 3);
          
      setDefaultBarFgColor(Color.RGB(255,0,0), 4);
          
      setDefaultBarFgColor(Color.RGB(255,0,0), 5);
          
      setDefaultBarFgColor(Color.RGB(255,0,0), 6);
          
      setDefaultBarThickness(20);
          
      setDefaultBarThickness(11);   
          
      setDefaultBarThickness(12);
          
      setDefaultBarThickness(13);
          
      setDefaultBarThickness(24);
          
      setDefaultBarThickness(25);
          
      setDefaultBarThickness(26);
          
      setPlotType(PLOTTYPE_FLATLINES,0);
          
      setPlotType(PLOTTYPE_FLATLINES,1);
          
      setPlotType(PLOTTYPE_FLATLINES,2);
          
      setPlotType(PLOTTYPE_FLATLINES,3);
          
      setPlotType(PLOTTYPE_FLATLINES,4);
          
      setPlotType(PLOTTYPE_FLATLINES,5);
          
      setPlotType(PLOTTYPE_FLATLINES,6);
          
      checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/PivotPoints.efs");

      }

      var 
      vOpen null;
      var 
      vOpen1 null;
      var 
      vHigh null;
      var 
      vHigh1 null;
      var 
      vLow null;
      var 
      vLow1 null;
      var 
      vClose1 null;

      var 
      vPP null;
      var 
      vR1 null;
      var 
      vR2 null;
      var 
      vS1 null;
      var 
      vS2 null;
      var 
      vR3 null;
      var 
      vS3 null;


      function 
      main() {
      var 
      vTime getValue("time");
          
          var 
      Condition = (month(0)!=month(-1)) && 
                          (
      vTime.getMonth()==|| 
                           
      vTime.getMonth()==|| 
                           
      vTime.getMonth()==|| 
                           
      vTime.getMonth()==12); 

          if (
      close(-1)==null
              return;
          
          if(
      getBarState()==BARSTATE_NEWBAR&&Condition) {
              
      vHigh1 vHigh;
              
      vLow1 vLow;
              
      vOpen1 vOpen;
              
      vClose1 close(-1);//comment out this line if using alternate vClose1 
              
      vHigh high();
              
      vLow low();
              
      vOpen=open();
          }
          
          if (
      vHigh == null
              
      vHigh high();
          if (
      vLow == null
              
      vLow low();
          
          
      vHigh Math.max(high(), vHigh);
          
      vLow Math.min(low(), vLow);
          
          
          
      //alternate vClose1 if one wants to use the daily bar Close. NOTE that this will not work with Tick Replay
          //vClose1 = call("/OHLC/getPrevOHLC.efs", "Close");  
          
          //for alternative Pivots that require today's Open use vOpen in the Pivot calculations
          
          
          
      vPP = (vHigh1 vLow1 vClose1) / 3;
          
      vR1 vPP + (vHigh1 vLow1) / 2;
          
      vR2 vPP + ( vHigh1 vLow1 ) * 0.618;
          
      vS1 vPP - (vHigh1 vLow1) / 2;
          
      vS2 vPP - ( vHigh1 vLow1 ) * 0.618;
          
      vR3 vPP + ( vHigh1 vLow1 );
          
      vS3 vPP - ( vHigh1 vLow1 );
          
          if (
      vOpen1 == null || vLow1 == null || vHigh1 == null || vClose1 == null) {
              return;
          } else { 
              return new Array(
      vR2,vR1,vPP,vS1,vS2,vR3,vS3);
          }


      I have changed a few formulas, it is not really Pivot, just a variation

      Comment


      • #4
        muecke
        That is happening because of the condition
        vTime.getMonth()==12);
        Months in the date object are numbered from 0 (ie January) to 11 (ie December) so you need to change the condition to
        vTime.getMonth()==0);
        Alex

        Comment


        • #5
          Perfect!!!

          THX

          Comment


          • #6
            muecke
            My pleasure
            Alex

            PS. You may want to remove the checkVersion(...) line from your script to avoid having the efs check for a new version

            Comment


            • #7
              Now I have a really dificult one:

              is there a way, to get a reference to the past 3 calculated Pivots(yearly, quarterly), do a (PP(-1) + PP(-2) + PP(-3)) / 3 and build the same lines on that average?

              any idea?

              Comment


              • #8
                muecke
                To reference past values you will need to create an Array which you update (ie pop and unshift) inside a condition similar to the following
                if(getBarState()==BARSTATE_NEWBAR && myCondition) {
                where myCondition is the condition that identifies a change in quarter or year.
                Once you have populated the Array you can then sum its elements to create the average eg
                myAvgArray = (myArray[0]+myArray[1]+myArray[2])/3
                To simplify the process of maintaining the Array you may want to look into using the ezArray() function that is in the easyArray.efsLib function library available here together with its documentation (see also the example that is provided in this post)
                For information on the Array object and its methods see this article in the EFS KnowledgeBase
                All of the above should provide you with the information required to make the necessary changes
                Alex

                Comment


                • #9
                  Hi Alex,

                  just saw your post today, thank you very much.
                  I'll try....

                  greetings

                  Comment

                  Working...
                  X