Announcement

Collapse
No announcement yet.

Question re. MAStudy().getValue()

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

  • Question re. MAStudy().getValue()

    i noticed the following bug:

    var ma0 = new MAStudy(period, 0, "Close", mavg_type);
    var ma0_value = ma0.getValue(MAStudy.MA);

    ma0.getValue(...) initially returns a valid value but then suddenly
    starts returning only 'null'.

    the full code in my main() is below. when running this code i get the following error msg (no crash reporter comes up as the entire eSignal app is now dead cold).

    here is the error msg: dialog title = Microsoft Visual C++ Runtime
    Library

    Runtime Error

    R6025
    - pure virtual function call (in winsig.exe)

    now here is the code of my main function (i was able to bypass this error by using the built-in ema and wma functions instead of MAStudy):
    PHP Code:
    function mainperiodmatype ) {
        if ( 
    period == null || period <= ) {
            
    period 7;
        }

        var 
    mavg_type;

        if ( 
    matype != null ) {
            
    matype.toUpperCase();

            switch ( 
    matype ) {
                case 
    "EMA":
                    
    mavg_type MAStudy.EXPONENTIAL;
                    break;
                case 
    "WMA":
                    
    mavg_type MAStudy.WEIGHTED;
                    break;
                default:
                    
    matype "EMA";
                    
    mavg_type MAStudy.EXPONENTIAL;
            }
        }
        else {
            
    matype "EMA";
            
    mavg_type MAStudy.EXPONENTIAL;
        }

        var 
    studyTitle "D" matype;
        
    setStudyTitle(studyTitle);
        
    setCursorLabelName(studyTitle0);
    _/*
    debugPrintln("period = " + period);
    debugPrintln("matype = " + matype);
    debugPrintln("mavg_type = " + mavg_type);
    debugPrintln("studyTitle = " + studyTitle);
    */

    // create the MA studies for our indicator
    // and get the values of the MA studies

    _/* using MAStudy constructor*/
        
    var ma0 = new MAStudy(period0"Close"mavg_type);
        var 
    ma0_value ma0.getValue(MAStudy.MA);

        if (
    ma0 == null) {
            
    debugPrintln("ma0 == null");
            return;
        }
        else {
            if (
    ma0_value == null) {
                
    debugPrintln("ma0_value = null" );
                return;
            }

            if (
    ma0_value != null) {
                
    debugPrintln("ma0_value = " ma0_value);

                var 
    ma1 = new MAStudy(period0ma0MAStudy.MAmavg_type);
                var 
    ma1_value = (ma0_value) - ma1.getValue(MAStudy.MA);
    // compute the double MA

    debugPrintln("ma1_value = " ma1_value);

                if(
    ma1_value == null) {
                    
    debugPrintln("ma1_value == null");
                    return;
                }
                
    debugPrintln("ma1_value = " ma1_value);
                return 
    ma1_value;  // the double moving average
            
    }
        } 
    and that's it. hope this helps.

  • #2
    terabolic
    There were some errors in the script you posted ie a missing closing curly bracket at the end of the script and a couple of underscores at the beginning of lines 31 and 41. Other than that the formula seems to be working and calculating the DEMA correctly as far as I can see
    Alex

    Comment


    • #3
      hi alex,

      the underscore and missing curly brace are artifacts from my email. what i mean is that the original code i have in the EFS editor does neither have a missing curly brace nor underscores at the beginning of any line. otherwise i wouldn't have been able to run the script.

      so i am really puzzled that it works for you but on my system it causes a crash. but even more puzzling is that MAStudy seems to work fine at the beginning of the run and then suddenly returns a null value.

      possibly yet another issue w/ the underlying OS and its libraries?

      anyhow, i got it to work by using the ema/wma constructors instead. just thought the dev team might want to know a/b this strange behavior.

      thanks for your input.

      Comment


      • #4
        Hi terabolic,

        If the code you posted is incorrect, please attach in a new post your actual code, ensuring it is correct.

        I copied your posted code, made the changes as Alex had suggested and the efs worked for me as well. See the DEMA efs output below in the lower pane along with your debug output in the Formula Output Window.

        Comment


        • #5
          hi steve:

          i tried to run again the code (which is posted below) and though it doesn't cause esignal to crash anymore,
          the debug statements in the output window still show that the
          variable ma0_value is equal to null after the script runs for a couple of secs.
          you have to scroll the formula output window down. i have
          posted a screenshot as well where you can see the output from the debug statements.

          why doesn't esignal crash anymore and the C++ runtime error doesn't appear either?

          the only thing that changed between now and before when i first encountered the problem is this:

          i recently wiped my hd and reinstalled xp pro sp2 because my
          system had been completely disabled by a virus. this is the 1st
          time i run the script again after the clean install and no more crash.

          not sure what we can conclude from this. perhaps before
          reinstall, my system was made too unstable by the virus which
          facilitated the crash and C++ runtime error since now it doesn't occur anymore.

          on the other hand the return value from MAStudy().getValue() is still null after a couple dozen iterations. so that hasn't disappeared.

          if you scroll down the output formula window, do you also see the same output that i have in my output window?

          and why the sudden jump in value from 3.633 etc... to 1.815 etc...?



          /*
          * This function returns the double MA of the specified MA.
          */

          function preMain() {
          setDefaultBarFgColor(Color.white, 0);
          setPlotType(PLOTTYPE_LINE,0);
          setDefaultBarThickness(2,0);
          setPriceStudy(true);
          }

          function main( period, matype ) {
          if ( period == null || period <= 2 ) {
          period = 7;
          }

          var mavg_type;

          if ( matype != null ) {
          matype.toUpperCase();

          switch ( matype ) {
          case "EMA":
          mavg_type = MAStudy.EXPONENTIAL;
          break;
          case "WMA":
          mavg_type = MAStudy.WEIGHTED;
          break;
          default:
          matype = "EMA";
          mavg_type = MAStudy.EXPONENTIAL;
          }
          }
          else {
          matype = "EMA";
          mavg_type = MAStudy.EXPONENTIAL;
          }

          var studyTitle = "D" + matype;
          setStudyTitle(studyTitle);
          setCursorLabelName(studyTitle, 0);
          /*
          debugPrintln("period = " + period);
          debugPrintln("matype = " + matype);
          debugPrintln("mavg_type = " + mavg_type);
          debugPrintln("studyTitle = " + studyTitle);
          */

          // create the MA studies for our indicator
          // and get the values of the MA studies

          /* using MAStudy constructor*/
          var ma0 = new MAStudy(period, 0, "Close", mavg_type);
          var ma0_value = ma0.getValue(MAStudy.MA);

          if (ma0 == null) {
          debugPrintln("ma0 == null");
          return;
          }
          else {
          if (ma0_value == null) {
          debugPrintln("ma0_value = " + ma0_value);
          return;
          }

          if (ma0_value != null) {
          debugPrintln("ma0_value != null");

          var ma1 = new MAStudy(period, 0, ma0,

          MAStudy.MA, mavg_type);
          var ma1_value = (2 * ma0_value) - ma1.getValue

          (MAStudy.MA); // compute the double MA

          debugPrintln("ma1_value = " + ma1_value);

          if(ma1_value == null) {
          debugPrintln("ma1_value == null");
          return;
          }
          debugPrintln("ma1_value = " + ma1_value);
          return ma1_value; // the double moving average
          }
          }


          /* using ema() & wma() built-in functions

          var ma0 = ema(period, close());
          var ma0_value = ma0.getValue(0);

          var ma1 = ema(period, ma0);
          var ma1_value = (2 * ma0_value) - ma1.getValue(0);

          return ma1_value;
          */
          }
          Attached Files
          Last edited by terabolic; 07-05-2006, 09:00 AM.

          Comment


          • #6
            terabolic
            The null returns you are seeing when you scroll down the Formula Output Window are for the very first bars while the average is priming. In fact you should see 7 nulls which correspond to the length of the average.
            The value of 3.633 is again at the beginning of your data file. Scroll back in the chart and you will see that as the average begins plotting that will be the same value.
            The value of 1.815 is the current value being returned by the script and if you go to the top of the Formula Output Window you will see it reported there
            Alex

            Comment

            Working...
            X