Announcement

Collapse
No announcement yet.

Modification to AMA.efs ??

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

  • Modification to AMA.efs ??

    I would like to modify the AMA.efs (kaufman adaptive moving avg.) so that it can be offset or lagged forward by 2 bars and also so it calculates only on the close of the bar instead of every tick. Offsetting this AMA forward provides much shaper and clearer cutoffs with fewer whipsaws. I could do this in a few minutes using TS easy language or Ensign's ESPL but I don't even know where to begin with Java.

    Would someone like to take a crack at it? The original code below was written by Mechos (file sharing site).


    function preMain()
    {
    setPriceStudy(true);
    }

    var dLastAMA = 0.0;
    var dThisAMA = 0.0;
    var fc;
    var sc;

    function main(nLength,nFastPeriod,nSlowPeriod)
    {
    if(nLength == null)
    nLength = 9;
    if(nFastPeriod == null)
    nFastPeriod = 2;
    if(nSlowPeriod == null)
    nSlowPeriod = 30;

    var nBarState = getBarState();
    var vClose;
    var i;
    var volatility = 0.0;
    var ratio;
    var ssc;
    var constant;

    if(nBarState == BARSTATE_ALLBARS) {
    // reset!
    dLastAMA = 0.0;
    dThisAMA = 0.0;
    fc = 2/(nFastPeriod + 1);
    sc = 2/(nSlowPeriod + 1);
    }
    else if(nBarState == BARSTATE_NEWBAR) {
    dLastAMA = dThisAMA;
    }
    dThisAMA = dLastAMA;

    vClose = close(0,-nLength - 1);
    if(vClose == null)
    return;
    for(i = 0;i < nLength;i++){
    volatility += Math.abs(vClose[i] - vClose[i+1]);
    }
    ratio = Math.abs((vClose[0] - vClose[nLength-1]) / volatility);
    ssc = ratio * (fc - sc) + sc;
    constant = ssc * ssc;
    dThisAMA = dLastAMA + (constant * (vClose[0] - dLastAMA));
    return(dThisAMA);
    }

  • #2
    Rick
    FWIW Michael Phillips, who wrote the code for the AMA.efs, then further improved that formula in the AMAbands.efs (also available in the Mechos group) while adding bands and the ability to select the Source for the calculations.
    If you want the advantages of the improved version but don't need the bands here is the code. It still does not include any offset though.
    As to computing on Close only just go to Tools->EFS Settings in the Main Menu and check the "Make all formulas compute on Close" setting.
    Alex

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("AMA2");
    setCursorLabelName("AMA", 0);
    setDefaultBarFgColor(Color.blue, 0);
    }

    var dLastAMA = 0.0;
    var dThisAMA = 0.0;
    var fc;
    var sc;
    var bPrimed;

    function main(strSource,nLength,nFastPeriod,nSlowPeriod)
    {
    if(strSource == null)
    strSource = "Close";
    if(nLength == null)
    nLength = 9;
    if(nFastPeriod == null)
    nFastPeriod = 2;
    if(nSlowPeriod == null)
    nSlowPeriod = 30;

    var nBarState = getBarState();
    var vClose;
    var vHigh;
    var vLow;
    var i;
    var volatility = 0.0;
    var sumHL = 0.0;
    var ratio;
    var ssc;
    var constant;

    if(nBarState == BARSTATE_ALLBARS) {
    // reset!
    dLastAMA = 0.0;
    dThisAMA = 0.0;
    fc = 2/(nFastPeriod + 1);
    sc = 2/(nSlowPeriod + 1);
    bPrimed = false;
    }
    else if(nBarState == BARSTATE_NEWBAR) {
    dLastAMA = dThisAMA;
    }
    dThisAMA = dLastAMA;
    vClose = getValue(strSource,0,-nLength - 1);
    if(vClose == null)
    return;

    if(bPrimed == false){
    for(i = 0; i < nLength; i++) {
    volatility += vClose[i];
    }
    dLastAMA = volatility / nLength;
    dThisAMA = dLastAMA;
    bPrimed = true;
    }
    else{
    for(i = 0;i < nLength;i++){
    volatility += Math.abs(vClose[i] - vClose[i+1]);
    }
    ratio = Math.abs((vClose[0] - vClose[nLength-1]) / volatility);
    ssc = ratio * (fc - sc) + sc;
    constant = ssc * ssc;
    dThisAMA = dLastAMA + (constant * (vClose[0] - dLastAMA));
    }
    return(dThisAMA);
    }

    Comment


    • #3
      Thanks Alexis for the tip about the global close only tool for efs studies. I forgot to add in my original post that I had already tried that trick for T3 and AMA and found that for all new bars plotted the calcs were in error. The longer the setting is in place the more the calcs deviate from their proper values.

      As I stated in another thread about Calculations on close only, I would like to see a proper global setting for ALL studies to save on CPU time. As for the AMA the lag setting is more critical. Is this a bear to program? I won't be able to get around to tackling Java for a few more weeks.

      Comment


      • #4
        There is a know issue with setComputeOnClose() that may be the cause of the problems you are seeing. eSignal is aware of the issue and I suspect it will be fixed soon.

        Personally, I wouldn't ever set a global set compute of close - some indicators seem to work best when you wait for a complete close of a bar, other seem to work best taking an intrabar signal. But this, of course is just my opinion.
        Garth

        Comment


        • #5
          Hello gspiker:
          Yes I understand what you mean when you say that some indicators work better if plotted on calculate on every tick basis. My suggestion of course to eSignal is that they make any global condition optional ! My preference is to have the option available for all individual studies much in the way Ensign does. I use simple AMA and EMA calcs. and find that lagging these indicators 1 or 2 bars into the future gives the best results. Obviously the last data point has little meaning and with todays very high volume on the ES it's a shame to waste the CPU cycles on calcs. that you're not even using.

          Thanks for your input.

          Comment

          Working...
          X