Announcement

Collapse
No announcement yet.

EMAcalc.efs

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

  • EMAcalc.efs

    File Name: EMAcalc.efs

    Description:
    Demonstrates how to create an exponential moving average calculation in EFS.

    Formula Parameters:
    nLength: Default is 10

    Notes:
    Default settings draw a 10 period exponential moving average of the Close.

    Download File:
    EMAcalc.efs




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

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("EMA calculation");
        
    setCursorLabelName("EMA of Close"0);
        
    setDefaultBarFgColor(Color.lime0); 
    }

    var 
    vEMA null;
    var 
    vEMA1 null;

    var 
    dPercent 0.0;
    var 
    bPrimed false;

    function 
    EMA(nLengthnArray) {
        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 += nArray[i];
            }
            
    bPrimed true;
            return (
    dSum nLength);
        } else {
            return (((
    close() - vEMA1) * dPercent) + vEMA1);
        }
    }

    function 
    main(nLength) {
        if(
    nLength == null || nLength <= 0nLength 10;

        var 
    nArray getValue("Close"0, -nLength);
        if(
    nArray == null) return;
        
        
    vEMA EMA(nLengthnArray);
        
        return 
    vEMA;

    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