Announcement

Collapse
No announcement yet.

Zerolag ema

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Zerolag ema

    I really like the zero lag ema and I'm trying to use it with some condition statements, but it doesn't follow the conditions. It just seems to randomly plot. I wrote a simple conditional statement to setBarBgcolor if the high(-3) < the zerolag && the current bar low(0) > the zerolag, but as I said, it seems to just plot randomly. Could someone take a look at this and tell me what I need to do, or point me in the right direction. Thanks!

    /*********************************
    Provided By:
    eSignal (Copyright © eSignal), a division of Interactive Data
    Corporation. 2007. All rights reserved. This sample eSignal
    Formula Script (EFS) is for educational purposes only and may be
    modified and saved under a new file name. eSignal is not responsible
    for the functionality once modified. eSignal reserves the right
    to modify and overwrite this EFS file with each new release.

    Description: Trading Divergences
    by Sylvain Vervoort

    Version: 1.0 12/7/2007

    Notes:
    * February 2008 Issue of Stocks and Commodities Magazine
    * Study requires version 8.0 or later.

    Formula Parameters: Defaults:
    Periods 20
    **********************************/


    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Zero Lag EMA test");
    setCursorLabelName("ZEMA", 0);
    setDefaultBarFgColor(Color.white, 0);
    setDefaultBarThickness(2, 0);

    var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(13);
    }

    // Global Variables
    var bVersion = null; // Version flag
    var bInit = false; // Initialization flag

    var xEma1 = null;
    var xEma2 = null;

    function main(nPeriods) {
    var nState = getBarState();
    var nIndex = getCurrentBarIndex();
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;


    if (bInit == false) {
    xEma1 = ema(nPeriods);
    xEma2 = ema(nPeriods, xEma1);
    bInit = true;
    }

    var nZEma = null;
    var nEma1 = xEma1.getValue(0);
    var nEma2 = xEma2.getValue(0);
    if (nEma1 == null || nEma2 == null) return;

    nZEma = nEma1 + (nEma1 - nEma2);

    if(high(-3) < nZEma &&
    low(0) > nZEma) {
    setBarBgColor(Color.RGB(123,103,0));
    }



    return nZEma;
    }


    function verify() {
    var b = false;
    if (getBuildNumber() < 779) {
    drawTextAbsolute(5, 35, "This study requires version 8.0 or later.",
    Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOL D|Text.LEFT,
    null, 13, "error");
    drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp",
    Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOL D|Text.LEFT,
    null, 13, "upgrade");
    return b;
    } else {
    b = true;
    }

    return b;
    }

  • #2
    Re: Zerolag ema

    opstock
    As far as I can see it is actually following the conditions ie it colors the background of the current bar if the high of three bars ago is less than the current value of the zerolag ma and if the low of the current bar is greater than the current value of the zerolag ma
    Perhaps you want the high of three bars ago to be below the zerolag ma of three bars ago.
    In that case you could use the ref() function to retrieve the value of the zerolag ma of three bars ago and then use that in your condition.
    For the description and syntax of the ref() function see this article in the EFS KnowledgeBase. You can also find a practical example of the use of the ref() function in this article also in the EFS KnowledgeBase
    Alex


    Originally posted by opstock
    I really like the zero lag ema and I'm trying to use it with some condition statements, but it doesn't follow the conditions. It just seems to randomly plot. I wrote a simple conditional statement to setBarBgcolor if the high(-3) < the zerolag && the current bar low(0) > the zerolag, but as I said, it seems to just plot randomly. Could someone take a look at this and tell me what I need to do, or point me in the right direction. Thanks!

    /*********************************
    Provided By:
    eSignal (Copyright © eSignal), a division of Interactive Data
    Corporation. 2007. All rights reserved. This sample eSignal
    Formula Script (EFS) is for educational purposes only and may be
    modified and saved under a new file name. eSignal is not responsible
    for the functionality once modified. eSignal reserves the right
    to modify and overwrite this EFS file with each new release.

    Description: Trading Divergences
    by Sylvain Vervoort

    Version: 1.0 12/7/2007

    Notes:
    * February 2008 Issue of Stocks and Commodities Magazine
    * Study requires version 8.0 or later.

    Formula Parameters: Defaults:
    Periods 20
    **********************************/


    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Zero Lag EMA test");
    setCursorLabelName("ZEMA", 0);
    setDefaultBarFgColor(Color.white, 0);
    setDefaultBarThickness(2, 0);

    var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(13);
    }

    // Global Variables
    var bVersion = null; // Version flag
    var bInit = false; // Initialization flag

    var xEma1 = null;
    var xEma2 = null;

    function main(nPeriods) {
    var nState = getBarState();
    var nIndex = getCurrentBarIndex();
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;


    if (bInit == false) {
    xEma1 = ema(nPeriods);
    xEma2 = ema(nPeriods, xEma1);
    bInit = true;
    }

    var nZEma = null;
    var nEma1 = xEma1.getValue(0);
    var nEma2 = xEma2.getValue(0);
    if (nEma1 == null || nEma2 == null) return;

    nZEma = nEma1 + (nEma1 - nEma2);

    if(high(-3) < nZEma &&
    low(0) > nZEma) {
    setBarBgColor(Color.RGB(123,103,0));
    }



    return nZEma;
    }


    function verify() {
    var b = false;
    if (getBuildNumber() < 779) {
    drawTextAbsolute(5, 35, "This study requires version 8.0 or later.",
    Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOL D|Text.LEFT,
    null, 13, "error");
    drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp",
    Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOL D|Text.LEFT,
    null, 13, "upgrade");
    return b;
    } else {
    b = true;
    }

    return b;
    }

    Comment


    • #3
      Oh my! I'm such an idiot. I forgot to put in -3 for the nZEma, duh!. Thanks for the quick response Alex.

      Comment


      • #4
        opstock
        Using -3 as is will not work because the variable nZEma is not a series [hence it does not contain historical values] which is why I said you will need to retrieve the value of the zerolag ma of three bars ago using the ref() function
        Alex


        Originally posted by opstock
        Oh my! I'm such an idiot. I forgot to put in -3 for the nZEma, duh!. Thanks for the quick response Alex.

        Comment


        • #5
          Yes, thanks so much Alex. I figured it out using the references you gave me and it works perfectly.

          Comment


          • #6
            opstock
            You are most welcome
            Alex


            Originally posted by opstock
            Yes, thanks so much Alex. I figured it out using the references you gave me and it works perfectly.

            Comment

            Working...
            X