Announcement

Collapse
No announcement yet.

Woodie's LSMA HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Woodie's LSMA HELP

    Whenever I have Woodie's Least Square Moving Average on a chart, and try to change time periods, or ticker symbols, it locks up the system from 45 seconds to ten minutes!

    Being a moron when it comes to any kind of programming, I am unable to spot any obvious problem with the script.

    Any help?

    *************************
    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
    */



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

    var vPrice = null;

    var vInit = false;

    function main(nLength,nOffset)
    {
    if (nLength == null) nLength = 25;
    if (nOffset == null) nOffset = 0;

    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) {
    vPrice.pop();
    vPrice.unshift(vHLC3);
    }
    vHLC3 = (vClose + vHigh + vLow) / 3;
    vPrice[0] = vHLC3;

    if (vPrice[nLength-1] == null) return;
    debugPrintln(vPrice[nLength-1]);

    //debugPrintln ("sadfs");

    var Num1 = 0.0;
    var Num2 = 0.0;
    var SumBars = nLength * (nLength - 1) * 0.5;
    var SumSqrBars = (nLength - 1) * nLength * (2 * nLength - 1) / 6;
    var SumY = 0.0;
    var Sum1 = 0.0;
    var Sum2 = 0.0;
    var Slope = 0.0;
    var Intercept = 0.0;
    var i = 0;
    for (i = 0; i < nLength; i++)
    {
    if(getCurrentBarIndex() > -5 && getCurrentBarIndex() != 0) debugPrintln(vPrice[i]);
    SumY += vPrice[i];
    Sum1 += i * vPrice[i];
    }
    Sum2 = SumBars * SumY;
    Num1 = nLength * Sum1 - Sum2;
    Num2 = SumBars * SumBars - nLength * SumSqrBars;
    if (Num2 != 0) Slope = Num1 / Num2;
    Intercept = (SumY - Slope * SumBars) / nLength;
    var LinearRegValue = Intercept + Slope * (nLength - 1 - nOffset);
    return LinearRegValue;
    }

  • #2
    Hello Lassiter,

    Remove all of the debugPrintln() statements. That will dramatically improve performance, as one of them is inside the for loop. You can download an updated version from the EFS Library.

    Woodies LSMA
    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

    Comment


    • #3
      LSMA on CLose

      I'm looking for an LSMA that is based on close only. I'm not a coder, can anyone help? Thanks in advance

      Comment


      • #4
        smg
        The attached efs is the same as the one available at the link posted in a prior message in this thread and modified to use the Close only instead of HLC/3. The only change implemented is in line 59 of the script.
        Alex
        Attached Files

        Comment


        • #5
          Thanks Alexis!

          Comment


          • #6
            smg
            You are most welcome
            Alex

            Comment

            Working...
            X