Announcement

Collapse
No announcement yet.

Woodies LSMA (Least Square Moving Average)

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

  • Woodies LSMA (Least Square Moving Average)

    File Name: Woodies_LSMA.efs

    Description:
    Calculates the Least Square Moving Average (LSMA) based on theories of "Woodie".

    Formula Parameters:
    nLength - Defines the length of the Moving Average. Default is 25.
    nOffset - Defines how offset the MA is. Default is 0.

    Download File:
    Woodie_LSMA.efs



    EFS Code:

    PHP Code:
    /*************************
    Copyright © eSignal, 2003
    **************************
    Description: Calculates the Least Square Moving Average (LSMA)
    based on theories of "Woodie".
    MA Length = 25
    MA Offset = 0
    MA Source = HLC/3

    Version Control:

    1.1 -- Corrected bug that didn't offset the LSMA properly.
    1.2 -- Offset problem corrected.

    */



    function preMain()
    {
        
    setPriceStudy(true);    
        
    setStudyTitle("Woodies LSMA");
        
    setCursorLabelName("LSMA");
        
    setDefaultBarThickness(2);
    }

    var 
    vPrice null;

    var 
    vInit false;

    var 
    LSMA_Array = new Array();

    function 
    main(nLength,nOffset)
    {
        if (
    nLength == nullnLength 25;
        if (
    nOffset == null) {
            
    nOffset 0;
        } else {
            
    nOffset Math.abs(Math.round(nOffset));
        }

        if (
    vInit == false) {
            
    vPrice = new Array(nLength);       
            
    vInit true;
        }
        
        
    vClose close();
        
    vHigh high();
        
    vLow low();
        
        if (
    vClose == null) return;
        if (
    vHigh == null) return;
        if (
    vLow == null) return;
        
        if (
    getBarState() == BARSTATE_NEWBAR) {
            if (
    vPrice[nLength-1] != nullvPrice.pop();
            
    vPrice.unshift(vHLC3);
        }
        
    vHLC3 = (vClose vHigh vLow) / 3;  
        
    vPrice[0] = vHLC3;
        
        if (
    vPrice[nLength-1] == null) return;
        
        var 
    Num1 0.0;
        var 
    Num2 0.0;
        var 
    SumBars nLength * (nLength 1) * 0.5;
        var 
    SumSqrBars = (nLength 1) * nLength * (nLength 1) / 6;
        var 
    SumY 0.0;
        var 
    Sum1 0.0;
        var 
    Sum2 0.0;
        var 
    Slope 0.0;
        var 
    Intercept 0.0;

        for (
    0nLengthi++)
        {
            
    SumY += vPrice[i];
            
    Sum1 += vPrice[i];
        }
        
    Sum2 SumBars SumY;
        
    Num1 nLength Sum1 Sum2;
        
    Num2 SumBars SumBars nLength SumSqrBars;
        if (
    Num2 != 0Slope Num1 Num2;
        
    Intercept = (SumY Slope SumBars) / nLength;
        var 
    LinearRegValue Intercept Slope * (nLength 1);
        
        if (
    getBarState() == BARSTATE_NEWBAR) {
            if (
    LSMA_Array[nLength-1] != nullLSMA_Array.pop(); // v1.2
            
    LSMA_Array.unshift(LinearRegValue);
        }
        
        
    LSMA_Array[0] = LinearRegValue;
        
        
    /*   *** Possible offset bug ***
        if (nOffset > 0) {
            return LSMA_Array[nOffset-1];
        } else {
            return LinearRegValue;
        } */
        
        
    return LSMA_Array[nOffset]; // v1.2

    Regards,
    Jay F.
    Product Manager
    _____________________________________
    Have a suggestion to improve our products?
    Click Support --> Request a Feature in eSignal 11
Working...
X