Announcement

Collapse
No announcement yet.

LinearRegressionIndicator.efs

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

  • LinearRegressionIndicator.efs

    File Name: LinearRegressionIndicator.efs

    Description:
    Plots the Linear Regression Indicator of the close, which is also referred to as moving linear regression.

    Formula Parameters:
    Periods: 20


    Notes:
    NA


    Download File:
    LinearRegressionIndicator.efs



    EFS Code:
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright © eSignal), a division of Interactive Data 
        Corporation. 2007. 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:  Linear Regression Indicator

    Parameters:                     Default:
        Periods                     20
    **********************************/

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Linear Regression Indicator");
        
    setCursorLabelName("LR"0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(20);
        
        var 
    fp1 = new FunctionParameter("nLength"FunctionParameter.NUMBER);
            
    fp1.setName("Periods");
            
    fp1.setLowerLimit(1);
            
    fp1.setDefault(20);
    }


    var 
    bInit false;
    var 
    xLR   null;

    function 
    main(nLength) {
        if (
    bInit == false) {
            
    xLR efsInternal("calcLR"nLength);
            
    bInit true;
        }
        
        
        var 
    nLR xLR.getValue(0);
        
        return 
    nLR;
    }


    function 
    calcLR(nLen) {
        
        
    // y = Ax + B;
        // A = SUM( (x-xAVG)*(y-yAVG) ) / SUM( (x-xAVG)^2 )
        // A = slope
        // B = yAVG - (A*xAVG);
        
        
    if (close(-(nLen-1)) != null) {
            var 
    xSum 0;
            var 
    ySum 0;
            var 
    0;
            for (
    0nLeni++) {
                
    xSum += i;
                
    ySum += close(-i);
            }
            var 
    xAvg xSum/nLen;
            var 
    yAvg ySum/nLen;
            var 
    aSum1 0;
            var 
    aSum2 0;
            
    0;
            for (
    0nLeni++) {
                
    aSum1 += (i-xAvg) * (close(-i)-yAvg); 
                
    aSum2 += (i-xAvg)*(i-xAvg);
            }
            var 
    = (aSum1 aSum2);
            var 
    yAvg - (A*xAvg);
        }
        
        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