Normally this stuff is my forté as I'm a software developer by profession, an engineer by training and a mathematician by inclination.
However, you've mixing up MQL arrays & mathematical algorithms with meaningless names like kk & jj in one huge function.
I would suggest divide-and-conquer and break it up into smaller functions, and try to keep the actual calculation routines 'pure' by not calling MQL-specific functions (like Close) inside them
Yes, it won't be as efficient, but as someone who used to strive to save machine cycles in Assembler many decades ago, I now realise that it's more important for code to be people-efficient rather than machine-efficient .. until performance proves otherwise.
I have the following code, it produces a COG/polynomial regression. I need to get the value of the center regression line (which the code already calculates) as well as the same value for the previous bar in order to calculate the slope. I can call the entire function again with a different initial shift to get the previous bar's value but this would be inefficient. Can anyone help me modify this function to get the current bar's and previous bar's value in the same go? I would really appreciate the help.
Since that's an exact copy of my rewrite, I think I can help.
First, you've computed the regression so you can compute the value of any point. This is exactly what
for(i = maxBar; i >= shift; i--) { // Count down so at end, sum = Y(shift). double sum = x[0]; //X0==1 for(kk = 1, Xn=i; kk <= COG.Degree; kk++, Xn *= i) sum += x[kk] * Xn;is doing to generate the residuals. Thus:
#define ONEBACK 1 double out[3] = x[0]; //X0==1 for(kk = 1, Xn=ONEBACK; kk <= COG.Degree; kk++, Xn *= ONEBACK) out[3] += x[kk] * Xn;
Second, since the least squares changes bar by bar, so the LS(1, center) won't exactly match LS(0, oneBack) but should be close.
I abandoned this idea last June.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have the following code, it produces a COG/polynomial regression. I need to get the value of the center regression line (which the code already calculates) as well as the same value for the previous bar in order to calculate the slope. I can call the entire function again with a different initial shift to get the previous bar's value but this would be inefficient. Can anyone help me modify this function to get the current bar's and previous bar's value in the same go? I would really appreciate the help.