Announcement

Collapse
No announcement yet.

Pivot Point Movng Avg.

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

  • Pivot Point Movng Avg.

    I have written an EFS that will draw the Pivot Point MA on the 5 Minute chart however I would have to reload the EFS every few minutes to redraw the line. I used the efsReload function so when I have after two new bars it will reload the efs, however this is causing my esignal get into a loop and it keeps reloading itself and basically it never starts. Of course if I remove the efsreload it will work fine. any suggestion on how I can fix this problem.

    Thank you.

    Behzad G.
    Tony Gof

  • #2
    Hello Tony,

    Generally, you shouldn't need to use reloadEFS() for these types of formulas. Please post your code and I'll take a look.
    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
      Thank you;

      here is my code:

      function preMain()
      {
      var fp1 = new FunctionParameter("PMAPeriod",FunctionParameter.NU MBER);
      fp1.setName("Pivot Moving Avg. Period");
      fp1.setDefault(3);

      var fp2= new FunctionParameter("ShiftMA",FunctionParameter.NUMB ER);
      fp2.setName("Shift MA");
      fp2.setDefault(0);

      setPriceStudy(true);
      setStudyTitle("Pivot Point MA");
      setCursorLabelName("PivotPointMA", 0);
      setDefaultBarStyle(PS_SOLID, 0);
      setDefaultBarFgColor(Color.RGB(255,0,255), 0);
      setDefaultBarThickness(2, 0);


      }

      var vPMAPeriod=null;
      var vShiftMA=0;
      var vPMA=0;
      var CandleCount=0;

      function main(PMAPeriod,ShiftMA)
      {
      vPMAPeriod=PMAPeriod;
      vShiftMA=ShiftMA;



      for (var i=ShiftMA;i<vPMAPeriod-1+ShiftMA;i++)
      {
      vPMA=vPMA + (high(-i) +low(-i) + close(-i))/3;


      }

      vPMA=vPMA/PMAPeriod;

      nState = getBarState();



      if (nState == BARSTATE_NEWBAR) {

      CandleCount++;

      }
      if (CandleCount==2)
      {
      CandleCount=0;
      //reloadEFS();

      }


      return vPMA;


      }
      Tony Gof

      Comment


      • #4
        Tony
        From what I can see the problem in your code is caused by not resetting vPMA to 0 prior to running the for loop.
        The following revision of your code should fix that problem and does not require reloading the efs.

        PHP Code:
        function preMain() {

            var 
        fp1 = new FunctionParameter("PMAPeriod",FunctionParameter.NUMBER);
            
        fp1.setName("Pivot Moving Avg. Period");
            
        fp1.setDefault(3);

            var 
        fp2= new FunctionParameter("ShiftMA",FunctionParameter.NUMBER);
            
        fp2.setName("Shift MA");
            
        fp2.setDefault(0);

            
        setPriceStudy(true);
            
        setStudyTitle("Pivot Point MA");
            
        setCursorLabelName("PivotPointMA"0);
            
        setDefaultBarStyle(PS_SOLID0);
            
        setDefaultBarFgColor(Color.RGB(255,0,255), 0);
            
        setDefaultBarThickness(20);
        }


        function 
        main(PMAPeriod,ShiftMA) {

            var 
        vPMA 0;//ACM moved inside main

            
        for (var i=ShiftMAi<PMAPeriod+ShiftMAi++) {//ACM modified
                
        vPMA += (high(-i) + low(-i) + close(-i))/3;//ACM modified
            
        }

            
        vPMA vPMA/PMAPeriod;

            return 
        vPMA;

        Having said this if what you are trying to do is a simple moving average of (High+Low+Close)/3 then you may find it easier to use the sma() function using hlc3() as the source as shown in the following variation of your script which will return the same values.
        Alex

        PHP Code:
        function preMain() {

            var 
        fp1 = new FunctionParameter("PMAPeriod",FunctionParameter.NUMBER);
            
        fp1.setName("Pivot Moving Avg. Period");
            
        fp1.setDefault(3);

            var 
        fp2= new FunctionParameter("ShiftMA",FunctionParameter.NUMBER);
            
        fp2.setName("Shift MA");
            
        fp2.setDefault(0);

            
        setPriceStudy(true);
            
        setStudyTitle("Pivot Point MA");
            
        setCursorLabelName("PivotPointMA"0);
            
        setDefaultBarStyle(PS_SOLID0);
            
        setDefaultBarFgColor(Color.RGB(255,0,255), 0);
            
        setDefaultBarThickness(20);
        }

        var 
        vPMA null

        function main(PMAPeriod,ShiftMA) {

            if(
        vPMA==nullvPMA offsetSeries(sma(PMAPeriod,hlc3()),ShiftMA);

            return 
        vPMA.getValue(0);

        Comment


        • #5
          Thank you, I will try your code and see how it will work.

          Tony.
          Tony Gof

          Comment


          • #6
            Tony
            You are most welcome.
            Alex

            Comment

            Working...
            X