Announcement

Collapse
No announcement yet.

LS of Close()-LS

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

  • LS of Close()-LS

    1. - MADPsq
    2. - Non-price Study
    3. - Regular Study (Indicator)
    4. - The code below returns the value of Close()-Least Squared called "eek".

    I would like the study to return the least squared value of eek (n periods), in other words, return the least squares of the last n periods of eek. Should seem easy enough, but I'm struggling with creating an elegant solution to the creation of the array of "eek" values ....right now I'm doing a lot of array processing the old-fashioned way, and I'm sucking up a lot of processor time when refreshing the chart. I'm sure there is a more efficient way to do it than what I've been trying.

    function preMain()
    {
    setPriceStudy(false);
    setStudyTitle("MADP (CL-LeastSq) ");
    setCursorLabelName("Madp", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarThickness(3,0);
    addBand(0, PS_DASH, 5, Color.navy);
    }

    function main(n) {
    if(n == null) n = 30;
    var sum = 0;
    var i = 0;
    var wt = 0;

    for(i = n; i > 0; i--)
    sum += ((i - (n + 1) / 3) * close(i - n));
    wt = 6 / (n * (n + 1)) * sum;

    var eek = close()-wt;


    return eek;
    }
    Last edited by whizz; 08-17-2003, 11:38 AM.

  • #2
    Whizz,

    Please take a look at this LSMA formula. Your study should be able to be derived from that pretty easily. If I read your post correctly, you should be able to adjust it, by adjusting two lines. Set setPriceStudy(true); to setPriceStudy(false); on line 21, and change line 100 to read... return LSMA_Array[nOffset] - close();
    Regards,
    Jay F.
    Product Manager
    _____________________________________
    Have a suggestion to improve our products?
    Click Support --> Request a Feature in eSignal 11

    Comment

    Working...
    X