Announcement

Collapse
No announcement yet.

efs not updating real time

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

  • efs not updating real time

    I downloaded an efs from 3-18-2004
    by steve hare called weighted ma of regression.efs. I loaded it into an advanced chart and it goes in fine. It does not update with the price bars though. It stays on the bar it was on when the chart opens or the efs is added to the chart. I tried selecting reload and it updates to the current bar but then stays on that bar and does not update as the bars move with time. I need help adjusting the code to cause the efs to update with the current bar. I have tried to add the efs as an attachment.
    Attached Files

  • #2
    Hi ScottD,

    The attachment did not come through, however, I believe you are referring to the efs in this post.

    I just downloaded it and ran it in tick replay and it updated fine when tested in that manner (simulated real time). It did have an issue with the lines changing slightly when reloaded in tick playback, which I did fix.

    Please check out the revised efs at this link and see if that fixes any problem you were having with the efs.

    Comment


    • #3
      updating

      Thanks Steve, I'll try the new efs today.
      I really like the MA of regression so hope it works for me. I'll post later today or tomorrow and let you know if it updates for me. Sorry my attachment did not work.

      Comment


      • #4
        New link similar not same

        Steve, I tried the new link and actually it was not the one I was using. The one that I was using was the similar one without the bands. You had been responding with someone else and created one without bands and then added the bands as an improvement. I placed the new one with bands on my advanced charts today so I'll see if they update. I'll try later to see if I can get the one I was using to show up in an attachment.

        Comment


        • #5
          WA ma/ no bands not updating

          Steve if you are checking back, the WA ma regression with the bands works and updates correctly. Included in this post is the text of the similar efs that does not have the bands. I do not see the difference that this one is not updating. Thanks for the additional work.


          February 2004
          Use and/or modify this code freely. If you redistribute it
          please include this and/or any other comment blocks and a
          description of any changes you make.
          ************************************************** ********/

          //defines global variables
          var nArray;
          var nArray1;
          var nArray2;
          var barcount = 0;


          function preMain(){
          setStudyTitle("title");
          setPriceStudy(true);//buttons displayed in price pane
          // setPriceStudy(false);//buttons displayed in non price pane
          setCursorLabelName("Reg", 0);
          setCursorLabelName("Wma", 1);
          setCursorLabelName("2", 2);
          setCursorLabelName("3", 3);
          setCursorLabelName("4", 4);
          setCursorLabelName("5", 5);
          setDefaultBarFgColor(Color.cyan, 0);
          setDefaultBarFgColor(Color.green, 1);
          setDefaultBarThickness(2,0);
          setDefaultBarThickness(2,1);
          nEditProperties();//Function Parameter statements
          }

          function main(nReg,nWma,Source,Unused){

          if (getBarState() == BARSTATE_ALLBARS) {//true once during initial load and subsequent reload using reloadEFS()
          nArray = Initialize_1X_Array(nReg);//calls array definition function, setting array to length of regression analysis
          nArray1 = Initialize_1X_Array(nWma);//setting array to length of weighted moving average
          nArray2 = Initialize_1X_Array(2);//set array to length of 2
          }

          if (getCurrentBarIndex() < -1000)return;
          if (getBarState() == BARSTATE_NEWBAR) {
          barcount++;


          var a = Price(Source); //function returns the function Price

          nArray.pop(); nArray.unshift(a); //populating Price Source into an array

          if (barcount > nReg){//prevents regression from being called until nArray is long enough
          var lsf = LSF(nReg, nArray);//calls linear regression function (returns an array)
          nArray1.pop(); nArray1.unshift(lsf[3]); //unshifts regression value into an array
          }

          if (barcount > (nReg + nWma)){//prevents moving average from being called until nArray1 is long enough
          var wma = WMA(nWma, nArray1);//calls weighted moving average function(returns a weighted average)
          nArray2.pop(); nArray2.unshift(wma); //unshifts weighted average into an array (in case previous value is needed)
          }

          return new Array(nArray1[0], nArray2[0]); //returns the two values to the chart
          }
          }


          //--support functions--support functions--support functions--support functions--support functions--

          function LSF(nv1,fnArray){//Linear Least Squares Fit routine
          if (nv1 < 2){nv1 = 2;}//prevents division by zero "ouch!!" for nv1 = 0
          var sXX = 0.0; var sYY = 0;var sXY = 0; var sX = 0.0; var sY = 0;var i;
          for(i = 0; i < nv1; i++) {//y = nInt + nSlope*x
          sX += nv1-i;sY += fnArray[i];
          sYY += Math.pow(fnArray[i],2);sXX += Math.pow((nv1-i),2);
          sXY += (nv1-i)*fnArray[i];
          }
          var xAve = sX /nv1;var yAve = sY / nv1;
          var nSlope = (nv1*sXY - sX*sY) / (nv1*sXX - sX*sX);
          var nInt = (sY - nSlope * sX)/nv1;//if(debug)debugPrintln("a = "+a);
          var RR= (Math.pow((sXY-nv1*yAve*xAve),2))/(((sXX-xAve*xAve*nv1)*(sYY-yAve*yAve*nv1)));
          var pred1 = nSlope*(nv1+1) + nInt;var pred2 = nSlope*(nv1+2) + nInt;
          return new Array (nSlope.toFixed(8)*1, nInt.toFixed(8)*1, RR.toFixed(8)*1,pred1.toFixed(4)*1,pred2.toFixed(4 )*1);
          //lsf = LSF(nv1,fnArray) where lsf[0] = slope, lsf[1] = Int, lsf[2] = RR, lsf[3] = pred1, lsf[4] = pred2,
          }//End Linear Least Squares Fit routine

          function WMA(nn,fnArray) { //weighted moving average
          if (nn < 2){nn = 2;}//prevents division by zero "ouch!!" for nn = 0
          var dSum = 0.0; var iSum = 0.0; var i;
          for(i = 0; i < nn; i++){dSum += fnArray[i]*(nn - i); iSum += nn - i;}
          return ((dSum / iSum).toFixed(4)*1);
          } //End weighted moving average

          function Initialize_1X_Array(n1){//initialize 1 dim array
          var i; var newArray = new Array();
          if (n1 == null){n1 =2;}
          for (i = 0;i < n1; i++){newArray[i] = 0;}
          return newArray;
          }

          function Price (n){

          var a = close();var b = high();var c = low();var d = open();
          var nn = close();
          if (n == "High")nn = b;
          else if (n == "Low")nn = c;
          else if (n == "Open")nn = d;
          else if (n == "HL/2")nn = (b+c)/2;
          else if (n == "HLC/3")nn = (a+b+c)/3;
          else if (n == "OHLC/4")nn = (a+b+c+d)/4;
          return nn.toFixed(3)*1;
          }

          function nEditProperties() { //contains all the edit studies Function Parameter statements normally in premain, put here for clarity

          var fp1 = new FunctionParameter("nReg", FunctionParameter.NUMBER);
          fp1.setName("Regression Length");
          fp1.setLowerLimit(2);
          fp1.setDefault(21);

          var fp2 = new FunctionParameter("nWma", FunctionParameter.NUMBER);
          fp2.setName("Moving Average Length");
          fp2.setLowerLimit(2);
          fp2.setDefault(21);

          var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
          fp3.setName("Source");
          fp3.addOption("Close");
          fp3.addOption("High");
          fp3.addOption("Low");
          fp3.addOption("Open");
          fp3.addOption("HL/2");
          fp3.addOption("HLC/3");
          fp3.addOption("OHLC/4");
          fp3.setDefault("Close"); //Edit this value to set a new default

          var fp4 = new FunctionParameter("Unused", FunctionParameter.STRING);//work-around to space out edit sudies
          fp4.setName("Unused");
          fp4.setDefault("[ ]");

          }

          Comment


          • #6
            Hi ScottD,

            You are most welcome. I looked at the differences between the two efs's for awhile but without spending more time, I was unable to figure out why the first efs behaved as it did. With the availability of the new efs2 functionality, I would probably code it differently so it would be more efficient and not so complex. I am glad the second one worked out well for you, I appreciate the feedback.

            Comment

            Working...
            X