Announcement

Collapse
No announcement yet.

GetSeries help needed!

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

  • GetSeries help needed!

    Folks, I cannot seem to get this to work regardless of what I do to coax a non null value. Your guidance is really appreciated:

    function main(IPeriod) {
    .......
    if (!binit) {
    highs1=highest(IPeriod, high());
    lows1=lowest(IPeriod,low());
    hlc1=efsInternal("gethlc3");
    hlcma1=sma(34, hlc1);
    }

    highs0=highs1.getValue(0); <---value is fine
    lows0=lows1.getValue(0); <--- " "
    var hlcc=hlc1.getValue(0);
    debugPrintln(hlcc); <--Only prints nulls!
    .....
    return;
    }
    function gethlc3() {
    return((highs1+lows1+close())/3);
    }

  • #2
    Two observations quickly. You can't add series in your function. You have to deal with each value individually using getValue() and return the result -- which creates your series.

    Also, this gets called for every tick unless you're using setComputeOnClose. Just keep that in mind. Good luck to you.

    Comment


    • #3
      Thanks much for the quick reply.

      I have tried the following to no avail:


      function gethlc3() {
      return((highs1.getValue(0)+lows1.getValue(0)+close (0))/3);
      }
      and

      function gethlc3() {
      return(getSeries(highs1.getValue(0)+lows1.getValue (0)+close(0))/3));
      }

      The returns are recognized as Series but with null values!

      Comment


      • #4
        Try this. This was good practice for me since I'm still trying to learn .efs programming. It's pretty rough, but you get the idea.

        var bInit = false;
        var highs1;
        var lows1;
        var hlc1;
        var hlcma1;
        function main () {
        lPeriod = 5;
        if (bInit == false) {
        highs1=highest(lPeriod,high());
        highs1=getSeries(highs1);
        lows1=lowest(lPeriod,low());
        lows1=getSeries(lows1);
        hlc1=efsInternal("xhlc3", highs1, lows1);
        hlc1=getSeries(hlc1);
        hlcma1=sma(34,hlc1);
        hlcma1=getSeries(hlcma1);
        bInit = true;
        }

        var highs0=highs1.getValue(0);
        var lows0=lows1.getValue(0);
        var hlcc=hlc1.getValue(0);
        debugPrintln(hlcc);
        return;
        }

        function xhlc3(highs1, lows1) {
        var tVal = highs1.getValue(0)+lows1.getValue(0)+close(0);
        tVal /= 3;
        return tVal;
        }

        Comment


        • #5
          Ahhh...Thank you so much, Rla1js!
          It does indeed work.
          Looking a bit into it, It seems to me the crucial difference is the passing of two series buffers to the efsInternal function!
          FYI, I removed all the getSeries, and it still works.
          Another words:

          if (bInit == false) {
          highs1=highest(lPeriod,high());
          lows1=lowest(lPeriod,low());
          hlc1=efsInternal("xhlc3", highs1, lows1);
          hlcma1=sma(34,hlc1);
          bInit = true;
          }

          does seem to work just as well.
          Now, the confusing thing to me is why the global buffers highs1 an lows1 cannot be accessed from the efsInternal (xhlc3)?

          Thanks again.
          \Hossein.

          Comment


          • #6
            Yep, using getSeries is optional in your case. I use it by habit, I think, since I often deal with different intervals within a script.

            I would have thought that, if you define a series variable outside main, that functions would have that series available to them. It seems not to be, however. So, I just pass all needed information and move on to other things. I'm sure someone else here knows but, hey, it's working.

            Good luck to you . . .

            Comment


            • #7
              I'm having almost the sme problem with series objects. I finally got the Histogrm to work correctly but can't get correct values for the signal line: xSig.

              As I understand it the built in functions (ATR, EMA) return a series object unless the BarIndex is specified.

              Also, calling a user defiend function which calculates the value for each bar (getValue(0)) also returns a series object.

              If that is correct then xHist should be a series object which is passed to the ema function to create xSig; but it is returning: (TypeError: xSig has no properties).


              PHP Code:
              /***************************************************
              Lentz Volatility Indicator
              code by PJ Scardino 3/12/11
              3/16/11 added signal line to histogram
              ***************************************************/
              debugClear();
              var 
              nLen 20;
              var 
              aLen 20;
              var 
              bInit false;
              var 
              xATR null;
              var 
              xEMA null;

              function 
              preMain() {

                  
              setPriceStudy(false);
                  
              setStudyTitle("LVI");
                  
                  
              setCursorLabelName("LVI"0);    
                  
              setDefaultBarFgColor(Color.green0);
                  
              setPlotType(PLOTTYPE_HISTOGRAM0);
                  
              setDefaultBarThickness(1,0);

                  
              setCursorLabelName("Sig"1);
                  
              setDefaultBarFgColor(Color.red1);
                  
              setPlotType(PLOTTYPE_LINE1);
                  
              setDefaultBarThickness(1,1);
                  
                  var 
              fp1 = new FunctionParameter("aLen"FunctionParameter.NUMBER);
                  
              fp1.setName("ATR Length");
                  
              fp1.setLowerLimit(1);
                  
              fp1.setDefault(20);    
                  var 
              fp2 = new FunctionParameter("nLen"FunctionParameter.NUMBER);
                  
              fp2.setName("MA Length");
                  
              fp2.setLowerLimit(1);
                  
              fp2.setDefault(20);
              }


              function 
              main(aLennLen) {
                  if (!
              bInit) {
                      
              xATR atr(aLen);
                      
              xEMA ema(nLenxATR);
                      
              bInit true;
                  }
                  
                  var 
              xHist fGetLVI();
                  var 
              xSig ema(9xHist);
                  
              debugPrintlnxSig.getValue(0) );
                  return 
              xHist;
                  
              //return new Array(xHist, xSig );   
              }

              function 
              fGetLVI() {
                  var 
              _ATR xATR.getValue(0);
                  var 
              _EMA xEMA.getValue(0);
                  var 
              _H _ATR _EMA;
                  return 
              _H;

              Comment


              • #8
                pj909

                Also, calling a user defiend function which calculates the value for each bar (getValue(0)) also returns a series object.
                If that function is returning a value then that is true only if it is called using efsInternal()

                If that is correct then xHist should be a series object which is passed to the ema function to create xSig; but it is returning: (TypeError: xSig has no properties).
                In your code xHist is not a series but a single value hence the error message

                For the description and syntax of the efsInternal() function together with examples of its use see this article in the EFS KnowledgeBase.
                You may also want to see the examples on how to create studies on studies that are shown in this thread [even though those make reference for the most part to the efsExternal() function they are applicable also to the efsInternal() function].
                Also review the script discussed earlier in this very same thread.
                Alex


                Originally posted by pj909
                I'm having almost the sme problem with series objects. I finally got the Histogrm to work correctly but can't get correct values for the signal line: xSig.

                As I understand it the built in functions (ATR, EMA) return a series object unless the BarIndex is specified.

                Also, calling a user defiend function which calculates the value for each bar (getValue(0)) also returns a series object.

                If that is correct then xHist should be a series object which is passed to the ema function to create xSig; but it is returning: (TypeError: xSig has no properties).


                PHP Code:
                /***************************************************
                Lentz Volatility Indicator
                code by PJ Scardino 3/12/11
                3/16/11 added signal line to histogram
                ***************************************************/
                debugClear();
                var 
                nLen 20;
                var 
                aLen 20;
                var 
                bInit false;
                var 
                xATR null;
                var 
                xEMA null;

                function 
                preMain() {

                    
                setPriceStudy(false);
                    
                setStudyTitle("LVI");
                    
                    
                setCursorLabelName("LVI"0);    
                    
                setDefaultBarFgColor(Color.green0);
                    
                setPlotType(PLOTTYPE_HISTOGRAM0);
                    
                setDefaultBarThickness(1,0);

                    
                setCursorLabelName("Sig"1);
                    
                setDefaultBarFgColor(Color.red1);
                    
                setPlotType(PLOTTYPE_LINE1);
                    
                setDefaultBarThickness(1,1);
                    
                    var 
                fp1 = new FunctionParameter("aLen"FunctionParameter.NUMBER);
                    
                fp1.setName("ATR Length");
                    
                fp1.setLowerLimit(1);
                    
                fp1.setDefault(20);    
                    var 
                fp2 = new FunctionParameter("nLen"FunctionParameter.NUMBER);
                    
                fp2.setName("MA Length");
                    
                fp2.setLowerLimit(1);
                    
                fp2.setDefault(20);
                }


                function 
                main(aLennLen) {
                    if (!
                bInit) {
                        
                xATR atr(aLen);
                        
                xEMA ema(nLenxATR);
                        
                bInit true;
                    }
                    
                    var 
                xHist fGetLVI();
                    var 
                xSig ema(9xHist);
                    
                debugPrintlnxSig.getValue(0) );
                    return 
                xHist;
                    
                //return new Array(xHist, xSig );   
                }

                function 
                fGetLVI() {
                    var 
                _ATR xATR.getValue(0);
                    var 
                _EMA xEMA.getValue(0);
                    var 
                _H _ATR _EMA;
                    return 
                _H;

                Comment


                • #9
                  OK I changed that line to:
                  var xHist = efsInternal( "fGetLVI");
                  and now the histogram stopped working with a new error occurring in fGetLVI: "xATR has no properties "

                  Comment


                  • #10
                    HELP - Why does efsInternal take so long?

                    Below are 2 code snippets. The first one does the calculation in main and loads instantly. The second puts the calculation in a function and takes almost 3 minutes to load.

                    PHP Code:
                    function main(aLennLen) {
                        if (!
                    bInit) {
                            
                    xATR atr(aLen);
                            
                    xEMA ema(nLenxATR);
                            
                    bInit true;
                        }
                        if(
                    xATR.getValue(0) == null || xEMA.getValue(0) == null) return;
                        
                    nLVI xEMA.getValue(0) -  xATR.getValue(0);
                        return 
                    nLVI;

                    There has to be a better way than this (it takes so long the program looks like it crashed):

                    PHP Code:
                    function main(aLennLen) {
                        if (!
                    bInit) {
                            
                    xATR atr(aLen);
                            
                    xEMA ema(nLenxATR);
                            
                    bInit true;
                        }
                        if(
                    xATR.getValue(0) == null || xEMA.getValue(0) == null) return;
                        var 
                    xLVI efsInternal("fGetLVI"xEMA.getValue(0), xATR.getValue(0) );
                        return 
                    xLVI.getValue(0);
                    }
                    function 
                    fGetLVI(_nM_nA) {
                        
                    _nLVI =  (_nM _nA );
                        return 
                    _nLVI;

                    The reason I'm using efsInternal is to return a series so I can add a Moving Average of LVI. I think this is what I will need to get the ema:
                    PHP Code:
                    var xSig ema(9xLVI);
                    return new Array(
                    xLVI.getValue(0), xSig.getValue(0)); 

                    Comment


                    • #11
                      pj909
                      The reason is that in your efsInternal() call you are passing values [eg myVar.getValue(0), etc] instead of series and because these change constantly the efs engine creates a new instance of the series object at every change hence using up resources.
                      Furthermore you should make that call inside the same bInit routine rather than outside of it [which also means that you need to declare the variable to which you assign the series object as a global variable] and then in the same routine calculate also whatever other study based on that series you want [again using global variables]
                      Again I would suggest that you review the examples at the link I suggested in my previous reply and also the script discussed earlier in this very same thread
                      Alex


                      Originally posted by pj909
                      HELP - Why does efsInternal take so long?

                      Below are 2 code snippets. The first one does the calculation in main and loads instantly. The second puts the calculation in a function and takes almost 3 minutes to load.

                      PHP Code:
                      function main(aLennLen) {
                          if (!
                      bInit) {
                              
                      xATR atr(aLen);
                              
                      xEMA ema(nLenxATR);
                              
                      bInit true;
                          }
                          if(
                      xATR.getValue(0) == null || xEMA.getValue(0) == null) return;
                          
                      nLVI xEMA.getValue(0) -  xATR.getValue(0);
                          return 
                      nLVI;

                      There has to be a better way than this (it takes so long the program looks like it crashed):

                      PHP Code:
                      function main(aLennLen) {
                          if (!
                      bInit) {
                              
                      xATR atr(aLen);
                              
                      xEMA ema(nLenxATR);
                              
                      bInit true;
                          }
                          if(
                      xATR.getValue(0) == null || xEMA.getValue(0) == null) return;
                          var 
                      xLVI efsInternal("fGetLVI"xEMA.getValue(0), xATR.getValue(0) );
                          return 
                      xLVI.getValue(0);
                      }
                      function 
                      fGetLVI(_nM_nA) {
                          
                      _nLVI =  (_nM _nA );
                          return 
                      _nLVI;

                      The reason I'm using efsInternal is to return a series so I can add a Moving Average of LVI. I think this is what I will need to get the ema:
                      PHP Code:
                      var xSig ema(9xLVI);
                      return new Array(
                      xLVI.getValue(0), xSig.getValue(0)); 

                      Comment


                      • #12
                        I did review those posts but you last comment about the EFS engine creating a new instance of the series helped. I'm getting more clear on when to use getValue. Was thinking I had to use that for each bar to calculate each value. Here is what I think I und3erstand now. I pass the series to the User Defined Function. The the function gets the individual values.

                        What I'm not clear on is what to to return. I've seen examples of returning the series vs returning an individual bar value. In fact the KB (getSeries notes) even suggests returning the series in main(). As for the UDF, if you pass a series, why wouldn't you return a series (instead of return getValue(0) etc)?

                        Anyway here is the working code.
                        PHP Code:
                        /*************************************************
                        Lentz Volatility Indicator
                        Steve Lentz of Discover Options came up with this idea.  See page 4 of article:
                        [url]www.discoveroptions.com/externalLive/education/enewsletters/OptionVIEWS_3_11.pdf[/url]
                        SV (Statistical Volatility) generally corresponds to market direction.  High SV
                        usually occurs as the market is falling and vice versa.  The purpose of LVI is 
                        to give an generalindication of the direction of trend.
                        PJ Scardino 3/12/11
                        3/21/11 modified original indicator to include a signal line to try and "front-run"
                        the volatility signal.  ie The farther volty moves away from its MA the more likely
                        it is to 'revert to the mean' or even swing to the other side.   
                        *************************************************/
                        debugClear();

                        var 
                        nLen 20;
                        var 
                        aLen 20;
                        var 
                        sLen 9;
                        function 
                        preMain() {

                            
                        setPriceStudy(false);
                            
                        setStudyTitle("LVI-sig");
                            
                            
                        setCursorLabelName("LVI"0);    
                            
                        setDefaultBarFgColor(Color.green0);
                            
                        setPlotType(PLOTTYPE_HISTOGRAM0);
                            
                        setDefaultBarThickness(2,0);

                            
                        setCursorLabelName("Sig"1);
                            
                        setDefaultBarFgColor(Color.blue1);
                            
                        setPlotType(PLOTTYPE_LINE1);
                            
                        setDefaultBarThickness(1,1);
                            
                            var 
                        fp1 = new FunctionParameter("aLen"FunctionParameter.NUMBER);
                            
                        fp1.setName("ATR Length");
                            
                        fp1.setLowerLimit(1);
                            
                        fp1.setDefault(20);    
                            var 
                        fp2 = new FunctionParameter("nLen"FunctionParameter.NUMBER);
                            
                        fp2.setName("MA Length");
                            
                        fp2.setLowerLimit(1);
                            
                        fp2.setDefault(20);
                            var 
                        fp3 = new FunctionParameter("sLen"FunctionParameter.NUMBER);
                            
                        fp3.setName("Length of EMA for Signal line");
                            
                        fp3.setLowerLimit(1);
                            
                        fp3.setDefault(9);
                        }

                        var 
                        bInit false;
                        var 
                        xATR null;
                        var 
                        xEMA null;
                        var 
                        xLVI null;
                        var 
                        xSig null;

                        function 
                        main(aLennLensLen) {
                            if (!
                        bInit) {
                                
                        xATR atr(aLen);
                                
                        xEMA ema(nLenxATR);
                                
                        xLVI efsInternal("fGetLVI"xEMAxATR );
                                
                        xSig ema(sLenxLVI);
                                
                        bInit true;
                            }
                            if(
                        xATR.getValue(0) == null || xEMA.getValue(0) == null) return;
                            
                            if (
                        xLVI.getValue(0) > 0) {            // bullish bias
                                
                        if (xLVI.getValue(0) > xSig.getValue(0)) {
                                    
                        setBarFgColorColor.RGB(0,192,0), ); 
                                } else {
                                    
                        setBarFgColorColor.RGB(128,128,0), ); 
                                } 
                            } else {                        
                        // bearish bias
                                
                        if (xLVI.getValue(0) < xSig.getValue(0)) {
                                    
                        setBarFgColorColor.RGB(192,0,0), ); 
                                } else {
                                    
                        setBarFgColor(Color.RGB(192,128,0), );
                                }
                            }

                            return new Array(
                        xLVI.getValue(0), xSig.getValue(0));
                        }
                        function 
                        fGetLVI(_xM_xA) {
                            
                        _nLVI =  (_xM.getValue(0) - _xA.getValue(0) );
                            return 
                        _nLVI;

                        Comment


                        • #13
                          pj909

                          What I'm not clear on is what to to return. I've seen examples of returning the series vs returning an individual bar value.
                          Unless you are plotting a study based on an external interval [and/or symbol] and you want its plot to be continuously adjusted in real time across the entire corresponding time frame on the chart [see this thread for a brief explanation of this] you do not need to return the series and can just return the value.
                          Alex


                          Originally posted by pj909

                          I did review those posts but you last comment about the EFS engine creating a new instance of the series helped. I'm getting more clear on when to use getValue. Was thinking I had to use that for each bar to calculate each value. Here is what I think I und3erstand now. I pass the series to the User Defined Function. The the function gets the individual values.

                          What I'm not clear on is what to to return. I've seen examples of returning the series vs returning an individual bar value. In fact the KB (getSeries notes) even suggests returning the series in main(). As for the UDF, if you pass a series, why wouldn't you return a series (instead of return getValue(0) etc)?

                          Anyway here is the working code.
                          PHP Code:
                          /*************************************************
                          Lentz Volatility Indicator
                          Steve Lentz of Discover Options came up with this idea.  See page 4 of article:
                          /www.discoveroptions.com/externalLive/education/enewsletters/OptionVIEWS_3_11.pdf
                          SV (Statistical Volatility) generally corresponds to market direction.  High SV
                          usually occurs as the market is falling and vice versa.  The purpose of LVI is 
                          to give an generalindication of the direction of trend.
                          PJ Scardino 3/12/11
                          3/21/11 modified original indicator to include a signal line to try and "front-run"
                          the volatility signal.  ie The farther volty moves away from its MA the more likely
                          it is to 'revert to the mean' or even swing to the other side.   
                          *************************************************/
                          debugClear();

                          var 
                          nLen 20;
                          var 
                          aLen 20;
                          var 
                          sLen 9;
                          function 
                          preMain() {

                              
                          setPriceStudy(false);
                              
                          setStudyTitle("LVI-sig");
                              
                              
                          setCursorLabelName("LVI"0);    
                              
                          setDefaultBarFgColor(Color.green0);
                              
                          setPlotType(PLOTTYPE_HISTOGRAM0);
                              
                          setDefaultBarThickness(2,0);

                              
                          setCursorLabelName("Sig"1);
                              
                          setDefaultBarFgColor(Color.blue1);
                              
                          setPlotType(PLOTTYPE_LINE1);
                              
                          setDefaultBarThickness(1,1);
                              
                              var 
                          fp1 = new FunctionParameter("aLen"FunctionParameter.NUMBER);
                              
                          fp1.setName("ATR Length");
                              
                          fp1.setLowerLimit(1);
                              
                          fp1.setDefault(20);    
                              var 
                          fp2 = new FunctionParameter("nLen"FunctionParameter.NUMBER);
                              
                          fp2.setName("MA Length");
                              
                          fp2.setLowerLimit(1);
                              
                          fp2.setDefault(20);
                              var 
                          fp3 = new FunctionParameter("sLen"FunctionParameter.NUMBER);
                              
                          fp3.setName("Length of EMA for Signal line");
                              
                          fp3.setLowerLimit(1);
                              
                          fp3.setDefault(9);
                          }

                          var 
                          bInit false;
                          var 
                          xATR null;
                          var 
                          xEMA null;
                          var 
                          xLVI null;
                          var 
                          xSig null;

                          function 
                          main(aLennLensLen) {
                              if (!
                          bInit) {
                                  
                          xATR atr(aLen);
                                  
                          xEMA ema(nLenxATR);
                                  
                          xLVI efsInternal("fGetLVI"xEMAxATR );
                                  
                          xSig ema(sLenxLVI);
                                  
                          bInit true;
                              }
                              if(
                          xATR.getValue(0) == null || xEMA.getValue(0) == null) return;
                              
                              if (
                          xLVI.getValue(0) > 0) {            // bullish bias
                                  
                          if (xLVI.getValue(0) > xSig.getValue(0)) {
                                      
                          setBarFgColorColor.RGB(0,192,0), ); 
                                  } else {
                                      
                          setBarFgColorColor.RGB(128,128,0), ); 
                                  } 
                              } else {                        
                          // bearish bias
                                  
                          if (xLVI.getValue(0) < xSig.getValue(0)) {
                                      
                          setBarFgColorColor.RGB(192,0,0), ); 
                                  } else {
                                      
                          setBarFgColor(Color.RGB(192,128,0), );
                                  }
                              }

                              return new Array(
                          xLVI.getValue(0), xSig.getValue(0));
                          }
                          function 
                          fGetLVI(_xM_xA) {
                              
                          _nLVI =  (_xM.getValue(0) - _xA.getValue(0) );
                              return 
                          _nLVI;

                          Comment

                          Working...
                          X