Announcement

Collapse
No announcement yet.

Linear Regression Reversal Indicator From Stocks And Commodities Magazine

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

  • Linear Regression Reversal Indicator From Stocks And Commodities Magazine

    I tried copying the formula for the Linear Regression Reversal Indicator from the current issue of Stocks and Commodities Magazine (December 2003) but get the message there is an error. Can someone tell me what the problem is. Thanks

    function preMain()
    {
    setStudyTitle("Lin Reg Reverse");
    setCursorLabelName("LRR",0);
    setDefaultBarFgColor(Color.green,0);
    setDefaultBarThickness(2,0);
    }
    function main(Length) {
    if(Length == null) Length = 5;
    var sum = 0;
    var i = 0;
    var mt = 0;
    varWT = 0;
    var vWT2 = getGlobalValue("WT2");
    if(vWT2 == null) {
    setGlobalValue("WT2", 0);
    }
    for(i = Length; i > 0; i--)
    sum += (i - (Length + 1) / 3 * close(i - Length);
    WT = 6/ Length * (Length + 1)) * sum
    if (WT >= vWT2)
    {
    setGlobalValue("WT2", WT);
    return 1;
    }
    else
    {
    setGlobalValue("WT2", WT);
    return -1;
    }
    return;
    }

  • #2
    rgh1rgh
    There are actually two errors
    This line
    sum += (i - (Length + 1) / 3 * close(i - Length);
    should be
    sum += (i - (Length + 1) / 3) * close(i - Length);
    and this line
    WT = 6/ Length * (Length + 1)) * sum
    should be
    WT = (6/ Length * (Length + 1)) * sum
    Hope this helps
    Alex

    Comment

    Working...
    X