Announcement

Collapse
No announcement yet.

Indicator only updates dynamically ?

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

  • Indicator only updates dynamically ?

    Can someone kindly enlighten me as to why my example indicator (below) will not draw a line for the entire length of chart history but instead only start from current time going forwards (dynamic only, from loading time)?

    Apologies in advance if it is blindingly obvious....

    1000 Thanks, DD

    /*************************
    .DD Test
    ***************************/

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("DD Test")
    setCursorLabelName("DD Test",0);
    setDefaultBarFgColor(Color.blue,0)
    setShowTitleParameters( true );
    }
    var LRs = null;

    function main() {

    if (LRs == null) LRs = middleLinearReg(21, 2,close());

    return sma(8, LRs);
    }

  • #2
    No reply still? Must be a hard one....

    Basically the Lin Reg indicator alone works perfectly across the whole chart history, as too does the SMA. But when you use the first as an input to the second you get no resulting line.

    Is this a problem with one being a 'series' and perhaps not being called up as such?

    Please help if anyone has any clues. I am new to this language and frankly am confused with things such as getValue, getSeries etc.

    Thanks in advance.
    DD

    Comment


    • #3
      Hi,

      The LR indicator only plots the defined length as can be seen below for the following efs script:

      PHP Code:
      function preMain() {
      setPriceStudy(false);
      setStudyTitle("DD Test")
      setCursorLabelName("DD Test",0);
      setDefaultBarFgColor(Color.blue,0)
      setShowTitleParameterstrue );
      }
      var 
      LRs null;
      function 
      main() { 
          return 
      middleLinearReg(212,close());

      Wayne
      Attached Files

      Comment


      • #4
        Try this efs to which I added a SMA(8) to match your script.

        Wayne

        PHP Code:
        /*********************************
        //http://forum.esignal.com/showthread.php?s=&threadid=30196&highlight=SEB+LinRegSlope
        Provided By:    eSignal (Copyright c eSignal), a division of Interactive Data
            Corporation. 2009. All rights reserved. This sample eSignal
            Formula Script (EFS) is for educational purposes only and may be
            modified and saved under a new file name.  eSignal is not responsible
            for the functionality once modified.  eSignal reserves the right
            to modify and overwrite this EFS file with each new release.
        Description:          This indicator plots the slope of linear regression in oscilator-like
            manner. This is a part of Standard Error Bands study.
        Version:            1.0  03/19/2009
        Formula Parameters:                     Default:
            Length                              21
        Notes:
            Linear Regression is a concept also know as the "least squares method" or
            "best fit". Linear Regression attempts to fit a straight line between several
            data points in such a way that distance between each data point and the line is
            minimized.
            "Standard Error Bands" Jon Anderson, Stocks&Commodities Magazine, Traders Tips, 09/1996
        **********************************/
        //20110524 added SMA of LR
        var fpArray = new Array();
        var 
        bInit false;
        function 
        preMain() {
            
        setStudyTitle("SEB LinRegSlope");
            
        setCursorLabelName("Slope"0);
            
        setDefaultBarFgColor(Color.red0);
            
        addBand(0PS_SOLID1Color.cyan);

            var 
        x=0;
            
        fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
            
        with(fpArray[x++]){
                
        setLowerLimit(1);
                
        setDefault(21);
            }
        }
        var 
        xSL null;
        var 
        SMA8;
        function 
        main(Length) {

        var 
        nBarState getBarState();
        var 
        nSL 0;
            if (
        nBarState == BARSTATE_ALLBARS) {
                if (
        Length == nullLength 21;
            }
            if (
        bInit == false) {
                
        xSL efsInternal("calc"Length);
                
        SMA8 sma(8xSL);
                
        SMA8 getSeries(SMA8);
                
        bInit true;
            }
            
        nSL xSL.getValue(0);
            if (
        nSL == null) return;
            return 
        SMA8;//nSL;
        }
        var 
        xClose null;
        var 
        xInit false;

        function 
        calc(Length) {
        var 
        SL 0;
        var 
        SumBars Length * (Length 1) * 0.5;
        var 
        SumSqrBars = (Length 1) * Length * (Length 1) / 6;
        var 
        Sum1 0;
        var 
        SumY 0;
        var 
        0;

            if(
        xInit==false){
                
        xClose close();
                
        xInit true;
            }
            for (
        0Lengthi++) {
                
        Sum1 += xClose.getValue(-i);
                
        SumY += xClose.getValue(-i);
            }
            var 
        Sum2 SumBars SumY;
            var 
        Num1 Length Sum1 Sum2;
            var 
        Num2 SumBars SumBars Length SumSqrBars;
            
        SL Num1 Num2;
            return 
        SL;

        Last edited by waynecd; 05-24-2011, 12:46 AM.

        Comment


        • #5
          Thanks for your reply Wayne.
          I get an error when I run your code:
          "SyntaxCheck, line 26: Formula file not found:"

          Actually I must apologise. I realised earlier that it (middleLinearReg) prints only as far back as the defined length and then found the code below instead, which I used, and which did work across the whole range. This is what I should have been referring to in second post and got the two confused after trying so many variations.

          function main() {
          var n = 21;
          var sum = 0;
          var i = 0;
          var LRs = 0;

          for(i = n; i > 0; i--)
          sum += (i - (n + 1) / 3) * close(i - n)
          LRs = 6 / (n * (n + 1)) * sum;
          return LRs

          Now here the LRs works perfectly across the chart.

          But how to take SMA of this?

          I tried sma(8,"LRs") but this just returns sma(8) of close.
          How does one get it to refer to LRs as the input?

          Note, lengths here are just for example, nothing specific.

          Thanks.

          Comment


          • #6
            The study I posted works fine in ver 10.6 latest release. Line 26 reads:
            PHP Code:
            setCursorLabelName("Slope"0); 
            so it has nothing to do with calling a file. Not sure why you get an error, maybe there is another study loaded on the chart?

            I don't use ver 11 since it is not ready for prime time yet (has issues with studies that use tick intervals).

            In any case the following works in 10.6 and uses your formula:
            PHP Code:
            var bInit false;//limits execution to once upon script loading
            var nLRsnSMA;
            function 
            main() { 
                if(!
            bInit){//if bInit is false
                    
            nLRs efsInternal("LRcalc");//creates LR series - lookup "efsInternal" in the knowledgebase
                    
            nSMA sma(8nLRs);//uses "nLRs" series as the souce of data
                    
            nSMA getSeries(nSMA);
                    
            bInit true;
                }
                return 
            nSMA;
            }
            function 
            LRcalc(){//separate function so it creates a series for use in the sma(...) calc
                
            var 21;
                var 
            sum 0;
                var 
            0;
                var 
            LRs 0;

                for(
            n0i--)
                
            sum += (- (1) / 3) * close(n)
                
            LRs / (* (1)) * sum
                return 
            LRs

            This is the chart displaying both studies:

            Wayne
            Attached Files
            Last edited by waynecd; 05-24-2011, 03:01 PM.

            Comment


            • #7
              Out of interest Wayne, what happens if you swap the two indicators around - taking LR of the SMA ?

              I tried the following but get nothing. I imagine that again it is a "series"issue. Anything obviously wrong here?

              Thanks, DD.


              var bInit = false;//limits execution to once upon script loading
              var nLRs, nSMA;

              function main() {

              if(!bInit){//if bInit is false
              nSMA = sma(8, "close");
              nSMA = getSeries(nSMA);
              nLRs = efsInternal("LRcalc");//creates LR series - lookup "efsInternal" in the knowledgebase
              bInit = true;
              }
              return nLRs;
              }
              function LRcalc(){//separate function so it creates a series
              var n = 21;
              var sum = 0;
              var i = 0;
              var LRs = 0;

              for(i = n; i > 0; i--)
              sum += (i - (n + 1) / 3) * nSMA(i - n)
              LRs = 6 / (n * (n + 1)) * sum;
              return LRs
              }

              Comment


              • #8
                In this particular case it seems both (returning the nLRs or the nSMA) methods produce the same plot.

                PHP Code:
                var bInit false;//limits execution to once upon script loading
                var nLRsnSMA;

                function 
                main() { 

                    if(!
                bInit){//if bInit is false
                        
                nSMA sma(8"close");
                        
                nSMA getSeries(nSMA);
                        
                nLRs efsInternal("LRcalc",nSMA);//creates LR series - lookup "efsInternal" in the knowledgebase
                        
                bInit true;
                    }
                    return 
                nLRs.getValue(0);
                }
                function 
                LRcalc(sSMA){//separate function so it creates a series 
                    
                var 21;
                    var 
                sum 0;
                    var 
                0;
                    var 
                LRs 0;

                    for(
                n0i--){
                        
                sum += (- (1) / 3) * sSMA.getValue(n);
                    }  
                    
                LRs / (* (1)) * sum
                    return 
                LRs;

                This is the same script with a small coding difference:
                PHP Code:
                var bInit false;//limits execution to once upon script loading
                var nLRsnSMA;

                function 
                main() { 

                    if(!
                bInit){//if bInit is false
                        
                nSMA sma(8"close");
                        
                nSMA getSeries(nSMA);
                        
                nLRs getSeries(efsInternal("LRcalc",nSMA));//creates LR series - lookup "efsInternal" in the knowledgebase
                        
                bInit true;
                    }
                    return 
                nLRs;//.getValue(0);
                }
                function 
                LRcalc(sSMA){//separate function so it creates a series 
                    
                var 21;
                    var 
                sum 0;
                    var 
                0;
                    var 
                LRs 0;

                    for(
                n0i--){
                        
                sum += (- (1) / 3) * sSMA.getValue(n);
                    }  
                    
                LRs / (* (1)) * sum
                    return 
                LRs;

                Wayne
                Last edited by waynecd; 05-27-2011, 02:13 AM.

                Comment


                • #9
                  Many thanks again Wayne. Looks so simple when you know what you are doing.
                  I see I have a lot to learn here about the intricacies of series and functions but you have gone a long way in helping me already by showing me what you have in these few examples. Much appreciated....

                  Cheers.
                  DD

                  Comment


                  • #10
                    yw

                    Wayne

                    Comment

                    Working...
                    X