Announcement

Collapse
No announcement yet.

Backtesting w/Linear Regression

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

  • Backtesting w/Linear Regression

    Hi All,

    Need a hand with backtesting using Linear Regression. I'm sure it's something I've overlooked, but it seems that if I put a number of regression bars into the LinearRegressionStudy that backtesting fails to work until it reaches a point where it's the number of bars away from the current index position. Don't seem to have this prob with moving averages, so I'm sure it's something I'm doing wrong.

    For example:

    //Common Variables
    var RegressionAngle = 0.0001; //Difference between RegressionBar 200 bars ago and now
    var vLinReg = new LinearRegressionStudy("Close", 200, 1);

    function main {
    var vOldBasis = vLinReg.getValue(LinearRegressionStudy.BASIS, -198);
    var vBasis = vLinReg.getValue(LinearRegressionStudy.BASIS, 0);

    if ((vBasis - vOldBasis) > RegressionAngle) {
    MovingDirection = "Up";
    } else if ((vOldBasis - vBasis) > RegressionAngle) {
    MovingDirection= "Down";
    } else {
    MovingDirection= "Flat";
    }

    if (MovingDirection = "Up" and not in trade etc. etc.) {}
    }


    The problem is that with backtesting it waits until the LinearRegressionStudy is only 200 bars from the current position before reading a value in.

    Whereas if I use the replay bars function it works fine (but no easy way to see results here).

    Any ideas as to what I'm doing wrong?

    Cheers,
    - Will

  • #2
    Re: Backtesting w/Linear Regression

    Will
    When first loaded (or reloaded) the Linear Regression function you are using only returns a value for the number of bars defined for its length.
    What you need to use is a moving linear regression. Run a search in the forum for moving linear regression or LSMA (which is the same thing) and you will find a number of scripts that will calculate either one and that you can adapt to your needs
    Alex


    Originally posted by willk
    Hi All,

    Need a hand with backtesting using Linear Regression. I'm sure it's something I've overlooked, but it seems that if I put a number of regression bars into the LinearRegressionStudy that backtesting fails to work until it reaches a point where it's the number of bars away from the current index position. Don't seem to have this prob with moving averages, so I'm sure it's something I'm doing wrong.

    For example:

    //Common Variables
    var RegressionAngle = 0.0001; //Difference between RegressionBar 200 bars ago and now
    var vLinReg = new LinearRegressionStudy("Close", 200, 1);

    function main {
    var vOldBasis = vLinReg.getValue(LinearRegressionStudy.BASIS, -198);
    var vBasis = vLinReg.getValue(LinearRegressionStudy.BASIS, 0);

    if ((vBasis - vOldBasis) > RegressionAngle) {
    MovingDirection = "Up";
    } else if ((vOldBasis - vBasis) > RegressionAngle) {
    MovingDirection= "Down";
    } else {
    MovingDirection= "Flat";
    }

    if (MovingDirection = "Up" and not in trade etc. etc.) {}
    }


    The problem is that with backtesting it waits until the LinearRegressionStudy is only 200 bars from the current position before reading a value in.

    Whereas if I use the replay bars function it works fine (but no easy way to see results here).

    Any ideas as to what I'm doing wrong?

    Cheers,
    - Will

    Comment

    Working...
    X