Hello,
I am looking for a piece of code that returns a linear regression value for a given bar, as opposed to an array of values for the "n" lowest-numbered bars returned by /builtin/LinearRegressionStudy.efs
The S&C web site (http://www.traders.com/Documentation...ps.html#wealth) contains a movtrend.efs file that presumably does the job. However, the code does not look much like least squares fit implementations that I have seen, contains a typo ("wt" vs. "mt"), and what appears to be hardcoded constants ("3" and "6"). Could someone confirm that the S&C source works as advertised, or post one that does?
Thanks,
dis
---
P.S. movtrend.efs
function preMain()
{
setStudyTitle("Movtrend");
setCursorLabelName("Movtrend", 0);
setDefaultBarFgColor(Color.blue, 0);
setPriceStudy(true);
}
function main(n) {
if(n == null)
n = 20;
var sum = 0;
var i = 0;
var mt = 0;
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * close(i - n);
wt = 6 / (n * (n + 1)) * sum
return wt;
}
I am looking for a piece of code that returns a linear regression value for a given bar, as opposed to an array of values for the "n" lowest-numbered bars returned by /builtin/LinearRegressionStudy.efs
The S&C web site (http://www.traders.com/Documentation...ps.html#wealth) contains a movtrend.efs file that presumably does the job. However, the code does not look much like least squares fit implementations that I have seen, contains a typo ("wt" vs. "mt"), and what appears to be hardcoded constants ("3" and "6"). Could someone confirm that the S&C source works as advertised, or post one that does?
Thanks,
dis
---
P.S. movtrend.efs
function preMain()
{
setStudyTitle("Movtrend");
setCursorLabelName("Movtrend", 0);
setDefaultBarFgColor(Color.blue, 0);
setPriceStudy(true);
}
function main(n) {
if(n == null)
n = 20;
var sum = 0;
var i = 0;
var mt = 0;
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * close(i - n);
wt = 6 / (n * (n + 1)) * sum
return wt;
}
Comment