Announcement

Collapse
No announcement yet.

Woodies LSMA

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

  • Woodies LSMA

    These are some of the changes have been made to the Woodies original lsma efs file. Somehow, it is giving an error message now. Can someone fix this problem. Much appreciated:


    *************************
    Description: Calculates the Least Square Moving Average (LSMA)
    based on theories of "Woodie".
    MA Length = 25
    MA Source = HLC/3

    */

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

    var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
    fp1.setName("LSMA Length");
    fp1.setDefault(25);

    var fp2 = new FunctionParameter("ColorDn", FunctionParameter.COLOR);
    fp2.setName("Down Color");
    fp2.setDefault(Color.red);

    var fp3 = new FunctionParameter("ColorUp", FunctionParameter.COLOR);
    fp3.setName("Up Color");
    fp3.setDefault(Color.olivegreen);
    }

    var vPrice = null;
    var vInit = false;
    var LSMA_Array = new Array();
    var SumBars = 0;
    var SumSqrBars = 0;
    var Slope = 0.0;

    function main(nLength,ColorUp,ColorDn)
    {
    if (nLength == null) nLength = 25;

    if (vInit == false) {
    vPrice = new Array(nLength);
    vInit = true;
    SumBars = nLength * (nLength - 1) * 0.5;
    SumSqrBars = (nLength - 1) * nLength * (2 * nLength - 1) / 6;
    }

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

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

    var SumY = 0.0;
    var Sum1 = 0.0;
    for (i = 0; i < nLength; i++)
    {
    SumY += vPrice[i];
    Sum1 += i * vPrice[i];
    }
    var Sum2 = SumBars * SumY;
    var Num1 = nLength * Sum1 - Sum2;
    var Num2 = SumBars * SumBars - nLength * SumSqrBars;
    if (Num2 != 0) Slope = Num1 / Num2;
    var Intercept = (SumY - Slope * SumBars) / nLength;
    if (getBarState() == BARSTATE_NEWBAR) {
    if (LSMA_Array[nLength-1] != null) LSMA_Array.pop();
    LSMA_Array.unshift(0);
    }
    LSMA_Array[0] = Intercept + Slope * (nLength - 1);

    if (LSMA_Array[0] > LSMA_Array[1]) setBarFgColor(ColorUp,0);
    else setBarFgColor(ColorDn,0);

    return LSMA_Array[0];
    }

  • #2
    bandraguy
    Replace olivegreen with olive in this section of the efs

    var fp3 = new FunctionParameter("ColorUp", FunctionParameter.COLOR);
    fp3.setName("Up Color");
    fp3.setDefault(Color.olivegreen);
    }

    Alex

    Comment

    Working...
    X