Announcement

Collapse
No announcement yet.

BollingerEMA.efs

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

  • BollingerEMA.efs

    File Name: BollingerEMA.efs

    Description:
    Bollinger study with an exponential moving average basis line and bands at plus and minus 2 standard deviations.

    Formula Parameters:
    nLength: Default is 20
    nStdDev: Default is 2

    Notes:


    Download File:
    BollingerEMA.efs




    EFS Code:
    PHP Code:
    /*********************************
    Provided By : eSignal. (c) Copyright 2003
    *********************************/

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Bollinger Bands (EMA of Basis Line)");
        
    setCursorLabelName("Upper Band"0);
        
    setCursorLabelName("EMA Basis"1);
        
    setCursorLabelName("Lower Band"2);
        
    setDefaultBarFgColor(Color.blue0);    // upper band
        
    setDefaultBarFgColor(Color.red1);     // basis line
        
    setDefaultBarFgColor(Color.blue2);    // lower band
    }

    var 
    vEMA null;
    var 
    vEMA1 null;

    var 
    dPercent 0.0;
    var 
    bPrimed false;

    function 
    EMA(nLengthnClose) {
        var 
    nBarState getBarState();
        var 
    dSum 0.0;
        var 
    dRef;

        if(
    nBarState == BARSTATE_ALLBARS || bPrimed == false) {
            
    dPercent = (2.0 / (nLength 1.0));
            
    bPrimed false;
        }

        if (
    nBarState == BARSTATE_NEWBAR) {
            
    vEMA1 vEMA;
        }

        if(
    bPrimed == false) {
            for(
    0nLengthi++) {
                
    dSum += nClose[i];
            }
            
    bPrimed true;
            return (
    dSum nLength);
        } else {
            return (((
    close() - vEMA1) * dPercent) + vEMA1);
        }
    }

    function 
    main(nLengthnStdDev) {
        if(
    nLength == null || nLength <= 0nLength 20;
        if(
    nStdDev == nullnStdDev 2;

        var 
    vClose getValue("Close"0, -nLength);
        if(
    vClose == null) return;
        
        var 
    sumX 0;
        var 
    sumX2 0;
        for (
    0nLength; ++i) {
            
    sumX += vClose[i];
            
    sumX2 += (vClose[i] * vClose[i])
        }
        var 
    meanX = (sumX/nLength);
        var 
    StdDev Math.sqrt((sumX2/nLength) - (meanX*meanX));

        
    vEMA EMA(nLengthvClose);
        
        var 
    vUpper vEMA + (nStdDev StdDev);
        var 
    vBasis vEMA;
        var 
    vLower vEMA - (nStdDev StdDev);

        return new Array(
    vUppervBasisvLower);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X