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;
}
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;
}
Comment