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