Announcement

Collapse
No announcement yet.

Problem: losing the MA of a custom indicator.

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

  • Problem: losing the MA of a custom indicator.

    Is there a problem creating 2 series in a called function?

    I am creating Series1 and using that to make Series2 then getting an MA of Series 2. The calculation of Series1 uses an ATR. No problem at this point. But when I added a volume series to fCalcBarVal, I lost the MA. If I don't use the volume series I can retrieve the MA of the Series2 without problem.

    PHP Code:
    if (!bInit) {
         
    xSeries1 efsInternal("fCalcBarVal"var1var2);
         
    xSeries2 efsInternal("fCalcS2"var3xSeries1);
         
    xMA ema(nLenxSeries2);           // losing this value
         
    bInit=true;
    }

    ...


    function 
    fCalcBarVal(v1v2) {
    if (!
    bInit2) {
         
    xATR=atr(v1);
         
    xMAV=sma(v2volume() );             // when I add this
         
    bInit2=true;
    }
    nATR=xATR.getValue(0);
    nMAV=xMAV.getValue(0);
    // do stuff with these values 
    ... 
    return(
    BarVal);


  • #2
    Just a guess since I can't test out your code, but try:

    PHP Code:
        if (!bInit2) {
            
    xATR=atr(v1);
            
    xMAV=sma(v2volume() );             
            
    xMAV=getSeries(xMAV);             //ADD THIS LINE OF CODE
            
    bInit2=true;
        } 

    Comment


    • #3
      Thanks Wayne.

      I tried that in both bInit sections: main() and the UDF. The problem is with the MA created in main(). Raw bar values are created in fCalcBarVal. That series is used by a 2nd UDF (xTrendy) to create the indicator. Then I'm plotting a moving average in main() of my new improved whizbang indicator.

      The UDF, fCalcBarVal, computes a value for each bar based on the price data of that bar. When I modify the calculation in the UDF to also use the volume of the bar the MA (in main) of the indicator returns a value of zero.

      The MA is fine if I don't add the volume data to the calculation of fCalcBarVal.

      (I didn't post the code because it is over 400 lines and would be laborious to go thru. It is functional w/o the volume calc. But, will do so if that would help)

      PHP Code:
      if (!bInit) {
           
      xCalcBarVal efsInternal("fCalcBarVal"var1var2 );
           
      xTrendyefsInternal("fCalcS2"var3xCalcBarVal );
           
      xMA ema(nLenxTrendy );               // the MA of series 2 is lost 
           
      xMA=getSeries(xMA);                      // with or w/o the get series command
           
      bInit=true;
      }
      var 
      nBarVal xBarVal.getValue(0);
      var 
      nTrendy  xTrendy.getValue(0);
      var 
      nMA xMA.getValue(0);                    //  this value is returning 0


      ...
      return new Array(
      nBarValnTrendynMA);
      }  
      // end of main

      function fCalcBarVal(v1v2) {
      if (!
      bInit2) {
           
      xATR=atr(v1);
           
      xMAV=sma(v2volume() );             // when I add this
           
      bInit2=true;
      }
      nATR=xATR.getValue(0);
      nMAV=xMAV.getValue(0);
      // do stuff with these values 
      ... 
      return(
      BarVal);

      Comment


      • #4
        The code would help so it can be tested.

        Wayne

        Comment


        • #5
          Started to upload the efs 2 wks ago and got sidetracked -- here it is.
          Attached Files

          Comment


          • #6
            See if these changes do what you intended.

            See attached study. Changes I made follow:

            1- commented out line 75.

            2- uncommented menu item for "fpVol"


            3- changed line 177 to:
            PHP Code:
            xCalcBarVal efsInternal("fCalcBarVal"fpATRfpLenfpVol);  // returns 2 series 

            4- on line 384 added:
            PHP Code:
            if(!isFinite(nVWT)) nVWT 1;//@@ ADDED (problem was that "nVWT" sometimes evaluated to infinity) 

            under:
            PHP Code:
            (nAvgVol != 0) ? nVWT = ( volume(0) / xMAV.getValue(0) ): nVWT 1

            5- changed line 328 to:
            PHP Code:
            function fCalcBarVal(_nLA_nLVbVolAdj) {//@@ ADDED "bVolAdj" 
            Wayne
            Attached Files
            Last edited by waynecd; 02-08-2012, 08:57 PM.

            Comment


            • #7
              Thanks Wayne.
              That fixed it. Apparently just checking for a zero value wasn't sufficient. Didn't think of using the isFinite test. Really appreciate your feedback.

              (now i need to find out why email notfiy isn't working - I subscribed to this thread but never got an email)

              PJ

              Comment


              • #8
                Glad it worked.

                Wayne

                Comment

                Working...
                X