Announcement

Collapse
No announcement yet.

2010 Nov: Zero Lag (Well, Almost) Indicator by John Ehlers and Ric Way

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

  • 2010 Nov: Zero Lag (Well, Almost) Indicator by John Ehlers and Ric Way

    File Name: ZeroLag_EC.efs, ZeroLag_EC_Strategy.efs

    Description:
    Zero Lag (Well, Almost) Indicator and Strategy by John Ehlers and Ric Way

    Formula Parameters:
    ZeroLag_EC.efs
    Length 20
    Gain Limit 50

    ZeroLag_EC_Strategy.efs
    Length 20
    Gain Limit 50
    Thresh 1

    Notes:
    The related article is copyrighted material.
    If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

    Download File:
    ZeroLag_EC.efs
    ZeroLag_EC_Strategy.efs

    ZeroLag_EC.efs

    ZeroLag_EC_Strategy.efs


    EFS Code: (ZeroLag_EC.efs)

    PHP Code:
    /*********************************
    Provided By:                                                      
        Interactive Data Corporation (Copyright © eSignal) 2010.      
        All rights reserved. This sample eSignal Formula Script (EFS) 
        is for educational purposes only. Interactive Data Corporation
        reserves the right to modify and overwrite this EFS file with 
        each new release.                                             

    Description:        
        Zero Lag (Well, Almost) Indicator by John Ehlers and Ric Way
    Version:            1.0  13/09/2010
     
    Formula Parameters:                     Default:
        Length                              20
        Gain Limit                          50
        
    Notes:
        The related article is copyrighted material. If you are not
        a subscriber of Stocks & Commodities, please visit [url]www.traders.com.[/url]
    **********************************/

    var fpArray = new Array();
    var 
    bVersion null;

    function 
    preMain()
    {
        
    setPriceStudy(true);
        
    setStudyTitle("zeroLag_EC");
        
    setCursorLabelName("zeroLag_EMA"0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(20);
        
    setPlotType(PLOTTYPE_LINE0);
        
    setCursorLabelName("zeroLag_EC"1);
        
    setDefaultBarStyle(PS_SOLID1);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarThickness(21);
        
    setPlotType(PLOTTYPE_LINE1);
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("gLength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Length");
            
    setLowerLimit(1);        
            
    setDefault(20);
        }
        
    fpArray[x] = new FunctionParameter("gGainLimit"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Gain Limit");
            
    setLowerLimit(1);        
            
    setDefault(50);
        }
    }

    var 
    bMainInit false
    var 
    xEMA null;
    var 
    xEC null;
    var 
    nAlpha 0;

    function 
    main(gLengthgGainLimit)
    {
        var 
    nGain 0;
        var 
    nBestGain 0;
        var 
    nError 0;
        var 
    nLeastError 1000000;
     
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;   
        var 
    nBarState getBarState();
        if (
    nBarState == BARSTATE_ALLBARS) {
            if (
    gLength == nullgLength 20;
            if (
    gGainLimit == nullgGainLimit 50;
            
    nAlpha 2/(gLength+1);
        }    
        if (!
    bMainInit)
        {
            
    xEMA efsInternal("calcEMA",nAlpha);
            
    xEC efsInternal("calcEC",nAlpha,gGainLimit,xEMA);
        }

        var 
    nEMA xEMA.getValue(0);
        var 
    nEC xEC.getValue(0);
        if( 
    nEMA == null || nEC == null) return ;

        return new Array( 
    nEMAnEC) ;
    }

    function 
    calcEMA(nAlpha)
    {
        if (
    getCurrentBarCount()==1) var nRefEMA close(0
        else  var 
    nRefEMA ref(-1);
        var 
    vEMA nAlpha*close(0)+(1-nAlpha)*nRefEMA;
        return 
    vEMA;
    }

    var 
    nBestGain 0;

    function 
    calcEC(nAlpha,nGaintLimitxEMA)
    {
        var 
    nLeastError 1000000;
        if (
    getCurrentBarCount()==1) var nRefEC close(0
        else var 
    nRefEC ref(-1);

        var 
    nClose close(0);
        var 
    vEMA xEMA.getValue(0);
        var 
    nCount 0;
        var 
    nGain 0;
        var 
    nError 0;
        var 
    vEC ;
        for (
    nCount=-nGaintLimitnCount<=nGaintLimitnCount++)
        {
            
    nGain nCount/10;
            
    vEC nAlpha*(vEMA+nGain*(nClose-nRefEC))+(1-nAlpha)*nRefEC;
            
    nError nClose vEC;
            if (
    Math.abs(nError)<nLeastError)
            {
                
    nLeastError Math.abs(nError);
                
    nBestGain nGain;
            }
        }
        
    vEC nAlpha * (vEMA nBestGain*(nClose nRefEC))+(1-nAlpha)*nRefEC;
      
        return 
    vEC;
    }

    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 779) {
            
    drawTextAbsolute(535"This study requires version 8.0 or later."
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"error");
            
    drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"upgrade");
            return 
    b;
        } else {
            
    true;
        }
        return 
    b;

    EFS Code: (ZeroLag_EC_Strategy.efs)

    PHP Code:
    /*********************************
    Provided By:                                                      
        Interactive Data Corporation (Copyright © eSignal) 2010.      
        All rights reserved. This sample eSignal Formula Script (EFS) 
        is for educational purposes only. Interactive Data Corporation
        reserves the right to modify and overwrite this EFS file with 
        each new release.                                             

    Description:        
        Zero Lag (Well, Almost) Strategy  by John Ehlers and Ric Way
    Version:            1.0  13/09/2010
     
    Formula Parameters:                     Default:
        Length                              20
        Gain Limit                          50
        Thresh                               1
        
    Notes:
        The related article is copyrighted material. If you are not
        a subscriber of Stocks & Commodities, please visit [url]www.traders.com.[/url]
    **********************************/

    var fpArray = new Array();
    var 
    bVersion null;

    function 
    preMain()
    {
        
    setPriceStudy(true);
        
    setStudyTitle("zeroLag_EC_Strategy");
        
    setColorPriceBars(false);
        
    setCursorLabelName("zeroLag_EMA"0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(20);
        
    setPlotType(PLOTTYPE_LINE0);
        
    setCursorLabelName("zeroLag_EC"1);
        
    setDefaultBarStyle(PS_SOLID1);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarThickness(21);
        
    setPlotType(PLOTTYPE_LINE1);
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("gLength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Length");
            
    setLowerLimit(1);        
            
    setDefault(20);
        }
        
    fpArray[x] = new FunctionParameter("gGainLimit"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Gain Limit");
            
    setLowerLimit(1);        
            
    setDefault(50);
        }
        
    fpArray[x] = new FunctionParameter("gThresh"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Thresh");
            
    setLowerLimit(1);        
            
    setDefault(1);
        }
    }

    var 
    bMainInit false
    var 
    xEMA null;
    var 
    xEC null;
    var 
    nAlpha 0;
    var 
    bBuy false;
    var 
    bSell false;

    function 
    main(gLengthgGainLimitgThresh)
    {
        var 
    nGain 0;
        var 
    nBestGain 0;
        var 
    nError 0;
        var 
    nLeastError 1000000;
     
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;   
        var 
    nBarState getBarState();
        var 
    nBarCount getCurrentBarCount();
        if (
    nBarState == BARSTATE_ALLBARS) {
            if (
    gLength == nullgLength 20;
            if (
    gGainLimit == nullgGainLimit 50;
            if (
    gThresh == nullgThresh 1;
            
    nAlpha 2/(gLength+1);
        }    
        if (!
    bMainInit)
        {
            
    xEMA efsInternal("calcEMA",nAlpha);
            
    xEC efsInternal("calcEC",nAlpha,gGainLimit,xEMA);
        }

        var 
    nEMA xEMA.getValue(0);
        var 
    nEC xEC.getValue(0);
        if( 
    nEMA == null || nEC == null) return ;
        if (
    getCurrentBarIndex() == 0) return;
        
        var 
    vEMA1 xEMA.getValue(-1);
        var 
    vEMA2 xEMA.getValue(-2);
        var 
    vEC1 xEC.getValue(-1);
        var 
    vEC2 xEC.getValue(-2);    
        var 
    nClose close(-1);
        if (
    vEC2 == null || vEMA2 == null) return;
       
        if (
    vEC2 vEMA2 && vEC1 vEMA1 && 100*nLeastError/nClose gThresh
        {
            
    drawTextRelative(0TopRow1" LONG "Color.whiteColor.green
            
    Text.PRESET|Text.CENTER|Text.FRAME"Arial Black"10"b"+(nBarCount));
            if(!
    Strategy.isLong()) Strategy.doLong("Entry Long"Strategy.MARKETStrategy.THISBAR);
        }
        if (
    vEC2 vEMA2 && vEC1 vEMA1 && 100*nLeastError/nClose gThresh)
        {
            
    drawTextRelative(0TopRow1+1,  " SHORT "Color.whiteColor.red
            
    Text.PRESET|Text.CENTER|Text.FRAME"Arial Black"10"b"+(getCurrentBarCount())); 
            if(!
    Strategy.isShort()) Strategy.doShort("Entry Short"Strategy.MARKETStrategy.THISBAR);
        }
        if(
    Strategy.isLong()) setBarBgColor(Color.lime);
        if(
    Strategy.isShort()) setBarBgColor(Color.yellow);
            
        return new Array( 
    nEMAnEC) ;
    }

    function 
    calcEMA(nAlpha)
    {
        if (
    getCurrentBarCount()==1) var nRefEMA close(0
        else  var 
    nRefEMA ref(-1);
        var 
    vEMA nAlpha*close(0)+(1-nAlpha)*nRefEMA;
        return 
    vEMA;
    }

    var 
    nBestGain 0;
    function 
    calcEC(nAlpha,nGaintLimitxEMA)
    {
        var 
    nLeastError 1000000;
        if (
    getCurrentBarCount()==1) var nRefEC close(0
        else var 
    nRefEC ref(-1);

        var 
    nClose close(0);
        var 
    vEMA xEMA.getValue(0);
        var 
    nCount 0;
        var 
    nGain 0;
        var 
    nError 0;
        var 
    vEC ;
        for (
    nCount=-nGaintLimitnCount<=nGaintLimitnCount++)
        {
            
    nGain nCount/10;
            
    vEC nAlpha*(vEMA+nGain*(nClose-nRefEC))+(1-nAlpha)*nRefEC;
            
    nError nClose vEC;
            if (
    Math.abs(nError)<nLeastError)
            {
                
    nLeastError Math.abs(nError);
                
    nBestGain nGain;
            }
        }
        
    vEC nAlpha * (vEMA nBestGain*(nClose nRefEC))+(1-nAlpha)*nRefEC;
      
        return 
    vEC;
    }

    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 779) {
            
    drawTextAbsolute(535"This study requires version 8.0 or later."
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"error");
            
    drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"upgrade");
            return 
    b;
        } else {
            
    true;
        }
        return 
    b;

    Last edited by eSignal; 10-15-2010, 05:31 AM.
Working...
X