Announcement

Collapse
No announcement yet.

2005 Mar: The Secret Behind The Filter (MedianAdaptiveFilter.efs)

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

  • 2005 Mar: The Secret Behind The Filter (MedianAdaptiveFilter.efs)

    File Name: MedianAdaptiveFilter.efs

    Description:
    This formula is based on the March 2005 article, The Secret Behind The Filter - What's The Difference, by John F. Ehlers.

    Formula Parameters:
    Thickness: 2
    Color: Red


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

    Download File:
    MedianAdaptiveFilter.efs



    EFS Code:
    PHP Code:
    /*******************************
    Provided By : eSignal (c) Copyright 2005
    Description:  Median-Average Adaptive Filter - by John F. Ehlers

    Version 1.0  1/7/2005

    Notes:
    March 2005 Issue - "The Secret Behind The Filter - What's The Difference?"

    Formula Parameters:                 Defaults:
    Thickness                           2
    Color                               Red
    *******************************/

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Median-Average Adaptive Filter ");
        
    setCursorLabelName("MAAF"0);
        
        
    setShowTitleParameters(false);
        
        
    // Study Parameters
        
    var sp1 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
            
    sp1.setName("Thickness");
            
    sp1.setDefault(2);
        var 
    sp2 = new FunctionParameter("cColor"FunctionParameter.COLOR);
            
    sp2.setName("Color");
            
    sp2.setDefault(Color.red);
    }


    var 
    bEdit true;
    var 
    Price = new Array(4);
    var 
    Smooth = new Array(39);
    var 
    nFilter null;
    var 
    nFilter_1 0;
    var 
    Value2 0;
    var 
    Value2_1 0;
    var 
    nThreshold 0.002

    function main(nThickcColor) {
        if (
    bEdit == true) {
            
    setDefaultBarThickness(nThick);
            
    setDefaultBarFgColor(cColor);
            
    bEdit false;
        }
        
        var 
    nState getBarState();

        if (
    nState == BARSTATE_NEWBAR) {
            
    nFilter_1 nFilter;
            
    Value2_1 Value2;
            
    Price.pop()
            
    Price.unshift((high(0)+low(0))/2)
            
    Smooth.pop();
            
    Smooth.unshift(0);
        }
        
    Price[0] = (high(0)+low(0))/2;
        if (
    Price[3] == null) return;    
        
        
    Smooth[0] = (Price[0] + (Price[1]) + (Price[2]) + Price[3]) / 6;
        if (
    Smooth[38] == null) return;
        
        var 
    Length 39;
        var 
    Value3 .2;
        var 
    alphaValue1;
        while (
    Value3 nThreshold) {
            
    alpha / (Length 1);
            
    Value1 Median(Length);
            
    Value2 alpha*Smooth[0] + (alpha)*Value2_1;
            if (
    Value1 != 0Value3 Math.abs(Value1 Value2) / Value1;
            
    Length Length 2;
            if (
    Length <= 0) break;
        }

        if (
    Length 3Length 3;
        
    alpha / (Length 1);
        
    nFilter = (alpha*Smooth[0] + (alpha)*nFilter_1);    

        return 
    nFilter;
    }

    function 
    Median(Length) {
        var 
    aArray = new Array(Length);
        var 
    nMedian null;
        
        for (var 
    0Lengthi++) {
            
    aArray[i] = Smooth[i];
        }
        
        
    aArray aArray.sort(compareNumbers);
        
        
    nMedian aArray[Math.round((Length-1)/2)];
        return 
    nMedian;
    }

    function 
    compareNumbers(ab) {
       return 
    b

    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