Announcement

Collapse
No announcement yet.

McClellanOsc2.efs

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

  • McClellanOsc2.efs

    File Name: McClellanOsc2.efs

    Description:
    McClellan Oscillator with user defined options for displaying the indictor as a cumulative summation index. The moving average calculation can be set to use simple or exponential. The oscillator is colored green when the slope of the oscillator is positive and red when negative. The plot type can be set to “Line” or “Histogram.”

    Formula Parameters:
    MA Type: Exponential [Exponential, Simple]
    Summation: On [On, Off]
    Positive Slope: Green
    Negative Slope: Red
    Plot Type: Histogram [Line, Histogram]

    Notes:


    Download File:
    McClellanOsc2.efs




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

    function preMain() {
        
    setStudyTitle("McClellan Oscillator2 "); 
        
    setCursorLabelName("McClellan Osc");
        
    addBand(0PS_SOLID1Color.black"zero");
        
        var 
    fp1 = new FunctionParameter("nMAType"FunctionParameter.STRING);
        
    fp1.setName("MA Type");
        
    fp1.addOption("Simple");
        
    fp1.addOption("Exponential");
        
    fp1.setDefault("Simple");
        
        var 
    fp2 = new FunctionParameter("bSum"FunctionParameter.STRING);
        
    fp2.setName("Summation");
        
    fp2.addOption("On");
        
    fp2.addOption("Off");
        
    fp2.setDefault("On");

        var 
    fp3 = new FunctionParameter("cPos"FunctionParameter.COLOR);
        
    fp3.setName("Positive Slope");
        
    fp3.setDefault(Color.green);

        var 
    fp4 = new FunctionParameter("cNeg"FunctionParameter.COLOR);
        
    fp4.setName("Negative Slope");
        
    fp4.setDefault(Color.red);

        var 
    fp5 = new FunctionParameter("sType"FunctionParameter.STRING);
        
    fp5.setName("Plot Type");
        
    fp5.addOption("Line");
        
    fp5.addOption("Histogram");
        
    fp5.setDefault("Histogram");
    }

    var 
    vOsc null;
    var 
    vOsc_ret 0;
    var 
    vOsc_ret1 null;
    var 
    vADD null;
    var 
    aADD = new Array(39);
    var 
    bEdit true;

    function 
    main(nMATypebSumcPoscNegsType) {
        var 
    nState getBarState();
        
        if (
    bEdit == true) {
            if (
    bSum == "On") {
                
    setCursorLabelName("McClellan Osc");
            } else if (
    bSum == "Off") {
                
    setCursorLabelName("McClellan Sum");
            }
            if (
    sType == "Line"setPlotType(PLOTTYPE_LINE);
            if (
    sType == "Histogram"setPlotType(PLOTTYPE_HISTOGRAM);
            
    bEdit false;
        }
        
        if (
    nState == BARSTATE_NEWBAR && vADD != null) {
            
    aADD.pop();
            
    aADD.unshift(vADD);
            
    vOsc_ret1 vOsc_ret;
        }
        
        
    vADD open(01"$ADD");
        if (
    vADD == null) return;
        
    aADD[0] = vADD[0];
        
        if (
    aADD[38] == null) return;
        
        if(
    nMAType == "Simple") {
            var 
    sum 0;
            var 
    0;
            var 
    0;
            for(
    039i++) {
                
    sum += aADD[i];
                if(
    19+= aADD[i];
            }
            
    vOsc = (19) - (sum 39);
        } else if (
    nMAType == "Exponential") {
            
    vEMA[0] = EMA(190);
            
    vEMA[1] = EMA(391);
            
    vOsc vEMA[0] - vEMA[1];
        }
        
        if (
    bSum == "On") {
            
    vOsc_ret vOsc_ret1 vOsc;
        } else if (
    bSum == "Off") {
            
    vOsc_ret vOsc;
        }
     
        if(
    vOsc_ret vOsc_ret1setBarFgColor(cPos);
        if(
    vOsc_ret<vOsc_ret1setBarFgColor(cNeg);
        
        return 
    vOsc_ret;
    }


    //0 = s, 1 = sum
    var vEMA = new Array(2);
    var 
    vEMA1 = new Array(2);

    var 
    dPercent = new Array(2)
    dPercent[0] = null;
    dPercent[1] = null;

    var 
    bPrimed = new Array(2);
    bPrimed[0] = false;
    bPrimed[1] = false;

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

        if(
    dPercent[nNum] == null) {
            
    dPercent[nNum] = (2.0 / (nLength 1.0));
            
    bPrimed[nNum] = false;
        }

        if (
    nBarState == BARSTATE_NEWBAR) {
            
    vEMA1[nNum] = vEMA[nNum];
        }

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

    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