Announcement

Collapse
No announcement yet.

Kaufman Moving Average Adaptive (KAMA)

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

  • Kaufman Moving Average Adaptive (KAMA)

    File Name: KAMA.efs

    Description:
    Kaufman Moving Average Adaptive (KAMA)

    Formula Parameters:
    Length: 21
    Price: Close

    Notes:
    Everyone wants a short-term, fast trading trend that works without large
    losses. That combination does not exist. But it is possible to have fast
    trading trends in which one must get in or out of the market quickly, but
    these have the distinct disadvantage of being whipsawed by market noise
    when the market is volatile in a sideways trending market. During these
    periods, the trader is jumping in and out of positions with no profit-making
    trend in sight. In an attempt to overcome the problem of noise and still be
    able to get closer to the actual change of the trend, Kaufman developed an
    indicator that adapts to market movement. This indicator, an adaptive moving
    average (AMA), moves very slowly when markets are moving sideways but moves
    swiftly when the markets also move swiftly, change directions or break out of
    a trading range.


    Download File:
    KAMA.efs



    EFS Code:
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright c eSignal), a division of Interactive Data 
        Corporation. 2008. All rights reserved. This sample eSignal 
        Formula Script (EFS) is for educational purposes only and may be 
        modified and saved under a new file name.  eSignal is not responsible
        for the functionality once modified.  eSignal reserves the right 
        to modify and overwrite this EFS file with each new release.
       

    Description:        
        Kaufman Moving Average Adaptive (KAMA)

    Version:            1.0  09/23/2008

    Notes:
        Everyone wants a short-term, fast trading trend that works without large
        losses. That combination does not exist. But it is possible to have fast
        trading trends in which one must get in or out of the market quickly, but
        these have the distinct disadvantage of being whipsawed by market noise
        when the market is volatile in a sideways trending market. During these
        periods, the trader is jumping in and out of positions with no profit-making
        trend in sight. In an attempt to overcome the problem of noise and still be
        able to get closer to the actual change of the trend, Kaufman developed an
        indicator that adapts to market movement. This indicator, an adaptive moving
        average (AMA), moves very slowly when markets are moving sideways but moves
        swiftly when the markets also move swiftly, change directions or break out of
        a trading range.

    Formula Parameters:                     Default:
        Length                                  21
        Price                                 Close
    **********************************/

    var fpArray = new Array();
    var 
    bInit false;

    function 
    preMain()
    {
        
    setStudyTitle("KAMA");
        
    setCursorLabelName("KAMA"0);
        
    setDefaultBarFgColor(Color.red0);
        
    setPlotType(PLOTTYPE_LINE,0);
        
    setDefaultBarThickness(1,0);
        
    setPriceStudy(true);
        
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(21);
        }

        
    fpArray[x] = new FunctionParameter("Price"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("open"); 
            
    addOption("high");
            
    addOption("low");
            
    addOption("close");
            
    addOption("hl2");
            
    addOption("hlc3");
            
    addOption("ohlc4"); 
            
    setDefault("close"); 
        }
    }

    var 
    xvnoise null;
    var 
    xMyPrice null;
    var 
    xAMA null;

    function 
    main(LengthPrice) {
    var 
    nAMA 0;
        
        if (
    Length == nullLength 21;
        if(
    Price == nullPrice"close";

        if ( 
    bInit == false ) { 
            
    xMyPrice = eval(Price)();
            
    xvnoise efsInternal("Calc_avnoise"xMyPrice);
            
    xAMA efsInternal("Calc_AMA",xvnoisexMyPriceLength);
            
    bInit true
        } 

        
    nAMA xAMA.getValue(0);
            
        return 
    nAMA;

    }

    function 
    Calc_AMA(xvnoisexMyPriceLength){
        var 
    nefratio 1;
        var 
    nAMA 0;
        var 
    nfastend 0.666;
        var 
    nslowend 0.0645;
        var 
    nnoise 0;
        var 
    nsignal 0;
        var 
    nsmooth 0;
        var 
    nAMA_Ref ref(-1);    
        var 
    nBarCount getCurrentBarCount();


        if (
    xMyPrice.getValue(-1) == null) return 0;
        if (
    nAMA_Ref == nullnAMA_Ref 1;

        if(
    nBarCount Length){
            
    nsignal Math.abs(xMyPrice.getValue(0) - xMyPrice.getValue(-Length));
            for(var 
    0Lengthi++)
                
    nnoise += xvnoise.getValue(-i);
            if(
    nnoise != 0)
                
    nefratio nsignal nnoise;
        } 
        
        
    nsmooth Math.pow(nefratio * (nfastend nslowend) + nslowend2); 

        if(
    nBarCount Length){
            
    nAMA nAMA_Ref nsmooth * (xMyPrice.getValue(0) - nAMA_Ref);
        }

        else if (
    nBarCount == Length){
            
    nAMA xMyPrice.getValue(0); 
        } else {
            return;
        }

        
        return 
    nAMA;
    }

    function 
    Calc_avnoise(xMyPrice) {
    var 
    nRes 0;
        
    nRes Math.abs(xMyPrice.getValue(0) - xMyPrice.getValue(-1));
        if (
    nRes == nullnRes 1;
        return 
    nRes;

Working...
X