Announcement

Collapse
No announcement yet.

1999 Jun: Sine-Weighted Moving Average, by Patrick Lafferty

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

  • 1999 Jun: Sine-Weighted Moving Average, by Patrick Lafferty

    File Name: MovAvgSine_Weightd.efs

    Description:
    Mov Avg Sine-Weightd

    Formula Parameters:
    Length : 5
    Thickness : 2
    Line Color : Green
    Display Cursor Labels : True


    Notes:
    Mov Avg Sine-Weightd Indicator
    Patrick Lafferty's article How Smooth Is Your Data Smoother? Uses
    the sine calculation to create a smoothed moving average. The basis
    of the sine-weighted moving average is calculated using the sine
    function in EFS.
    The related article is copyrighted material. If you are not
    a subscriber of Stocks & Commodities, please visit www.traders.com.


    Download File:
    MovAvgSine_Weightd.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:        
        Mov Avg Sine-Weightd

    Version:            1.0  01/14/2009

    Formula Parameters:                     Default:
        Length                              5
        Thickness                           2
        Line Color                          Green
        Display Cursor Labels               True

    Notes: 
        Mov Avg Sine-Weightd Indicator
        Patrick Lafferty's article How Smooth Is Your Data Smoother? Uses
        the sine calculation to create a smoothed moving average. The basis
        of the sine-weighted moving average is calculated using the sine
        function in EFS. 
        The related article is copyrighted material. If you are not
        a subscriber of Stocks & Commodities, please visit [url]www.traders.com.[/url]

    **********************************/

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

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setShowCursorLabel(false);
        
    setShowTitleParametersfalse );
        
    setStudyTitle("Mov Avg Sine-Weightd");
        
    setCursorLabelName("Sine-Weightd"0);
        
    setDefaultBarFgColor(Color.green0);
        
    setPlotType(PLOTTYPE_LINE0); 
        
    setDefaultBarThickness(10);
       
        
    askForInput();
        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("LineColor"FunctionParameter.COLOR);
        
    with(fpArray[x++]){
            
    setName("Color line");
            
    setDefault(Color.green);
        }    

        
    fpArray[x] = new FunctionParameter("ViewValue"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Display Title Value");
            
    setDefault(true);
        }    
        
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Length");
            
    setLowerLimit(1);        
            
    setDefault(5);
        }

        
    fpArray[x] = new FunctionParameter("Thickness"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Thickness line");
            
    setLowerLimit(1);        
            
    setDefault(2);
        }
    }

    var 
    xSWMA null;

    function 
    main(LengthLineColorThicknessViewValue) {
    var 
    SWMA 0;
        if ( 
    bInit == false ) { 
            
    setDefaultBarFgColor(LineColor0);
            
    setDefaultBarThickness(Thickness0);
            
    setShowCursorLabel(ViewValue);
            
    xSWMA efsInternal("Calc_SWMA"Length);
            
    bInit true
        } 

        
    SWMA xSWMA.getValue(0);
        if (
    SWMA == null) return;
        return 
    SWMA
    }

    function 
    Calc_SWMA(Length){
    var 
    nRes 0;
    var 
    Numerator 0;
    var 
    Denominator 0;
    var 
    Factor 180 6;
    var 
    pi 3.1415926;

        if (
    getCurrentBarCount() < Length) return;
        for (var 
    0<= Lengthi++) {
            
    Numerator += Math.sin(pi * (Factor) / 180) * close(-(Length-i)); 
            
    Denominator += Math.sin(pi * (Factor) / 180);
        }
        if (
    Denominator != ) {
            
    nRes Numerator Denominator;
        }
        if (
    nRes == null) return;
        return 
    nRes;

Working...
X