Announcement

Collapse
No announcement yet.

function problem?

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

  • function problem?

    Alex, or anyone else, could you take a look at the attached efs? Alex provided it originally. It is a McClellan Osc with a moving average for a signal. I made some slight mods, which work, but there is one thing I can not get to work. In the original, one could change the ma's from simple to exponential, but the signal ma was always a simple ma. I'm trying to make that exponential as well. I'm trying to use the EMA function down at the bottom that is used for the thwo McClellan ma's. Changed the function to accept a third ma, and it checks out if I make a dummy ma. But when I try to use the "aMA" array used for the signal simple ms, it will not work. Using debugPrint, I have verified that all the parameters passed to the EMA function have values. However, the value of vMA (or vEMA[2] for that matter) is always given as "NaN" and thus the exponential ma will not print. Can't figure out why. Anyone have suggestions?
    Attached Files

  • #2
    bigtee
    You may find it easier to modify the McClellan Oscillator which is posted here
    The simplest way to add an expoential moving average to that study is to first declare a global variable called for example
    MAofOsc and set it to null

    var MAofOsc = null;

    Then in the main function inside the bInit statement right after the following line

    mcclellanOsc = efsInternal("calc",Type,Summation,sym(Symbol));

    add the following

    MAofOsc = ema(10,mcclellanOsc);

    This will create an exponential moving average of the McClellan Oscillator. Then replace the existing return statement with the following

    return new Array (getSeries(mcclellanOsc),getSeries(MaofOsc));

    Once you have done that all that is left to do is to add whatever preMain statements are required to name the cursor label, color the plot, etc. Also you may want to add some Function Parameters to make the parameters of the moving average user definable
    Alex

    Comment


    • #3
      Thanks Alex. I had two reasons for doing this efs. One to actually change the ma for use, and two, to learn how to make and call custom functions. Your answer would take care of number one. Any ideas why my call to to the function does not work? This is more an academic question than one to get me to an efs to put on my charts.

      bigtee

      Comment


      • #4
        bigtee
        You omitted to include a null check on the aMA array. In line 119 add
        if(aMA[MALength-1]==null) return;
        Also you need to uncomment lines 152-154
        Alex

        Comment


        • #5
          Thank you Alex.

          I have made myself notes on the solution and the "why" for future use.

          bigtee

          Comment


          • #6
            bigtee
            FWIW regardless of the fix it is still preferable to use the version I suggested earlier as that uses the EFS2 sym() function which correctly synchronizes all the symbols.
            Alex

            Comment

            Working...
            X